www

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

commit ad5ce20c82eb56046efda679ce36d7294d95a53a
parent 7b7d3d85e38aa77c4c47993ea03a451770afedda
Author: Dan Stillman <dstillman@zotero.org>
Date:   Fri,  8 Sep 2006 06:01:29 +0000

Fixes #286, if a quick search is entered in the item pane, and a new item is added to the library, the item appears regardless

New logic in itemTreeView notify() target:

- Items are only selected on add in the active window -- this fixes a fairly major flaw in the previous system that would cause new items to be selected in all open windows

- If a quicksearch is open in the active window and a new item is added, clear the search

- If quicksearch and active window and item modify, rerun search

- If quicksearch and not active window, rerun search

- If not quicksearch and not active window, update list but retain previous selection


Diffstat:
Mchrome/chromeFiles/content/scholar/overlay.js | 6------
Mchrome/chromeFiles/content/scholar/xpcom/itemTreeView.js | 115+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
2 files changed, 75 insertions(+), 46 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/overlay.js b/chrome/chromeFiles/content/scholar/overlay.js @@ -139,12 +139,6 @@ var ScholarPane = new function() */ function newItem(typeID) { - if(document.getElementById('tb-search').value != "") - { - document.getElementById('tb-search').value = ""; - document.getElementById('tb-search').doCommand(); - } - var item = new Scholar.Item(typeID); item.save(); if(itemsView && itemsView._itemGroup.isCollection()) diff --git a/chrome/chromeFiles/content/scholar/xpcom/itemTreeView.js b/chrome/chromeFiles/content/scholar/xpcom/itemTreeView.js @@ -74,12 +74,21 @@ Scholar.ItemTreeView.prototype.refresh = function() Scholar.ItemTreeView.prototype.notify = function(action, type, ids) { var madeChanges = false; - this.selection.selectEventsSuppressed = true; var savedSelection = this.saveSelection(); ids = Scholar.flattenArguments(ids); + // See if we're in the active window + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + if (wm.getMostRecentWindow("navigator:browser") == + this._treebox.treeBody.ownerDocument.defaultView){ + var activeWindow = true; + } + + var quicksearch = this._treebox.treeBody.ownerDocument.getElementById('tb-search'); + if((action == 'remove' && !this._itemGroup.isLibrary()) || (action == 'delete' && this._itemGroup.isLibrary())) { //Since a remove involves shifting of rows, we have to do it in order @@ -110,54 +119,81 @@ Scholar.ItemTreeView.prototype.notify = function(action, type, ids) } else if(action == 'modify') //must check for null because it could legitimately be 0 { - for(var i=0, len=ids.length; i<len; i++) + // If no quicksearch, process modifications manually + if (quicksearch.value == '') { - var row = this._itemRowMap[ids[i]]; - if( row != null) + for(var i=0, len=ids.length; i<len; i++) { - if(this.isContainer(row) && this.isContainerOpen(row)) + var row = this._itemRowMap[ids[i]]; + if( row != null) { - this.toggleOpenState(row); - this.toggleOpenState(row); + if(this.isContainer(row) && this.isContainerOpen(row)) + { + this.toggleOpenState(row); + this.toggleOpenState(row); + } + else if(this.getParentIndex(row)) + { + + } + else + { + this._treebox.invalidateRow(row); + } + madeChanges = true; } - else if(this.getParentIndex(row)) + else if(this._itemGroup.isLibrary() || this._itemGroup.ref.hasItem(ids[i])) { + var item = Scholar.Items.get(ids[i]); + if(!item.getSource()) + { + //most likely, the note or attachment's parent was removed. + this._showItem(new Scholar.ItemTreeView.TreeRow(item,0,false),this.rowCount); + this._treebox.rowCountChanged(this.rowCount-1,1); + madeChanges = true; + } } - else - { - this._treebox.invalidateRow(row); - } - madeChanges = true; } - else if(this._itemGroup.isLibrary() || this._itemGroup.ref.hasItem(ids[i])) + } + + // If quicksearch, re-run it, since the results may have changed + else + { + quicksearch.doCommand(); + madeChanges = true; + } + } + else if(action == 'add') + { + // If no quicksearch, process new items manually + if (quicksearch.value == '') + { + var items = Scholar.Items.get(ids); + + for (var i in items) { - var item = Scholar.Items.get(ids[i]); - - if(!item.getSource()) + if((this._itemGroup.isLibrary() || items[i].inCollection(this._itemGroup.ref.getID())) // if the item belongs in this collection + && this._itemRowMap[items[i].getID()] == null // if we haven't already added it to our hash map + && (items[i].isRegularItem() || !items[i].getSource())) // if it's stand-alone { - //most likely, the note or attachment's parent was removed. - this._showItem(new Scholar.ItemTreeView.TreeRow(item,0,false),this.rowCount); + this._showItem(new Scholar.ItemTreeView.TreeRow(items[i],0,false),this.rowCount); this._treebox.rowCountChanged(this.rowCount-1,1); + madeChanges = true; } } } - } - else if(action == 'add') - { - var items = Scholar.Items.get(ids); - - for (var i in items){ - if((this._itemGroup.isLibrary() || items[i].inCollection(this._itemGroup.ref.getID())) // if the item belongs in this collection - && this._itemRowMap[items[i].getID()] == null // if we haven't already added it to our hash map - && (items[i].isRegularItem() || !items[i].getSource())) // if it's stand-alone + // Otherwise rerun the search, which refreshes the item list + else + { + // If active window, clear search first + if (activeWindow) { - this._showItem(new Scholar.ItemTreeView.TreeRow(items[i],0,false),this.rowCount); - this._treebox.rowCountChanged(this.rowCount-1,1); - - madeChanges = true; + quicksearch.value = ''; } + quicksearch.doCommand(); + madeChanges = true; } } @@ -173,15 +209,14 @@ Scholar.ItemTreeView.prototype.notify = function(action, type, ids) this._refreshHashMap(); } - if(action == 'add') + // If adding and this is the active window, select the item + if(action == 'add' && ids.length===1 && activeWindow) { - if (ids.length===1){ - // Reset to Info tab - this._treebox.treeBody.ownerDocument. - getElementById('scholar-view-tabs').selectedIndex = 0; - - this.selectItem(ids[0]); - } + // Reset to Info tab + this._treebox.treeBody.ownerDocument. + getElementById('scholar-view-tabs').selectedIndex = 0; + + this.selectItem(ids[0]); } else {