diff --git a/chrome/content/zotero/advancedSearch.js b/chrome/content/zotero/advancedSearch.js new file mode 100644 index 0000000000..3172a2183d --- /dev/null +++ b/chrome/content/zotero/advancedSearch.js @@ -0,0 +1,125 @@ +var ZoteroAdvancedSearch = new function() { + this.onLoad = onLoad; + this.search = search; + this.clear = clear; + this.save = save; + this.onDblClick = onDblClick; + this.onUnload = onUnload; + + var _searchBox; + var _itemsView; + + function onLoad() { + _searchBox = document.getElementById('zotero-search-box'); + + var io = window.arguments[0]; + _searchBox.search = io.dataIn.search; + } + + + function search() { + _searchBox.updateSearch(); + + // A minimal implementation of Zotero.CollectionTreeView + var itemGroup = { + getChildItems: function () { + var ids = _searchBox.search.search(); + return Zotero.Items.get(ids); + }, + isLibrary: function () { return false; }, + isCollection: function () { return false; }, + isSearch: function () { return true; } + } + + if (_itemsView) { + _itemsView.unregister(); + } + + _itemsView = new Zotero.ItemTreeView(itemGroup, false); + document.getElementById('zotero-items-tree').view = _itemsView; + } + + + function clear() { + if (_itemsView) { + _itemsView.unregister(); + } + document.getElementById('zotero-items-tree').view = null; + + var s = new Zotero.Search(); + s.addCondition('title', 'contains', ''); + _searchBox.search = s; + } + + + function save() { + _searchBox.updateSearch(); + + var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] + .getService(Components.interfaces.nsIPromptService); + + var untitled = Zotero.DB.getNextName('collections', 'collectionName', + Zotero.getString('pane.collections.untitled')); + + var name = { value: untitled }; + var result = promptService.prompt(window, "", + Zotero.getString('pane.collections.savedSearchName'), name, "", {}); + + if (!result) + { + return; + } + + if (!name.value) + { + newName.value = untitled; + } + + var s = _searchBox.search.clone(); + s.setName(name.value); + s.save(); + } + + + // Adapted from: http://www.xulplanet.com/references/elemref/ref_tree.html#cmnote-9 + function onDblClick(event, tree) + { + if (event && tree && event.type == "dblclick") + { + var row = {}, col = {}, obj = {}; + tree.treeBoxObject.getCellAt(event.clientX, event.clientY, row, col, obj); + // obj.value == cell/text/image + // TODO: handle collection double-click + if (obj.value && _itemsView && _itemsView.selection.currentIndex > -1) + { + var item = _itemsView.getSelectedItems()[0]; + + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + + var lastWin = wm.getMostRecentWindow("navigator:browser"); + + if (!lastWin) { + window.open(); + var newWindow = wm.getMostRecentWindow("navigator:browser"); + var b = newWindow.getBrowser(); + return; + } + + if (lastWin.document.getElementById('zotero-pane').getAttribute('collapsed') == 'true') { + lastWin.ZoteroPane.toggleDisplay(); + } + + lastWin.ZoteroPane.selectItem(item.getID(), false, true); + } + } + } + + + function onUnload() { + // Unregister search from Notifier + if (_itemsView) { + _itemsView.unregister(); + } + } +} diff --git a/chrome/content/zotero/advancedSearch.xul b/chrome/content/zotero/advancedSearch.xul new file mode 100644 index 0000000000..405e6bc636 --- /dev/null +++ b/chrome/content/zotero/advancedSearch.xul @@ -0,0 +1,55 @@ + + + + + + + %zoteroDTD; + + %searchboxDTD; +]> + + + +