From 7fbe630c8518394a4bd7207ab29c9685445901a1 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 26 Jan 2007 10:51:43 +0000 Subject: [PATCH] Closes #47, Advanced search window And they said it would never happen. Doesn't yet support dragging items to other windows, etc., but you can double-click to focus the item in the most recent Zotero pane. You can also save the search as...a saved search, which means that theoretically we could get rid of the now-redundant "New Saved Search" icon. == Other/related changes == Search dialog: - Better keyboard handling (focus condition menu by default, Enter to trigger command (e.g. search in the Advanced Search window), Shift-Enter to add new row) Zotero.Search: - Zotero.Search.clone() -- return copy of search - Zotero.Search.getSearchConditions() now returns copy of conditions itemTreeView: - Always sort by the first column if no sort column set; removed isSorted() logic, since isSorted() now always returns true - Made itemsTreeView.refresh() call rowCountChanged, since there were cases in which the tree could end up looking for nonexistent rows after they'd been removed - selectItem() now takes a second parameter, expand, to open the selected item if it's a container - selectItem() now tries to get the selected item at least slightly away from the bottom (since ensureRowIsVisible does only the bare minimum) and also tries to get the parent item in view when scrolling upwards to make a child item visible - Moved getSelectedItems() logic into the treeview instead of overlay.js --- chrome/content/zotero/advancedSearch.js | 125 +++++++++++++++++ chrome/content/zotero/advancedSearch.xul | 55 ++++++++ .../content/zotero/bindings/searchtextbox.xml | 2 +- .../content/zotero/bindings/zoterosearch.xml | 77 +++++++---- chrome/content/zotero/overlay.js | 24 +++- chrome/content/zotero/overlay.xul | 2 + chrome/content/zotero/xpcom/itemTreeView.js | 127 ++++++++++++------ chrome/content/zotero/xpcom/search.js | 33 ++++- chrome/locale/en-US/zotero/searchbox.dtd | 4 + chrome/locale/en-US/zotero/zotero.properties | 1 + chrome/skin/default/zotero/overlay.css | 5 + .../zotero/toolbar-advanced-search.png | Bin 0 -> 615 bytes chrome/skin/default/zotero/zotero.css | 17 +++ 13 files changed, 396 insertions(+), 76 deletions(-) create mode 100644 chrome/content/zotero/advancedSearch.js create mode 100644 chrome/content/zotero/advancedSearch.xul create mode 100755 chrome/skin/default/zotero/toolbar-advanced-search.png 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; +]> + + + +