diff --git a/chrome/content/zotero-platform/mac/overlay.css b/chrome/content/zotero-platform/mac/overlay.css index 19103e167..ff1d5191e 100644 --- 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 index a71ce8587..e18b41111 100644 --- 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 index f8c85c976..32960abfb 100644 --- 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); + } } } @@ -1817,6 +1825,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: { diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 3b195ce0c..559f9cdf7 100644 --- 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 index 5cfc1cf06..6624a7542 100644 --- 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 index eb0c72c18..cc90a320e 100644 --- a/chrome/content/zotero/zoteroPane.xul +++ b/chrome/content/zotero/zoteroPane.xul @@ -46,7 +46,6 @@