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
This commit is contained in:
parent
2453fed74a
commit
3856885e6d
|
@ -43,6 +43,10 @@
|
||||||
padding: 5px 1px 5px 11px;
|
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 {
|
#zotero-tb-sync > .toolbarbutton-icon {
|
||||||
-moz-padding-start: 8px;
|
-moz-padding-start: 8px;
|
||||||
padding-top: 1px;
|
padding-top: 1px;
|
||||||
|
|
|
@ -1890,7 +1890,8 @@ Zotero.ItemGroup.prototype.getSearchObject = function() {
|
||||||
s2.setScope(s, includeScopeChildren);
|
s2.setScope(s, includeScopeChildren);
|
||||||
|
|
||||||
if (this.searchText) {
|
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){
|
if (this.tags){
|
||||||
|
|
|
@ -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
|
// 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);
|
var parts = Zotero.SearchConditions.parseSearchString(value);
|
||||||
|
|
||||||
for each(var part in parts) {
|
for each(var part in parts) {
|
||||||
this.addCondition('blockStart');
|
this.addCondition('blockStart');
|
||||||
this.addCondition('field', operator, part.text, false);
|
if (condition == 'quicksearch-titlesAndCreators') {
|
||||||
this.addCondition('creator', operator, part.text, false);
|
this.addCondition('title', 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);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var splits = Zotero.Fulltext.semanticSplitter(part.text);
|
this.addCondition('field', operator, part.text, false);
|
||||||
for each(var split in splits) {
|
}
|
||||||
this.addCondition('fulltextWord', operator, split, 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',
|
name: 'quicksearch',
|
||||||
operators: {
|
operators: {
|
||||||
|
|
|
@ -1713,6 +1713,17 @@ Zotero.Prefs = new function(){
|
||||||
Zotero.Sync.Runner.IdleListener.unregister();
|
Zotero.Sync.Runner.IdleListener.unregister();
|
||||||
}
|
}
|
||||||
break;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,6 +119,8 @@ var ZoteroPane = new function()
|
||||||
window.addEventListener("resize", this.updateToolbarPosition, false);
|
window.addEventListener("resize", this.updateToolbarPosition, false);
|
||||||
window.setTimeout(this.updateToolbarPosition, 0);
|
window.setTimeout(this.updateToolbarPosition, 0);
|
||||||
|
|
||||||
|
this.updateQuickSearchBox();
|
||||||
|
|
||||||
if (Zotero.isMac) {
|
if (Zotero.isMac) {
|
||||||
//document.getElementById('zotero-tb-actions-zeroconf-update').setAttribute('hidden', false);
|
//document.getElementById('zotero-tb-actions-zeroconf-update').setAttribute('hidden', false);
|
||||||
document.getElementById('zotero-pane-stack').setAttribute('platform', 'mac');
|
document.getElementById('zotero-pane-stack').setAttribute('platform', 'mac');
|
||||||
|
@ -1694,7 +1696,7 @@ var ZoteroPane = new function()
|
||||||
var search = document.getElementById('zotero-tb-search');
|
var search = document.getElementById('zotero-tb-search');
|
||||||
if (search.value != '') {
|
if (search.value != '') {
|
||||||
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");
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,7 +46,6 @@
|
||||||
<script src="locateMenu.js" type="application/javascript;version=1.7"/>
|
<script src="locateMenu.js" type="application/javascript;version=1.7"/>
|
||||||
|
|
||||||
<commandset id="mainCommandSet">
|
<commandset id="mainCommandSet">
|
||||||
<command id="cmd_zotero_search" oncommand="ZoteroPane_Local.search();"/>
|
|
||||||
<command id="cmd_zotero_reportErrors" oncommand="ZoteroPane_Local.reportErrors();"/>
|
<command id="cmd_zotero_reportErrors" oncommand="ZoteroPane_Local.reportErrors();"/>
|
||||||
</commandset>
|
</commandset>
|
||||||
|
|
||||||
|
@ -145,10 +144,10 @@
|
||||||
<toolbarseparator/>
|
<toolbarseparator/>
|
||||||
<toolbarbutton id="zotero-tb-advanced-search" class="zotero-tb-button" tooltiptext="&zotero.toolbar.advancedSearch;" oncommand="ZoteroPane_Local.openAdvancedSearchWindow()"/>
|
<toolbarbutton id="zotero-tb-advanced-search" class="zotero-tb-button" tooltiptext="&zotero.toolbar.advancedSearch;" oncommand="ZoteroPane_Local.openAdvancedSearchWindow()"/>
|
||||||
<spacer flex="1"/>
|
<spacer flex="1"/>
|
||||||
<textbox id="zotero-tb-search" type="search" timeout="250" command="cmd_zotero_search" dir="reverse"
|
<textbox id="zotero-tb-search" type="search" timeout="250" dir="reverse"
|
||||||
onkeypress="ZoteroPane_Local.handleSearchKeypress(this, event)"
|
onkeypress="ZoteroPane_Local.handleSearchKeypress(this, event)"
|
||||||
oninput="ZoteroPane_Local.handleSearchInput(this, event)">
|
oninput="ZoteroPane_Local.handleSearchInput(this, event)"
|
||||||
</textbox>
|
oncommand="ZoteroPane_Local.search()"/>
|
||||||
</hbox>
|
</hbox>
|
||||||
|
|
||||||
<hbox id="zotero-item-toolbar" align="center" flex="1">
|
<hbox id="zotero-item-toolbar" align="center" flex="1">
|
||||||
|
|
|
@ -419,6 +419,15 @@
|
||||||
width: 150px;
|
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
|
#zotero-view-tabbox, #zotero-item-pane-content > groupbox, #zotero-item-pane-content > groupbox > .groupbox-body
|
||||||
{
|
{
|
||||||
margin: 0 !important;
|
margin: 0 !important;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user