Folders deletion logic added (needs Folder.erase() which should recursively delete children as well)

This commit is contained in:
David Norton 2006-05-19 15:26:54 +00:00
parent 0fa7c008aa
commit 72a2dd9216
2 changed files with 37 additions and 26 deletions

View File

@ -134,37 +134,48 @@ Scholar.TreeView.prototype.performAction = function(action) { }
Scholar.TreeView.prototype.performActionOnCell = function(action, row, col) { } Scholar.TreeView.prototype.performActionOnCell = function(action, row, col) { }
Scholar.TreeView.prototype.getProgressMode = function(row, col) { } Scholar.TreeView.prototype.getProgressMode = function(row, col) { }
Scholar.TreeView.prototype.deleteSelectedItem = function() Scholar.TreeView.prototype.deleteSelection = function()
{ {
if(this.selection.count == 0) if(this.selection.count == 0)
{ {
return; return;
} }
else if(confirm("Are you sure you want to delete the selected item"+(this.selection.count > 1 ? "s" : "")+"?")) if(!confirm("Are you sure you want to delete the selected item"+(this.selection.count > 1 ? "s" : "")+"?"))
{ {
var items = new Array(); return;
}
//collapse open folders
for(var i=0; i<this.rowCount; i++)
{
if(this.selection.isSelected(i) && this.isContainer(i) && this.isContainerOpen(i))
this.toggleOpenState(i);
}
//create an array of selected items/folders
var rows = new Array();
var start = new Object(); var start = new Object();
var end = new Object(); var end = new Object();
for (var i=0, len=this.selection.getRangeCount(); i<len; i++) for (var i=0, len=this.selection.getRangeCount(); i<len; i++)
{ {
this.selection.getRangeAt(i,start,end); this.selection.getRangeAt(i,start,end);
for (var j=start.value; j<=end.value; j++) for (var j=start.value; j<=end.value; j++)
if(!this.isContainer(j)) rows.push(j);
items.push(j);
} }
//iterate and erase...
this._treebox.beginUpdateBatch(); this._treebox.beginUpdateBatch();
for (var i=0; i<items.length; i++) for (var i=0; i<rows.length; i++)
{ {
this._getItemAtRow(items[i]-i).erase(); this._getItemAtRow(rows[i]-i).erase(); //erases item/folder from DB
this._hideItem(items[i]-i);
//remove row from tree
this._hideItem(rows[i]-i);
this.rowCount--; this.rowCount--;
this._treebox.rowCountChanged(items[i]-i, -1); this._treebox.rowCountChanged(rows[i]-i, -1);
} }
this._treebox.endUpdateBatch(); this._treebox.endUpdateBatch();
}
} }
/* /*
DRAG AND DROP (IMPLEMENT LATER) DRAG AND DROP (IMPLEMENT LATER)

View File

@ -11,8 +11,8 @@
<script src="include.js"/> <script src="include.js"/>
<script src="sidebar.js"/> <script src="sidebar.js"/>
<keyset> <keyset>
<key id="delete-cmd" keycode="VK_DELETE" oncommand="myTreeView.deleteSelectedItem()"/> <key id="delete-cmd" keycode="VK_DELETE" oncommand="myTreeView.deleteSelection()"/>
<key id="backspace-cmd" keycode="VK_BACK" oncommand="myTreeView.deleteSelectedItem()"/> <key id="backspace-cmd" keycode="VK_BACK" oncommand="myTreeView.deleteSelection()"/>
</keyset> </keyset>
<stringbundle id="scholar-strings" src="chrome://scholar/locale/scholar.properties"/> <stringbundle id="scholar-strings" src="chrome://scholar/locale/scholar.properties"/>
<vbox id="list-pane" flex="1"> <vbox id="list-pane" flex="1">