commit fbcd247b0926256f01109e0f25107a5abaadad1e
parent 9f7437f5caa1ef4161cea0570ba1ee7e1770e5ed
Author: David Norton <david@nortoncrew.com>
Date: Fri, 9 Jun 2006 14:42:53 +0000
Cleaned up the code in the tree views.
Fixed a bug on 'add' - items showing up in Library even if they were already there.
Diffstat:
2 files changed, 169 insertions(+), 147 deletions(-)
diff --git a/chrome/chromeFiles/content/scholar/collectionTreeView.js b/chrome/chromeFiles/content/scholar/collectionTreeView.js
@@ -1,8 +1,16 @@
Scholar.CollectionTreeView = function()
{
this._treebox = null;
- this._unregisterID = Scholar.Notifier.registerColumnTree(this);
this.refresh();
+
+ this._unregisterID = Scholar.Notifier.registerColumnTree(this);
+}
+
+Scholar.CollectionTreeView.prototype.setTree = function(treebox)
+{
+ if(this._treebox)
+ return;
+ this._treebox = treebox;
}
Scholar.CollectionTreeView.prototype.refresh = function()
@@ -19,14 +27,6 @@ Scholar.CollectionTreeView.prototype.refresh = function()
}
/*
- * Unregisters itself from Scholar.Notifier (called on window close)
- */
-Scholar.CollectionTreeView.prototype.unregister = function()
-{
- Scholar.Notifier.unregisterColumnTree(this._unregisterID);
-}
-
-/*
* Is called by Scholar.Notifier on any changes to the data layer
*/
Scholar.CollectionTreeView.prototype.notify = function(action, type, ids)
@@ -101,11 +101,12 @@ Scholar.CollectionTreeView.prototype.notify = function(action, type, ids)
this._refreshHashMap();
}
-Scholar.CollectionTreeView.prototype.setTree = function(treebox)
+/*
+ * Unregisters itself from Scholar.Notifier (called on window close)
+ */
+Scholar.CollectionTreeView.prototype.unregister = function()
{
- if(this._treebox)
- return;
- this._treebox = treebox;
+ Scholar.Notifier.unregisterColumnTree(this._unregisterID);
}
Scholar.CollectionTreeView.prototype.getCellText = function(row, column)
@@ -137,7 +138,10 @@ Scholar.CollectionTreeView.prototype.isContainerEmpty = function(row)
return true;
}
-Scholar.CollectionTreeView.prototype.getLevel = function(row) { return this._dataItems[row][2]; }
+Scholar.CollectionTreeView.prototype.getLevel = function(row)
+{
+ return this._dataItems[row][2];
+}
Scholar.CollectionTreeView.prototype.getParentIndex = function(row)
{
@@ -192,23 +196,6 @@ Scholar.CollectionTreeView.prototype.toggleOpenState = function(row)
this._refreshHashMap();
}
-Scholar.CollectionTreeView.prototype._showItem = function(item, level, beforeRow) { this._dataItems.splice(beforeRow, 0, [item, false, level]); this.rowCount++; }
-
-Scholar.CollectionTreeView.prototype._hideItem = function(row) { this._dataItems.splice(row,1); this.rowCount--; }
-
-Scholar.CollectionTreeView.prototype._getItemAtRow = function(row) { return this._dataItems[row][0]; }
-Scholar.CollectionTreeView.prototype.isSorted = function() { return false; }
-Scholar.CollectionTreeView.prototype.isSeparator = function(row) { return false; }
-Scholar.CollectionTreeView.prototype.isEditable = function(row, idx) { return false; }
-Scholar.CollectionTreeView.prototype.getRowProperties = function(row, prop) { }
-Scholar.CollectionTreeView.prototype.getColumnProperties = function(col, prop) { }
-Scholar.CollectionTreeView.prototype.getCellProperties = function(row, col, prop) { }
-Scholar.CollectionTreeView.prototype.getImageSrc = function(row, col) { }
-Scholar.CollectionTreeView.prototype.performAction = function(action) { }
-Scholar.CollectionTreeView.prototype.performActionOnCell = function(action, row, col) { }
-Scholar.CollectionTreeView.prototype.getProgressMode = function(row, col) { }
-Scholar.CollectionTreeView.prototype.cycleHeader = function(column) { }
-
Scholar.CollectionTreeView.prototype.deleteSelection = function()
{
if(this.selection.count == 0)
@@ -247,20 +234,36 @@ Scholar.CollectionTreeView.prototype.deleteSelection = function()
this.selection.select(this.rowCount-1);
}
+Scholar.CollectionTreeView.prototype._showItem = function(item, level, beforeRow)
+{
+ this._dataItems.splice(beforeRow, 0, [item, false, level]); this.rowCount++;
+}
+
+Scholar.CollectionTreeView.prototype._hideItem = function(row)
+{
+ this._dataItems.splice(row,1); this.rowCount--;
+}
+
+Scholar.CollectionTreeView.prototype._getItemAtRow = function(row)
+{
+ return this._dataItems[row][0];
+}
+
+/*
+ * Create hash map of collection ids to row indexes
+ */
Scholar.CollectionTreeView.prototype._refreshHashMap = function()
{
- // Create hash map of collection and object ids to row indexes
-
this._collectionRowMap = new Array();
- for(var i=0; i < this.rowCount; i++){
- if (this.isContainer(i)){
+ for(var i=0; i < this.rowCount; i++)
+ if (this.isContainer(i))
this._collectionRowMap[this._getItemAtRow(i).ref.getID()] = i;
- }
- }
- //Scholar.debug(Scholar.varDump(this.collectionRowMap));
- //Scholar.debug(Scholar.varDump(this.objectRowMap));
+
+
}
+/* DRAG AND DROP FUNCTIONS */
+
Scholar.CollectionTreeView.prototype.canDrop = function(row, orient)
{
if((row == 0 && orient == 1) || orient == 0)
@@ -320,9 +323,24 @@ Scholar.CollectionTreeView.prototype.getSupportedFlavours = function ()
Scholar.CollectionTreeView.prototype.onDrop = function (evt,dropdata,session) { }
+/* MORE TREEVIEW FUNCTIONS THAT HAVE TO BE HERE */
+
+Scholar.CollectionTreeView.prototype.isSorted = function() { return false; }
+Scholar.CollectionTreeView.prototype.isSeparator = function(row) { return false; }
+Scholar.CollectionTreeView.prototype.isEditable = function(row, idx) { return false; }
+Scholar.CollectionTreeView.prototype.getRowProperties = function(row, prop) { }
+Scholar.CollectionTreeView.prototype.getColumnProperties = function(col, prop) { }
+Scholar.CollectionTreeView.prototype.getCellProperties = function(row, col, prop) { }
+Scholar.CollectionTreeView.prototype.getImageSrc = function(row, col) { }
+Scholar.CollectionTreeView.prototype.performAction = function(action) { }
+Scholar.CollectionTreeView.prototype.performActionOnCell = function(action, row, col) { }
+Scholar.CollectionTreeView.prototype.getProgressMode = function(row, col) { }
+Scholar.CollectionTreeView.prototype.cycleHeader = function(column) { }
+
//
// SCHOLAR ITEMGROUP
//
+
Scholar.ItemGroup = function(type, ref)
{
this.type = type;
diff --git a/chrome/chromeFiles/content/scholar/itemTreeView.js b/chrome/chromeFiles/content/scholar/itemTreeView.js
@@ -1,15 +1,22 @@
Scholar.ItemTreeView = function(itemGroup)
{
+ this._itemGroup = itemGroup;
+
this._treebox = null;
this._savedSelection = null;
- this._dataItems = new Array();
- this.rowCount = 0;
- this._itemGroup = itemGroup;
this.refresh();
this._unregisterID = Scholar.Notifier.registerItemTree(this);
}
+Scholar.ItemTreeView.prototype.setTree = function(treebox)
+{
+ if(this._treebox)
+ return;
+ this._treebox = treebox;
+ this.sort();
+}
+
Scholar.ItemTreeView.prototype.refresh = function()
{
this._dataItems = new Array();
@@ -23,17 +30,84 @@ Scholar.ItemTreeView.prototype.refresh = function()
this._refreshHashMap();
}
-Scholar.ItemTreeView.prototype.unregister = function()
+//CALLED BY DATA LAYER ON CHANGE:
+Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
{
- Scholar.Notifier.unregisterItemTree(this._unregisterID);
+ var madeChanges = false;
+
+ this.selection.selectEventsSuppressed = true;
+ this.saveSelection();
+
+ 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(action == 'delete' || !this._itemGroup.ref.hasItem(ids[i]))
+ rows.push(this._itemRowMap[ids[i]]);
+
+ if(rows.length > 0)
+ {
+ rows.sort(function(a,b) { return a-b });
+
+ for(var i=0, len=rows.length; i<len; i++)
+ {
+ var row = rows[i];
+ this._hideItem(row-i);
+ this._treebox.rowCountChanged(row-i,-1);
+ }
+
+ madeChanges = true;
+ }
+
+ }
+ else if(action == 'modify') //must check for null because it could legitimately be 0
+ {
+ if(this._itemRowMap[ids])
+ {
+ this._treebox.invalidateRow(row);
+ madeChanges = true;
+ }
+ }
+ else if(action == 'add')
+ {
+ var item = Scholar.Items.get(ids);
+
+ if((this._itemGroup.isLibrary() || item.inCollection(this._itemGroup.ref.getID())) && this._itemRowMap[ids] == null)
+ {
+ this._showItem(item,this.rowCount);
+ this._treebox.rowCountChanged(this.rowCount-1,1);
+
+ madeChanges = true;
+ }
+ }
+
+ if(madeChanges)
+ {
+ if(this.isSorted())
+ {
+ this.sort(); //this also refreshes the hash map
+ this._treebox.invalidate();
+ }
+ else if(action != 'modify') //no need to update this if we just modified
+ {
+ this._refreshHashMap();
+ }
+
+ if(action == 'add')
+ this.selection.select(this._itemRowMap[item.getID()]);
+ else
+ this.rememberSelection();
+ }
+ this.selection.selectEventsSuppressed = false;
}
-Scholar.ItemTreeView.prototype.setTree = function(treebox)
+Scholar.ItemTreeView.prototype.unregister = function()
{
- if(this._treebox)
- return;
- this._treebox = treebox;
- this.sort();
+ Scholar.Notifier.unregisterItemTree(this._unregisterID);
}
Scholar.ItemTreeView.prototype.getCellText = function(row, column)
@@ -49,13 +123,6 @@ Scholar.ItemTreeView.prototype.getCellText = function(row, column)
return val;
}
-
-Scholar.ItemTreeView.prototype._showItem = function(item, beforeRow) { this._dataItems.splice(beforeRow, 0, item); this.rowCount++; }
-
-Scholar.ItemTreeView.prototype._hideItem = function(row) { this._dataItems.splice(row,1); this.rowCount--; }
-
-Scholar.ItemTreeView.prototype._getItemAtRow = function(row) { return this._dataItems[row]; }
-
Scholar.ItemTreeView.prototype.isSorted = function()
{
for(var i=0, len=this._treebox.columns.count; i<len; i++)
@@ -64,14 +131,6 @@ Scholar.ItemTreeView.prototype.isSorted = function()
return false;
}
-Scholar.ItemTreeView.prototype.isSeparator = function(row) { return false; }
-Scholar.ItemTreeView.prototype.isContainer = function(row) { return false; }
-Scholar.ItemTreeView.prototype.getLevel = function(row) { return 0; }
-Scholar.ItemTreeView.prototype.getRowProperties = function(row, prop) { }
-Scholar.ItemTreeView.prototype.getColumnProperties = function(col, prop) { }
-Scholar.ItemTreeView.prototype.getCellProperties = function(row, col, prop) { }
-Scholar.ItemTreeView.prototype.getImageSrc = function(row, col) { }
-
Scholar.ItemTreeView.prototype.cycleHeader = function(column)
{
for(var i=0, len=this._treebox.columns.count; i<len; i++)
@@ -172,95 +231,28 @@ Scholar.ItemTreeView.prototype.searchText = function(search)
this._treebox.invalidate();
}
-Scholar.ItemTreeView.prototype._refreshHashMap = function()
-{
- // Create hash map of item ids to row indexes
-
- this._itemRowMap = new Array();
- for(var i=0; i < this.rowCount; i++)
- this._itemRowMap[this._getItemAtRow(i).getID()] = i;
+Scholar.ItemTreeView.prototype._showItem = function(item, beforeRow)
+{
+ this._dataItems.splice(beforeRow, 0, item); this.rowCount++;
}
-Scholar.ItemTreeView.prototype.getCollectionID = function()
+Scholar.ItemTreeView.prototype._hideItem = function(row)
{
- if(this._itemGroup.isCollection())
- return this._itemGroup.ref.getID();
-
+ this._dataItems.splice(row,1); this.rowCount--;
}
-//CALLED BY DATA LAYER ON CHANGE:
-Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
+Scholar.ItemTreeView.prototype._getItemAtRow = function(row)
{
- var madeChanges = false;
-
- this.selection.selectEventsSuppressed = true;
- this.saveSelection();
+ return this._dataItems[row];
+}
- 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(action == 'delete' || !this._itemGroup.ref.hasItem(ids[i]))
- rows.push(this._itemRowMap[ids[i]]);
-
- if(rows.length > 0)
- {
- rows.sort(function(a,b) { return a-b });
-
- for(var i=0, len=rows.length; i<len; i++)
- {
- var row = rows[i];
- this._hideItem(row-i);
- this._treebox.rowCountChanged(row-i,-1);
- }
-
- madeChanges = true;
- }
-
- }
- else if(action == 'modify') //must check for null because it could legitimately be 0
- {
- if(this._itemRowMap[ids])
- {
- this._treebox.invalidateRow(row);
- madeChanges = true;
- }
- }
- else if(action == 'add')
- {
- var item = Scholar.Items.get(ids);
-
- if(this._itemGroup.isLibrary() || item.inCollection(this.getCollectionID()))
- {
- this._showItem(item,this.rowCount);
- this._treebox.rowCountChanged(this.rowCount-1,1);
-
- madeChanges = true;
- }
- }
+Scholar.ItemTreeView.prototype._refreshHashMap = function()
+{
+ // Create hash map of item ids to row indexes
- if(madeChanges)
- {
- if(this.isSorted())
- {
- this.sort(); //this also refreshes the hash map
- this._treebox.invalidate();
- }
- else if(action != 'modify') //no need to update this if we just modified
- {
- this._refreshHashMap();
- }
-
- if(action == 'add')
- this.selection.select(this._itemRowMap[item.getID()]);
- else
- this.rememberSelection();
- }
- this.selection.selectEventsSuppressed = false;
+ this._itemRowMap = new Array();
+ for(var i=0; i < this.rowCount; i++)
+ this._itemRowMap[this._getItemAtRow(i).getID()] = i;
}
Scholar.ItemTreeView.prototype.saveSelection = function()
@@ -287,6 +279,8 @@ Scholar.ItemTreeView.prototype.rememberSelection = function()
}
}
+/* DRAG AND DROP FUNCTIONS */
+
Scholar.ItemTreeView.prototype.canDrop = function(index, orient)
{
return false;
@@ -307,4 +301,14 @@ Scholar.ItemTreeView.prototype.getSupportedFlavours = function ()
}
Scholar.ItemTreeView.prototype.onDragOver = function (evt,dropdata,session) { }
-Scholar.ItemTreeView.prototype.onDrop = function (evt,dropdata,session) { }
-\ No newline at end of file
+Scholar.ItemTreeView.prototype.onDrop = function (evt,dropdata,session) { }
+
+//More functions we have to include for TreeView
+
+Scholar.ItemTreeView.prototype.isSeparator = function(row) { return false; }
+Scholar.ItemTreeView.prototype.isContainer = function(row) { return false; }
+Scholar.ItemTreeView.prototype.getLevel = function(row) { return 0; }
+Scholar.ItemTreeView.prototype.getRowProperties = function(row, prop) { }
+Scholar.ItemTreeView.prototype.getColumnProperties = function(col, prop) { }
+Scholar.ItemTreeView.prototype.getCellProperties = function(row, col, prop) { }
+Scholar.ItemTreeView.prototype.getImageSrc = function(row, col) { }
+\ No newline at end of file