From fbcd247b0926256f01109e0f25107a5abaadad1e Mon Sep 17 00:00:00 2001 From: David Norton Date: Fri, 9 Jun 2006 14:42:53 +0000 Subject: [PATCH] Cleaned up the code in the tree views. Fixed a bug on 'add' - items showing up in Library even if they were already there. --- .../content/scholar/collectionTreeView.js | 96 +++++--- .../content/scholar/itemTreeView.js | 222 +++++++++--------- 2 files changed, 170 insertions(+), 148 deletions(-) diff --git a/chrome/chromeFiles/content/scholar/collectionTreeView.js b/chrome/chromeFiles/content/scholar/collectionTreeView.js index 208a2a387d..059a04a954 100644 --- 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() @@ -18,14 +26,6 @@ Scholar.CollectionTreeView.prototype.refresh = function() this._refreshHashMap(); } -/* - * 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 */ @@ -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 index 99c742b9a4..3a925b4d22 100644 --- 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,19 +30,86 @@ Scholar.ItemTreeView.prototype.refresh = function() this._refreshHashMap(); } +//CALLED BY DATA LAYER ON CHANGE: +Scholar.ItemTreeView.prototype.notify = function(action, type, ids) +{ + 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 0) + { + rows.sort(function(a,b) { return a-b }); + + for(var i=0, len=rows.length; i 0) - { - rows.sort(function(a,b) { return a-b }); - - for(var i=0, len=rows.length; i