Some experimentation with drag and drop (doesn't work yet)

Made some fixes on itemTreeView to allow for notify() on multiple deletes
	(shifts the row identifier up 1 for each previous delete, etc.)
	One more thing -- this might not happen because the tree calls each Item.erase() or Collection.removeItem() individually.
Bug fix on notifier.js so that register*Tree() actually returns the hash. :-)
	Unfortunately, unregister*Tree() does not seem to actually work, there is still an object at _observers['itemTree'][hash]
(temporary): When you select an item Scholar no longer loads a page into the browser.
	The javascript bugs on those HTML pages were frustrating the debugger.
This commit is contained in:
David Norton 2006-06-02 12:59:58 +00:00
parent 146d4811ab
commit fdd8245eec
5 changed files with 116 additions and 33 deletions

View File

@ -29,8 +29,16 @@ Scholar.FolderTreeView.prototype.getCellText = function(row, column)
return "";
}
Scholar.FolderTreeView.prototype.isContainer = function(row) { return this._getItemAtRow(row).isCollection(); }
Scholar.FolderTreeView.prototype.isContainerOpen = function(row) { return this._dataItems[row][1]; }
Scholar.FolderTreeView.prototype.isContainer = function(row)
{
return this._getItemAtRow(row).isCollection();
}
Scholar.FolderTreeView.prototype.isContainerOpen = function(row)
{
return this._dataItems[row][1];
}
Scholar.FolderTreeView.prototype.isContainerEmpty = function(row)
{
var itemGroup = this._getItemAtRow(row);
@ -164,6 +172,23 @@ Scholar.FolderTreeView.prototype._refreshHashMap = function()
//Scholar.debug(Scholar.varDump(this.objectRowMap));
}
Scholar.FolderTreeView.prototype.canDrop = function(row, orient)
{
if(orient == this.DROP_ON && this._getItemAtRow(row).isCollection())
return true;
else
return false;
}
Scholar.FolderTreeView.prototype.drop = function(row, orient)
{
//you can't really do anything here, look to overlay.js - ScholarCollectionsDragObserver
}
//
// SCHOLAR ITEMGROUP
//
Scholar.ItemGroup = function(type, ref)
{
this.type = type;

View File

@ -119,10 +119,10 @@ Scholar.ItemTreeView.prototype.deleteSelection = function()
else if(this._itemGroup.isCollection())
this._itemGroup.ref.removeItem(this._getItemAtRow(rows[i]-i).getID());
/* Don't do this, the notifier tells us?
//remove row from tree:
this._hideItem(rows[i]-i);
this._treebox.rowCountChanged(rows[i]-i, -1);
this._treebox.rowCountChanged(rows[i]-i, -1); */
}
this._treebox.endUpdateBatch();
@ -159,36 +159,66 @@ Scholar.ItemTreeView.prototype.getCollectionID = function()
Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
{
ids = Scholar.flattenArguments(ids);
var madeChanges = false;
for (var i=0, len=ids.length; i<len; i++){
var row = this._itemRowMap[ids[i]];
if(action == 'remove' && row)
if(action == 'remove')
{
//Since a remove involves
//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)
rows.push(this._itemRowMap[ids[i]]);
if(rows.length > 0)
{
this._hideItem(row);
this._treebox.rowCountChanged(row,-1);
}
else if(action == 'modify' && row)
{
this._treebox.invalidateRow(row)
}
else if(action == 'add' && !row)
{
var item = Scholar.Items.get(ids[i]);
rows.sort(function(a,b) { return a-b });
if(this._itemGroup.isLibrary() || item.inCollection(this.getCollectionID()))
for(var i=0, len=rows.length; i<len; i++)
{
this._showItem(item,this.rowCount);
this._treebox.rowCountChanged(this.rowCount,1);
var row = rows[i];
this._hideItem(row-i);
this._treebox.rowCountChanged(row-i,-1);
}
//TODO: sorted? figure it out later
}
else
{
return;
}
madeChanges = true;
}
}
else
{
for (var i=0, len=ids.length; i<len; i++)
{
var row = this._itemRowMap[ids[i]];
if(action == 'modify' && row != null) //must check for null because it could legitimately be 0
{
this._treebox.invalidateRow(row)
}
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);
}
madeChanges = true;
//TODO: sorted? figure it out later
}
}
}
this._refreshHashMap();
if(madeChanges)
this._refreshHashMap();
}
Scholar.ItemTreeView.prototype.canDrop = function(index, orient)
{
return false;
}

View File

@ -56,8 +56,8 @@ var ScholarPane = new function()
function folderSelected()
{
//if(itemsView)
// itemsView.unregister();
if(itemsView)
itemsView.unregister();
if(foldersView.selection.count == 1 && foldersView.selection.currentIndex != -1)
{
@ -88,7 +88,7 @@ var ScholarPane = new function()
if(!validURL(url))
url = 'http://www.google.com/search?q='+encodeURIComponent('"'+item.getField("title")+'"'); //+'&btnI'
document.getElementById('content').loadURI(url);
// document.getElementById('content').loadURI(url);
document.getElementById('scholar-floater').hidden=false;
}
else
@ -129,4 +129,30 @@ var ScholarPane = new function()
}
}
var ScholarItemsDragObserver =
{
onDragStart: function (evt,transferData,action)
{
transferData.data=new TransferData();
transferData.data.addDataForFlavour("text/unicode","finally");
}
};
var ScholarCollectionsDragObserver =
{
getSupportedFlavours : function ()
{
var flavours = new FlavourSet();
flavours.appendFlavour("text/unicode");
return flavours;
},
onDragOver: function (evt,dropdata,session){},
onDrop: function (evt,dropdata,session)
{
alert(dropdata.data);
}
}
window.addEventListener("load", function(e) { ScholarPane.init(e); }, false);

View File

@ -33,6 +33,7 @@
<hbox flex="1">
<tree id="folders-tree" hidecolumnpicker="true"
onselect="ScholarPane.folderSelected();" seltype="single"
ondragover="nsDragAndDrop.dragOver(event,ScholarCollectionsDragObserver)" ondragdrop="nsDragAndDrop.drop(event,ScholarCollectionsDragObserver)"
persist="width" flex="1">
<treecols>
<treecol
@ -48,6 +49,7 @@
id="items-tree"
enableColumnDrag="true" onkeypress="if(event.keyCode == event.DOM_VK_BACK_SPACE || event.keyCode == event.DOM_VK_DELETE){ ScholarPane.deleteSelection(); return false; }"
onselect="ScholarPane.itemSelected();"
ondraggesture="if (event.target.localName == 'treechildren') nsDragAndDrop.startDrag(event,ScholarItemsDragObserver);"
persist="width" flex="5">
<treecols>
<treecol

View File

@ -10,11 +10,11 @@ Scholar.Notifier = new function(){
this.trigger = trigger;
function registerColumnTree(ref){
_register('columnTree', ref);
return _register('columnTree', ref);
}
function registerItemTree(ref){
_register('itemTree', ref);
return _register('itemTree', ref);
}
function unregisterColumnTree(hash){