Cleaned up the code in the tree views.
Fixed a bug on 'add' - items showing up in Library even if they were already there.
This commit is contained in:
parent
9f7437f5ca
commit
fbcd247b09
2 changed files with 170 additions and 148 deletions
|
@ -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;
|
||||
|
|
|
@ -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<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.unregister = function()
|
||||
{
|
||||
Scholar.Notifier.unregisterItemTree(this._unregisterID);
|
||||
}
|
||||
|
||||
Scholar.ItemTreeView.prototype.setTree = function(treebox)
|
||||
{
|
||||
if(this._treebox)
|
||||
return;
|
||||
this._treebox = treebox;
|
||||
this.sort();
|
||||
}
|
||||
|
||||
Scholar.ItemTreeView.prototype.getCellText = function(row, column)
|
||||
{
|
||||
var obj = this._getItemAtRow(row);
|
||||
|
@ -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,6 +231,21 @@ Scholar.ItemTreeView.prototype.searchText = function(search)
|
|||
this._treebox.invalidate();
|
||||
}
|
||||
|
||||
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._refreshHashMap = function()
|
||||
{
|
||||
// Create hash map of item ids to row indexes
|
||||
|
@ -181,88 +255,6 @@ Scholar.ItemTreeView.prototype._refreshHashMap = function()
|
|||
this._itemRowMap[this._getItemAtRow(i).getID()] = i;
|
||||
}
|
||||
|
||||
Scholar.ItemTreeView.prototype.getCollectionID = function()
|
||||
{
|
||||
if(this._itemGroup.isCollection())
|
||||
return this._itemGroup.ref.getID();
|
||||
|
||||
}
|
||||
|
||||
//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<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;
|
||||
}
|
||||
}
|
||||
|
||||
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.saveSelection = function()
|
||||
{
|
||||
this._savedSelection = new Array();
|
||||
|
@ -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) { }
|
||||
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) { }
|
Loading…
Reference in a new issue