From 2c1c8636e220b497564d9862eaa00c5d0c65a4be Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 13 Jan 2007 00:21:51 +0000 Subject: [PATCH] Fix two problems that occur when the tag selector is closed: - Items removed from collections remain in the center pane - Adding an item while a collection is selected causes the Library to become selected --- chrome/content/zotero/xpcom/itemTreeView.js | 30 +++++++++++++-------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index e67a2178b..7621f45d0 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -41,7 +41,7 @@ Zotero.ItemTreeView = function(itemGroup, sourcesOnly) this._treebox = null; this.refresh(); - this._unregisterID = Zotero.Notifier.registerObserver(this, 'item'); + this._unregisterID = Zotero.Notifier.registerObserver(this, ['item', 'collection-item']); } @@ -110,10 +110,6 @@ Zotero.ItemTreeView.prototype.refresh = function() */ Zotero.ItemTreeView.prototype.notify = function(action, type, ids) { - if (type != 'item' && type != 'collection-item'){ - return; - } - var madeChanges = false; this.selection.selectEventsSuppressed = true; var savedSelection = this.saveSelection(); @@ -128,6 +124,20 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids) var quicksearch = this._treebox.treeBody.ownerDocument.getElementById('zotero-tb-search'); + // 'collection-item' ids are in the form collectionID-itemID + if (type == 'collection-item') { + var splitIDs = []; + for each(var id in ids) { + var split = id.split('-'); + // Not items not in this collection + if (split[0] != this._itemGroup.ref.getID()) { + continue; + } + splitIDs.push(split[1]); + } + ids = splitIDs; + } + if((action == 'remove' && !this._itemGroup.isLibrary()) || action == 'delete') { //Since a remove involves shifting of rows, we have to do it in order @@ -136,17 +146,15 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids) var rows = new Array(); for(var i=0, len=ids.length; i 0) { rows.sort(function(a,b) { return a-b });