From 9f7437f5caa1ef4161cea0570ba1ee7e1770e5ed Mon Sep 17 00:00:00 2001
From: David Norton <david@nortoncrew.com>
Date: Fri, 9 Jun 2006 14:01:07 +0000
Subject: [PATCH] [interface] itemsTreeView correctly handles notify(erase)
 [data access] Collection.removeItem() calls trigger() with the right type

---
 .../content/scholar/itemTreeView.js           | 44 ++++++++-----------
 .../content/scholar/xpcom/data_access.js      |  2 +-
 2 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/itemTreeView.js b/chrome/chromeFiles/content/scholar/itemTreeView.js
index 983a8ea23..99c742b9a 100644
--- a/chrome/chromeFiles/content/scholar/itemTreeView.js
+++ b/chrome/chromeFiles/content/scholar/itemTreeView.js
@@ -191,20 +191,20 @@ Scholar.ItemTreeView.prototype.getCollectionID = function()
 //CALLED BY DATA LAYER ON CHANGE:
 Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
 {
-	ids = Scholar.flattenArguments(ids);
 	var madeChanges = false;
 	
 	this.selection.selectEventsSuppressed = true;
 	this.saveSelection();
 
-	if(action == 'remove')
+	if((action == 'remove' && !this._itemGroup.isLibrary()) || (action == 'delete' && this._itemGroup.isLibrary()))
 	{
+		ids = Scholar.flattenArguments(ids);
 		//Since a remove involves shifting of rows, we have to do it in order
 		
 		//sort the ids by row
 		var rows = new Array();
 		for(var i=0, len=ids.length; i<len; i++)
-			if(this._itemRowMap[ids[i]] != null)
+			if(action == 'delete' || !this._itemGroup.ref.hasItem(ids[i]))
 				rows.push(this._itemRowMap[ids[i]]);
 		
 		if(rows.length > 0)
@@ -222,32 +222,24 @@ Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
 		}		
 		
 	}
-	else
+	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(this._itemRowMap[ids])
 		{
-		
-			var row = this._itemRowMap[ids[i]];
-			if(action == 'modify' && row != null) 	//must check for null because it could legitimately be 0
-			{
-				var item = Scholar.Items.get(ids[i]);
+			this._treebox.invalidateRow(row);
+			madeChanges = true;
+		}
+	}
+	else if(action == 'add')
+	{
+		var item = Scholar.Items.get(ids);
 				
-				this._treebox.invalidateRow(row);
-				madeChanges = true;
-			}
-			else if(action == 'add' && row == null)
-			{
-				var item = Scholar.Items.get(ids[i]);
-				
-				if(this._itemGroup.isLibrary() || item.inCollection(this.getCollectionID()))
-				{
-					this._showItem(item,this.rowCount);
-					this._treebox.rowCountChanged(this.rowCount-1,1);
-				}
-			
-				madeChanges = true;
-			}
-			
+		if(this._itemGroup.isLibrary() || item.inCollection(this.getCollectionID()))
+		{
+			this._showItem(item,this.rowCount);
+			this._treebox.rowCountChanged(this.rowCount-1,1);
+	
+			madeChanges = true;
 		}
 	}
 	
diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js
index 2897e78c5..c550aa788 100644
--- a/chrome/chromeFiles/content/scholar/xpcom/data_access.js
+++ b/chrome/chromeFiles/content/scholar/xpcom/data_access.js
@@ -1234,7 +1234,7 @@ Scholar.Collection.prototype.removeItem = function(itemID){
 	// If this was the last item, set collection to empty
 	if (!this._childItems.length){
 		this._hasChildItems = false;
-		Scholar.Notifier.trigger('modify', 'collections', this.getID());
+		Scholar.Notifier.trigger('modify', 'collection', this.getID());
 	}
 	
 	Scholar.Notifier.trigger('remove', 'item', itemID);