www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 3856885e6da9c4845ed5ae572313c5da56474230
parent 2453fed74ab8cf401862a74485c3af78e281349e
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon, 25 Apr 2011 15:27:49 +0000

Closes #1004, Add menu to quicksearch bar to change search modes

Initial version -- needs additional refinement

Not yet tested on Windows/Linux, and won't look right in Fx3.6


Diffstat:
Mchrome/content/zotero-platform/mac/overlay.css | 4++++
Mchrome/content/zotero/xpcom/collectionTreeView.js | 3++-
Mchrome/content/zotero/xpcom/search.js | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
Mchrome/content/zotero/xpcom/zotero.js | 11+++++++++++
Mchrome/content/zotero/zoteroPane.js | 93++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mchrome/content/zotero/zoteroPane.xul | 9++++-----
Mchrome/skin/default/zotero/overlay.css | 9+++++++++
7 files changed, 176 insertions(+), 19 deletions(-)

diff --git a/chrome/content/zotero-platform/mac/overlay.css b/chrome/content/zotero-platform/mac/overlay.css @@ -43,6 +43,10 @@ padding: 5px 1px 5px 11px; } +#zotero-tb-search-menu-button { + list-style-image: url("chrome://browser/skin/searchbar-dropmarker.png"); +} + #zotero-tb-sync > .toolbarbutton-icon { -moz-padding-start: 8px; padding-top: 1px; diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -1890,7 +1890,8 @@ Zotero.ItemGroup.prototype.getSearchObject = function() { s2.setScope(s, includeScopeChildren); if (this.searchText) { - s2.addCondition('quicksearch', 'contains', this.searchText); + var cond = 'quicksearch-' + Zotero.Prefs.get('search.quicksearch-mode'); + s2.addCondition(cond, 'contains', this.searchText); } if (this.tags){ diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js @@ -398,24 +398,32 @@ Zotero.Search.prototype.addCondition = function(condition, operator, value, requ } // Shortcut to add a condition on every table -- does not return an id - if (condition=='quicksearch'){ + if (condition.match(/^quicksearch/)) { var parts = Zotero.SearchConditions.parseSearchString(value); for each(var part in parts) { this.addCondition('blockStart'); - this.addCondition('field', operator, part.text, false); - this.addCondition('creator', operator, part.text, false); - this.addCondition('tag', operator, part.text, false); - this.addCondition('note', operator, part.text, false); - this.addCondition('annotation', operator, part.text, false); - - if (part.inQuotes) { - this.addCondition('fulltextContent', operator, part.text, false); + if (condition == 'quicksearch-titlesAndCreators') { + this.addCondition('title', operator, part.text, false); } else { - var splits = Zotero.Fulltext.semanticSplitter(part.text); - for each(var split in splits) { - this.addCondition('fulltextWord', operator, split, false); + this.addCondition('field', operator, part.text, false); + } + this.addCondition('creator', operator, part.text, false); + + if (condition == 'quicksearch-everything') { + this.addCondition('tag', operator, part.text, false); + this.addCondition('note', operator, part.text, false); + this.addCondition('annotation', operator, part.text, false); + + if (part.inQuotes) { + this.addCondition('fulltextContent', operator, part.text, false); + } + else { + var splits = Zotero.Fulltext.semanticSplitter(part.text); + for each(var split in splits) { + this.addCondition('fulltextWord', operator, split, false); + } } } @@ -1818,6 +1826,40 @@ Zotero.SearchConditions = new function(){ }, { + name: 'quicksearch-titlesAndCreators', + operators: { + is: true, + isNot: true, + contains: true, + doesNotContain: true + }, + noLoad: true + }, + + { + name: 'quicksearch-fields', + operators: { + is: true, + isNot: true, + contains: true, + doesNotContain: true + }, + noLoad: true + }, + + { + name: 'quicksearch-everything', + operators: { + is: true, + isNot: true, + contains: true, + doesNotContain: true + }, + noLoad: true + }, + + // Deprecated + { name: 'quicksearch', operators: { is: true, diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js @@ -1713,6 +1713,17 @@ Zotero.Prefs = new function(){ Zotero.Sync.Runner.IdleListener.unregister(); } break; + + case "search.quicksearch-mode": + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + var enumerator = wm.getEnumerator("navigator:browser"); + while (enumerator.hasMoreElements()) { + var win = enumerator.getNext(); + if (!win.ZoteroPane) continue; + win.ZoteroPane.updateQuickSearchBox(); + } + break; } } } diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js @@ -119,6 +119,8 @@ var ZoteroPane = new function() window.addEventListener("resize", this.updateToolbarPosition, false); window.setTimeout(this.updateToolbarPosition, 0); + this.updateQuickSearchBox(); + if (Zotero.isMac) { //document.getElementById('zotero-tb-actions-zeroconf-update').setAttribute('hidden', false); document.getElementById('zotero-pane-stack').setAttribute('platform', 'mac'); @@ -1694,7 +1696,7 @@ var ZoteroPane = new function() var search = document.getElementById('zotero-tb-search'); if (search.value != '') { search.value = ''; - search.doCommand('cmd_zotero_search'); + ZoteroPane_Local.search(); } } @@ -3610,6 +3612,95 @@ var ZoteroPane = new function() toolbar.style.width = computedStyle.getPropertyValue("width"); } } + + + this.updateQuickSearchBox = function () { + var mode = Zotero.Prefs.get("search.quicksearch-mode"); + var prefix = 'zotero-tb-search-mode-'; + var prefixLen = prefix.length; + + var modes = { + titlesAndCreators: { + label: "Titles & Creators" + }, + + fields: { + label: "All Fields" + }, + + everything: { + label: "Everything" + } + }; + + if (!modes[mode]) { + mode = 'everything'; + } + + var searchBox = document.getElementById('zotero-tb-search'); + + var hbox = document.getAnonymousNodes(searchBox)[0]; + var input = hbox.getElementsByAttribute('class', 'textbox-input')[0]; + + // Already initialized, so just update selection + var button = hbox.getElementsByAttribute('id', 'zotero-tb-search-menu-button'); + if (button.length) { + button = button[0]; + var menupopup = button.firstChild; + for each(var menuitem in menupopup.childNodes) { + if (menuitem.id.substr(prefixLen) == mode) { + menuitem.setAttribute('checked', true); + if (Zotero.isFx36) { + searchBox.emptytext = modes[mode].label; + } + else { + searchBox.placeholder = modes[mode].label; + } + return; + } + } + return; + } + + // Otherwise, build menu + button = document.createElement('button'); + button.id = 'zotero-tb-search-menu-button'; + button.setAttribute('type', 'menu'); + + var menupopup = document.createElement('menupopup'); + + for (var i in modes) { + var menuitem = document.createElement('menuitem'); + menuitem.setAttribute('id', prefix + i); + menuitem.setAttribute('label', modes[i].label); + menuitem.setAttribute('name', 'searchMode'); + menuitem.setAttribute('type', 'radio'); + //menuitem.setAttribute("tooltiptext", ""); + + menupopup.appendChild(menuitem); + + if (mode == i) { + menuitem.setAttribute('checked', true); + menupopup.selectedItem = menuitem; + } + } + + menupopup.setAttribute( + 'oncommand', + 'var mode = event.target.id.substr(22); ' + + 'Zotero.Prefs.set("search.quicksearch-mode", mode);' + ); + + button.appendChild(menupopup); + hbox.insertBefore(button, input); + + if (Zotero.isFx36) { + searchBox.emptytext = modes[mode].label; + } + else { + searchBox.placeholder = modes[mode].label; + } + } } /** diff --git a/chrome/content/zotero/zoteroPane.xul b/chrome/content/zotero/zoteroPane.xul @@ -46,7 +46,6 @@ <script src="locateMenu.js" type="application/javascript;version=1.7"/> <commandset id="mainCommandSet"> - <command id="cmd_zotero_search" oncommand="ZoteroPane_Local.search();"/> <command id="cmd_zotero_reportErrors" oncommand="ZoteroPane_Local.reportErrors();"/> </commandset> @@ -145,10 +144,10 @@ <toolbarseparator/> <toolbarbutton id="zotero-tb-advanced-search" class="zotero-tb-button" tooltiptext="&zotero.toolbar.advancedSearch;" oncommand="ZoteroPane_Local.openAdvancedSearchWindow()"/> <spacer flex="1"/> - <textbox id="zotero-tb-search" type="search" timeout="250" command="cmd_zotero_search" dir="reverse" - onkeypress="ZoteroPane_Local.handleSearchKeypress(this, event)" - oninput="ZoteroPane_Local.handleSearchInput(this, event)"> - </textbox> + <textbox id="zotero-tb-search" type="search" timeout="250" dir="reverse" + onkeypress="ZoteroPane_Local.handleSearchKeypress(this, event)" + oninput="ZoteroPane_Local.handleSearchInput(this, event)" + oncommand="ZoteroPane_Local.search()"/> </hbox> <hbox id="zotero-item-toolbar" align="center" flex="1"> diff --git a/chrome/skin/default/zotero/overlay.css b/chrome/skin/default/zotero/overlay.css @@ -419,6 +419,15 @@ width: 150px; } +#zotero-tb-search-menu-button +{ + margin: -6px -2px -6px -16px; + padding: 6px 2px 6px 14px; + -moz-appearance: none; + min-width: 0; + cursor: default; +} + #zotero-view-tabbox, #zotero-item-pane-content > groupbox, #zotero-item-pane-content > groupbox > .groupbox-body { margin: 0 !important;