From 8710875fdb3235cc4a527cfb475d518ae184ddc6 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 2 Jan 2007 13:15:31 +0000 Subject: [PATCH] Fix itemTreeView.rememberSelection() to find children of unopened parents as well as top-level items This makes the quicksearch considerably more useful, as you can search for a child item in the library, select it, and then clear the search to view the item in context. (Works for multiple items as well, even of different parents.) --- chrome/content/zotero/xpcom/itemTreeView.js | 23 +++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 7daca7d3cd..34f9d2d909 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -612,7 +612,7 @@ Zotero.ItemTreeView.prototype.selectItem = function(id) // No parent -- it's not here return false; } - this.toggleOpenState(this._itemRowMap[item.getSource()]); //opens the parent of the item + this.toggleOpenState(this._itemRowMap[parent]); //opens the parent of the item row = this._itemRowMap[id]; } @@ -755,6 +755,7 @@ Zotero.ItemTreeView.prototype.saveSelection = function() savedSelection.push(this._getItemAtRow(j).ref.getID()); } } + return savedSelection; } @@ -766,8 +767,26 @@ Zotero.ItemTreeView.prototype.rememberSelection = function(selection) this.selection.clearSelection(); for(var i=0; i < selection.length; i++) { - if(this._itemRowMap[selection[i]] != null) + if (this._itemRowMap[selection[i]] != null) { this.selection.toggleSelect(this._itemRowMap[selection[i]]); + } + // Try the parent + else { + var item = Zotero.Items.get(selection[i]); + if (!item) { + continue; + } + + var parent = item.getSource(); + if (!parent) { + continue; + } + + if (this._itemRowMap[parent] != null) { + this.toggleOpenState(this._itemRowMap[parent]); + this.selection.toggleSelect(this._itemRowMap[selection[i]]); + } + } } }