Removing a saved search removes the item in the left pane.

Search dialog:
 - should work now.
 - Any/All control
 - All 8 operators
Add search button uses an icon
This commit is contained in:
David Norton 2006-08-10 22:39:21 +00:00
parent 9c496770a6
commit d815154efa
7 changed files with 65 additions and 39 deletions

View file

@ -34,9 +34,18 @@
conditionsBox.removeChild(conditionsBox.firstChild); conditionsBox.removeChild(conditionsBox.firstChild);
var conditions = this.search.getSearchConditions(); var conditions = this.search.getSearchConditions();
if(conditions.length) for(var id in conditions)
for(var i = 0, len = conditions.length; i<len; i++) {
this.addCondition(i); if(conditions[id]['condition'] == 'joinMode')
{
this.id('joinModeMenu').setAttribute('condition',id);
this.id('joinModeMenu').value = conditions[id]['operator'];
}
else
{
this.addCondition(conditions[id]);
}
}
]]> ]]>
</setter> </setter>
@ -44,12 +53,12 @@
<method name="onAddClicked"> <method name="onAddClicked">
<body> <body>
<![CDATA[ <![CDATA[
this.addCondition(this.search.addCondition("itemType","is","1")); this.addCondition(this.search.getSearchCondition(this.search.addCondition("title","contains","")));
]]> ]]>
</body> </body>
</method> </method>
<method name="addCondition"> <method name="addCondition">
<parameter name="id"/> <parameter name="ref"/>
<body> <body>
<![CDATA[ <![CDATA[
var conditionsBox = this.id('conditions'); var conditionsBox = this.id('conditions');
@ -58,26 +67,42 @@
conditionsBox.appendChild(condition); conditionsBox.appendChild(condition);
condition.initWithParentAndConditionID(this, id); condition.initWithParentAndCondition(this, ref);
conditionsBox.childNodes[0].id('remove').hidden = (conditionsBox.childNodes.length == 1); conditionsBox.childNodes[0].id('remove').hidden = (conditionsBox.childNodes.length == 1);
]]> ]]>
</body> </body>
</method> </method>
<method name="removeCondition"> <method name="removeCondition">
<parameter name="idx"/> <parameter name="id"/>
<body> <body>
<![CDATA[ <![CDATA[
var conditionsBox = this.id('conditions'); var conditionsBox = this.id('conditions');
this.search.removeCondition(idx); this.search.removeCondition(id);
conditionsBox.removeChild(conditionsBox.childNodes[idx]);
for(var i = idx, len=conditionsBox.childNodes.length; i < len; i++) for(var i = 0, len=conditionsBox.childNodes.length; i < len; i++)
conditionsBox.childNodes[i].conditionID = i; if(conditionsBox.childNodes[i].conditionID == id)
{
conditionsBox.removeChild(conditionsBox.childNodes[i]);
i = len;
}
conditionsBox.childNodes[0].id('remove').hidden = (conditionsBox.childNodes.length == 1); conditionsBox.childNodes[0].id('remove').hidden = (conditionsBox.childNodes.length == 1);
]]> ]]>
</body> </body>
</method> </method>
<method name="updateJoinMode">
<body>
<![CDATA[
var menu = this.id('joinModeMenu');
if(menu.hasAttribute('condition'))
this.search.updateCondition(menu.getAttribute('condition'),'joinMode',menu.value,null);
else
menu.setAttribute('condition', this.search.addCondition('joinMode',menu.value,null));
]]>
</body>
</method>
<method name="save"> <method name="save">
<body> <body>
<![CDATA[ <![CDATA[
@ -87,8 +112,7 @@
for(var i = 0, len=conditionsBox.childNodes.length; i < len; i++) for(var i = 0, len=conditionsBox.childNodes.length; i < len; i++)
conditionsBox.childNodes[i].updateSearch(); conditionsBox.childNodes[i].updateSearch();
this.search.save(); return this.search.save();
]]> ]]>
</body> </body>
</method> </method>
@ -107,10 +131,10 @@
<xul:groupbox xbl:inherits="flex"> <xul:groupbox xbl:inherits="flex">
<xul:caption align="center"> <xul:caption align="center">
<xul:label value="Match"/> <xul:label value="Match"/>
<xul:menulist> <xul:menulist id="joinModeMenu" oncommand="this.parentNode.parentNode.parentNode.updateJoinMode();">
<xul:menupopup> <xul:menupopup>
<xul:menuitem label="Any" value="any"/> <xul:menuitem label="Any" value="any"/>
<xul:menuitem label="All" value="all"/> <xul:menuitem label="All" value="all" selected="true"/>
</xul:menupopup> </xul:menupopup>
</xul:menulist> </xul:menulist>
<xul:label value="of the following:"/> <xul:label value="of the following:"/>
@ -124,10 +148,12 @@
<implementation> <implementation>
<constructor> <constructor>
<![CDATA[ <![CDATA[
this.operators = new Array('is', 'isNot', 'contains', 'doesNotContain'); var operators = new Array('is', 'isNot', 'contains', 'doesNotContain', 'lessThan', 'greaterThan', 'isBefore', 'isAfter');
var conditionsList = this.id('conditionsmenu'); var operatorsList = this.id('operatorsmenu');
conditionsList.removeAllItems; for(i in operators)
operatorsList.appendItem(Scholar.getString('searchOperator.'+operators[i]),operators[i]);
var conditionsList = this.id('conditionsmenu');
var conditions = Scholar.SearchConditions.getStandardConditions(); var conditions = Scholar.SearchConditions.getStandardConditions();
for(var i=0, len=conditions.length; i<len; i++) for(var i=0, len=conditions.length; i<len; i++)
@ -156,22 +182,20 @@
]]> ]]>
</body> </body>
</method> </method>
<field name="operators"/>
<field name="dontupdate"/> <field name="dontupdate"/>
<field name="parent"/> <field name="parent"/>
<field name="conditionID"/> <field name="conditionID"/>
<method name="initWithParentAndConditionID"> <method name="initWithParentAndCondition">
<parameter name="parent"/> <parameter name="parent"/>
<parameter name="id"/> <parameter name="condition"/>
<body> <body>
<![CDATA[ <![CDATA[
this.parent = parent; this.parent = parent;
this.conditionID = id; this.conditionID = condition['id'];
if(this.parent.search) if(this.parent.search)
{ {
this.dontupdate = true; //so that the search doesn't get updated while we are creating controls. this.dontupdate = true; //so that the search doesn't get updated while we are creating controls.
var condition = this.parent.search.getSearchCondition(this.conditionID);
this.id('conditionsmenu').value = condition['condition']; this.id('conditionsmenu').value = condition['condition'];
this.id('operatorsmenu').value = condition['operator']; this.id('operatorsmenu').value = condition['operator'];
@ -226,12 +250,7 @@
<xul:menupopup/> <xul:menupopup/>
</xul:menulist> </xul:menulist>
<xul:menulist id="operatorsmenu"> <xul:menulist id="operatorsmenu">
<xul:menupopup> <xul:menupopup/>
<xul:menuitem label="is" value="is"/>
<xul:menuitem label="isNot" value="isNot"/>
<xul:menuitem label="contains" value="contains"/>
<xul:menuitem label="doesNotContain" value="doesNotContain"/>
</xul:menupopup>
</xul:menulist> </xul:menulist>
<xul:textbox id="valuefield" flex="1"/> <xul:textbox id="valuefield" flex="1"/>
<xul:toolbarbutton id="remove" class="clicky" label="-" oncommand="this.parentNode.parentNode.onRemoveClicked();"/> <xul:toolbarbutton id="remove" class="clicky" label="-" oncommand="this.parentNode.parentNode.onRemoveClicked();"/>

View file

@ -65,10 +65,7 @@ Scholar.CollectionTreeView.prototype.refresh = function()
var savedSearches = Scholar.Searches.getAll(); var savedSearches = Scholar.Searches.getAll();
for(var i = 0; i < savedSearches.length; i++) for(var i = 0; i < savedSearches.length; i++)
{
this._showItem(new Scholar.ItemGroup('search',savedSearches[i]), 0, this._dataItems.length); //itemgroup ref, level, beforeRow this._showItem(new Scholar.ItemGroup('search',savedSearches[i]), 0, this._dataItems.length); //itemgroup ref, level, beforeRow
Scholar.debug(i);
}
this._refreshHashMap(); this._refreshHashMap();
} }
@ -106,6 +103,8 @@ Scholar.CollectionTreeView.prototype.notify = function(action, type, ids)
{ {
var madeChanges = false; var madeChanges = false;
Scholar.debug(action+', '+type+', '+ids);
if(action == 'remove') if(action == 'remove')
{ {
ids = Scholar.flattenArguments(ids); ids = Scholar.flattenArguments(ids);
@ -310,7 +309,10 @@ Scholar.CollectionTreeView.prototype.deleteSelection = function()
if(group.isCollection()) if(group.isCollection())
group.ref.erase(); group.ref.erase();
else if(group.isSearch()) else if(group.isSearch())
{
Scholar.Searches.erase(group.ref['id']); Scholar.Searches.erase(group.ref['id']);
this._hideItem(rows[i]-i); //we don't have the notification system set up with searches.
}
} }
this._treebox.endUpdateBatch(); this._treebox.endUpdateBatch();

View file

@ -177,7 +177,7 @@ var ScholarPane = new function()
window.openDialog('chrome://scholar/content/searchDialog.xul','','chrome,modal',io); window.openDialog('chrome://scholar/content/searchDialog.xul','','chrome,modal',io);
if(io.dataOut) if(io.dataOut)
getCollectionsView().reload(); getCollectionsView().reload(); //we don't have notification support for searches
} }
function onCollectionSelected() function onCollectionSelected()
@ -300,7 +300,7 @@ var ScholarPane = new function()
var io = {dataIn: {search: s, name: collection.getName()}, dataOut: null}; var io = {dataIn: {search: s, name: collection.getName()}, dataOut: null};
window.openDialog('chrome://scholar/content/searchDialog.xul','','chrome,modal',io); window.openDialog('chrome://scholar/content/searchDialog.xul','','chrome,modal',io);
if(io.dataOut) if(io.dataOut)
onCollectionSelected(); onCollectionSelected(); //reload itemsView
} }
} }
} }

View file

@ -69,8 +69,8 @@
<vbox id="collections-pane" persist="width" flex="1"> <vbox id="collections-pane" persist="width" flex="1">
<toolbar> <toolbar>
<toolbarbutton id="tb-collection-add" tooltiptext="&toolbar.newCollection.label;" command="cmd_scholar_newCollection"/> <toolbarbutton id="tb-collection-add" tooltiptext="&toolbar.newCollection.label;" command="cmd_scholar_newCollection"/>
<toolbarbutton id="tb-collection-addsearch" tooltiptext="&toolbar.newSearch.label;" oncommand="ScholarPane.newSearch();"/>
<toolbarbutton id="tb-collection-rename" tooltiptext="&toolbar.renameCollection.label;" oncommand="ScholarPane.renameSelectedCollection();" disabled="true"/> <toolbarbutton id="tb-collection-rename" tooltiptext="&toolbar.renameCollection.label;" oncommand="ScholarPane.renameSelectedCollection();" disabled="true"/>
<toolbarbutton id="tb-collection-addsearch" label="Add Search" oncommand="ScholarPane.newSearch();"/>
<spacer flex="1"/> <spacer flex="1"/>
<toolbarbutton id="tb-collection-menu" type="menu"> <toolbarbutton id="tb-collection-menu" type="menu">
<menupopup> <menupopup>

View file

@ -39,6 +39,5 @@ function doUnload()
function doAccept() function doAccept()
{ {
document.getElementById('search-box').search.setName(document.getElementById('search-name').value); document.getElementById('search-box').search.setName(document.getElementById('search-name').value);
document.getElementById('search-box').save(); io.dataOut = document.getElementById('search-box').save();
io.dataOut = true;
} }

View file

@ -21,6 +21,7 @@
<!ENTITY toolbar.newItem.label "New Item"> <!ENTITY toolbar.newItem.label "New Item">
<!ENTITY toolbar.removeItem.label "Remove Item..."> <!ENTITY toolbar.removeItem.label "Remove Item...">
<!ENTITY toolbar.newCollection.label "New Project"> <!ENTITY toolbar.newCollection.label "New Project">
<!ENTITY toolbar.newSearch.label "New Search">
<!ENTITY toolbar.renameCollection.label "Rename Project..."> <!ENTITY toolbar.renameCollection.label "Rename Project...">
<!ENTITY toolbar.removeCollection.label "Remove Project..."> <!ENTITY toolbar.removeCollection.label "Remove Project...">
<!ENTITY toolbar.exportCollection.label "Export Project..."> <!ENTITY toolbar.exportCollection.label "Export Project...">

View file

@ -135,6 +135,11 @@
width: 150px; width: 150px;
} }
#tb-collection-addsearch
{
list-style-image: url('chrome://scholar/skin/treesource-search.png');
}
#tb-search-cancel #tb-search-cancel
{ {
margin: 0px; margin: 0px;