Move custom search textbox (for regex, etc.) and in-the-last condition field into zoterosearch.xml

This commit is contained in:
Dan Stillman 2007-01-30 21:41:37 +00:00
parent 5313aff1a2
commit 97de1a41e2
3 changed files with 217 additions and 240 deletions

View File

@ -1,236 +0,0 @@
<?xml version="1.0"?>
<!--
***** BEGIN LICENSE BLOCK *****
Copyright (c) 2006 Center for History and New Media
George Mason University, Fairfax, Virginia, USA
http://chnm.gmu.edu
Licensed under the Educational Community License, Version 1.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.opensource.org/licenses/ecl1.php
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
***** END LICENSE BLOCK *****
-->
<!DOCTYPE bindings SYSTEM "chrome://zotero/locale/searchbox.dtd">
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="zotero-search-textbox">
<implementation>
<property name="value"
onget="return document.getAnonymousNodes(this)[0].value"
onset="document.getAnonymousNodes(this)[0].setAttribute('value', val); return val"/>
<property name="mode">
<getter>
<![CDATA[
if (this.getAttribute('hasOptions')!='true'){
return false;
}
var button = this.id('textbox-button');
var menu = this.id(button.popup);
var selectedIndex = -1;
for (var i=0; i<menu.childNodes.length; i++){
if (menu.childNodes[i].getAttribute('checked')=='true'){
selectedIndex = i;
break;
}
}
switch (button.popup){
case 'textbox-fulltext-menu':
switch (selectedIndex){
case 0:
return false;
case 1:
return 'phraseBinary';
case 2:
return 'regexp';
case 3:
return 'regexpCS';
}
break;
}
throw('Invalid search textbox popup');
]]>
</getter>
</property>
<method name="update">
<parameter name="condition"/>
<parameter name="mode"/>
<body>
<![CDATA[
var button = this.id('textbox-button');
switch (condition){
case 'fulltextContent':
button.popup = 'textbox-fulltext-menu';
button.setAttribute('popup', 'textbox-fulltext-menu');
var menu = this.id(button.popup);
this.setAttribute('hasOptions', true);
var selectedIndex = 0;
if (mode){
switch (mode){
case 'phrase':
selectedIndex = 0;
break;
case 'phraseBinary':
selectedIndex = 1;
break;
case 'regexp':
selectedIndex = 2;
break;
case 'regexpCS':
selectedIndex = 3;
break;
}
}
menu.childNodes[selectedIndex].setAttribute('checked', true);
break;
default:
this.setAttribute('hasOptions', false);
// Set textbox to autocomplete mode
switch (condition)
{
// Skip autocomplete for these fields
case 'date':
case 'note':
case 'extra':
break;
default:
var textbox = document.getAnonymousNodes(this)[0];
textbox.setAttribute('type', 'autocomplete');
textbox.setAttribute('autocompletesearch', 'zotero');
if (condition=='creator')
{
// 2 searches both single- and double-field creators
var autocompleteCondition = condition + '/2'
}
else
{
var autocompleteCondition = condition;
}
textbox.setAttribute('autocompletesearchparam', autocompleteCondition);
}
}
if (!autocompleteCondition)
{
var textbox = document.getAnonymousNodes(this)[0];
textbox.removeAttribute('type');
}
]]>
</body>
</method>
<method name="id">
<parameter name="id"/>
<body>
<![CDATA[
return document.getAnonymousNodes(this)[0].getElementsByAttribute('id',id)[0];
]]>
</body>
</method>
</implementation>
<content>
<xul:textbox id="textbox" xbl:inherits="flex">
<xul:popupset>
<xul:menupopup id="textbox-fulltext-menu">
<xul:menuitem type="radio" checked="true" label="&zotero.search.textModes.phrase;"/>
<xul:menuitem type="radio" label="&zotero.search.textModes.phraseBinary;"/>
<xul:menuitem type="radio" label="&zotero.search.textModes.regexp;"/>
<xul:menuitem type="radio" label="&zotero.search.textModes.regexpCS;"/>
</xul:menupopup>
</xul:popupset>
<xul:toolbarbutton id="textbox-button" type="menu"/>
</xul:textbox>
</content>
</binding>
<binding id="search-in-the-last">
<implementation>
<property name="value">
<getter>
<![CDATA[
var menulist = document.getAnonymousNodes(this)[0].firstChild.nextSibling;
return document.getAnonymousNodes(this)[0].firstChild.value + ' ' +
menulist.firstChild.childNodes[menulist.selectedIndex].getAttribute('value')
]]>
</getter>
<setter>
<![CDATA[
var [num, units] = val.split(' ');
document.getAnonymousNodes(this)[0].firstChild.setAttribute('value', num);
var menulist = document.getAnonymousNodes(this)[0].firstChild.nextSibling;
var menupopup = menulist.firstChild;
var selectThis = 0;
for (var i=0; i<menupopup.childNodes.length; i++){
if (menupopup.childNodes[i].value == units)
{
selectThis = i;
break;
}
}
menulist.selectedIndex = selectThis;
return val;
]]>
</setter>
</property>
<method name="id">
<parameter name="id"/>
<body>
<![CDATA[
return document.getAnonymousNodes(this)[0].getElementsByAttribute('id',id)[0];
]]>
</body>
</method>
</implementation>
<content>
<xul:hbox flex="1">
<xul:textbox flex="1"/>
<xul:menulist>
<xul:menupopup flex="1">
<xul:menuitem label="&zotero.search.date.units.days;" value="days" selected="true"/>
<xul:menuitem label="&zotero.search.date.units.months;" value="months"/>
<xul:menuitem label="&zotero.search.date.units.years;" value="years"/>
</xul:menupopup>
</xul:menulist>
</xul:hbox>
</content>
</binding>
</bindings>

View File

@ -23,9 +23,10 @@
<!DOCTYPE bindings SYSTEM "chrome://zotero/locale/searchbox.dtd">
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="search-box">
<implementation>
<field name="searchRef"/>
@ -207,6 +208,8 @@
</content>
</binding>
<binding id="search-condition">
<implementation>
<field name="conditionID"/>
@ -563,4 +566,214 @@
</xul:hbox>
</content>
</binding>
<binding id="search-textbox">
<implementation>
<property name="value"
onget="return document.getAnonymousNodes(this)[0].value"
onset="document.getAnonymousNodes(this)[0].setAttribute('value', val); return val"/>
<property name="mode">
<getter>
<![CDATA[
if (this.getAttribute('hasOptions')!='true'){
return false;
}
var button = this.id('textbox-button');
var menu = this.id(button.popup);
var selectedIndex = -1;
for (var i=0; i<menu.childNodes.length; i++){
if (menu.childNodes[i].getAttribute('checked')=='true'){
selectedIndex = i;
break;
}
}
switch (button.popup){
case 'textbox-fulltext-menu':
switch (selectedIndex){
case 0:
return false;
case 1:
return 'phraseBinary';
case 2:
return 'regexp';
case 3:
return 'regexpCS';
}
break;
}
throw('Invalid search textbox popup');
]]>
</getter>
</property>
<method name="update">
<parameter name="condition"/>
<parameter name="mode"/>
<body>
<![CDATA[
var button = this.id('textbox-button');
switch (condition){
case 'fulltextContent':
button.popup = 'textbox-fulltext-menu';
button.setAttribute('popup', 'textbox-fulltext-menu');
var menu = this.id(button.popup);
this.setAttribute('hasOptions', true);
var selectedIndex = 0;
if (mode){
switch (mode){
case 'phrase':
selectedIndex = 0;
break;
case 'phraseBinary':
selectedIndex = 1;
break;
case 'regexp':
selectedIndex = 2;
break;
case 'regexpCS':
selectedIndex = 3;
break;
}
}
menu.childNodes[selectedIndex].setAttribute('checked', true);
break;
default:
this.setAttribute('hasOptions', false);
// Set textbox to autocomplete mode
switch (condition)
{
// Skip autocomplete for these fields
case 'date':
case 'note':
case 'extra':
break;
default:
var textbox = document.getAnonymousNodes(this)[0];
textbox.setAttribute('type', 'autocomplete');
textbox.setAttribute('autocompletesearch', 'zotero');
if (condition=='creator')
{
// 2 searches both single- and double-field creators
var autocompleteCondition = condition + '/2'
}
else
{
var autocompleteCondition = condition;
}
textbox.setAttribute('autocompletesearchparam', autocompleteCondition);
}
}
if (!autocompleteCondition)
{
var textbox = document.getAnonymousNodes(this)[0];
textbox.removeAttribute('type');
}
]]>
</body>
</method>
<method name="id">
<parameter name="id"/>
<body>
<![CDATA[
return document.getAnonymousNodes(this)[0].getElementsByAttribute('id',id)[0];
]]>
</body>
</method>
</implementation>
<content>
<xul:textbox id="textbox" xbl:inherits="flex">
<xul:popupset>
<xul:menupopup id="textbox-fulltext-menu">
<xul:menuitem type="radio" checked="true" label="&zotero.search.textModes.phrase;"/>
<xul:menuitem type="radio" label="&zotero.search.textModes.phraseBinary;"/>
<xul:menuitem type="radio" label="&zotero.search.textModes.regexp;"/>
<xul:menuitem type="radio" label="&zotero.search.textModes.regexpCS;"/>
</xul:menupopup>
</xul:popupset>
<xul:toolbarbutton id="textbox-button" type="menu"/>
</xul:textbox>
</content>
</binding>
<binding id="search-in-the-last">
<implementation>
<property name="value">
<getter>
<![CDATA[
var menulist = document.getAnonymousNodes(this)[0].firstChild.nextSibling;
return document.getAnonymousNodes(this)[0].firstChild.value + ' ' +
menulist.firstChild.childNodes[menulist.selectedIndex].getAttribute('value')
]]>
</getter>
<setter>
<![CDATA[
var [num, units] = val.split(' ');
document.getAnonymousNodes(this)[0].firstChild.setAttribute('value', num);
var menulist = document.getAnonymousNodes(this)[0].firstChild.nextSibling;
var menupopup = menulist.firstChild;
var selectThis = 0;
for (var i=0; i<menupopup.childNodes.length; i++){
if (menupopup.childNodes[i].value == units)
{
selectThis = i;
break;
}
}
menulist.selectedIndex = selectThis;
return val;
]]>
</setter>
</property>
<method name="id">
<parameter name="id"/>
<body>
<![CDATA[
return document.getAnonymousNodes(this)[0].getElementsByAttribute('id',id)[0];
]]>
</body>
</method>
</implementation>
<content>
<xul:hbox flex="1">
<xul:textbox flex="1"/>
<xul:menulist>
<xul:menupopup flex="1">
<xul:menuitem label="&zotero.search.date.units.days;" value="days" selected="true"/>
<xul:menuitem label="&zotero.search.date.units.months;" value="months"/>
<xul:menuitem label="&zotero.search.date.units.years;" value="years"/>
</xul:menupopup>
</xul:menulist>
</xul:hbox>
</content>
</binding>
</bindings>

View File

@ -91,7 +91,7 @@ searchcondition menulist[id="operatorsmenu"]
zoterosearchtextbox
{
-moz-binding: url('chrome://zotero/content/bindings/searchtextbox.xml#zotero-search-textbox');
-moz-binding: url('chrome://zotero/content/bindings/zoterosearch.xml#search-textbox');
}
zoterosearchtextbox toolbarbutton