From 1d14c69ad54171e17b93f4b108149a7d0c2b6f44 Mon Sep 17 00:00:00 2001 From: David Norton Date: Thu, 8 Jun 2006 18:42:55 +0000 Subject: [PATCH] [interface] Preliminary drag-and-drop. 1) Items into collections. 2) Collections into collections. Dan S, please check this out, I am getting some exceptions from the data access portion. [interface] Temporarily, "metadata" pane on the right is not resizable. --- .../content/scholar/collectionTreeView.js | 68 ++++++++++++++++--- .../content/scholar/itemTreeView.js | 19 +++++- chrome/chromeFiles/content/scholar/overlay.js | 44 ++++-------- .../chromeFiles/content/scholar/overlay.xul | 10 +-- .../skin/default/scholar/overlay.css | 1 - 5 files changed, 97 insertions(+), 45 deletions(-) diff --git a/chrome/chromeFiles/content/scholar/collectionTreeView.js b/chrome/chromeFiles/content/scholar/collectionTreeView.js index 22898b2ab9..4a46f0d99e 100644 --- a/chrome/chromeFiles/content/scholar/collectionTreeView.js +++ b/chrome/chromeFiles/content/scholar/collectionTreeView.js @@ -1,10 +1,21 @@ Scholar.CollectionTreeView = function() { this._treebox = null; + this._unregisterID = Scholar.Notifier.registerColumnTree(this); + this.refresh(); +} + +Scholar.CollectionTreeView.prototype.refresh = function() +{ this._dataItems = new Array(); this.rowCount = 0; this._showItem(new Scholar.ItemGroup('library',null),0,1); - this._unregisterID = Scholar.Notifier.registerColumnTree(this); + + var newRows = Scholar.getCollections(); + for(var i = 0; i < newRows.length; i++) + this._showItem(new Scholar.ItemGroup('collection',newRows[i]), 0, this._dataItems.length); //item ref, level, beforeRow + + this._refreshHashMap(); } /* @@ -80,12 +91,6 @@ Scholar.CollectionTreeView.prototype.setTree = function(treebox) if(this._treebox) return; this._treebox = treebox; - - var newRows = Scholar.getCollections(); - for(var i = 0; i < newRows.length; i++) - this._showItem(new Scholar.ItemGroup('collection',newRows[i]), 0, this._dataItems.length); //item ref, level, beforeRow - - this._refreshHashMap(); } Scholar.CollectionTreeView.prototype.getCellText = function(row, column) @@ -243,18 +248,61 @@ Scholar.CollectionTreeView.prototype._refreshHashMap = function() Scholar.CollectionTreeView.prototype.canDrop = function(row, orient) { - if(orient == this.DROP_ON && this._getItemAtRow(row).isCollection()) + if(orient == 0 && this._getItemAtRow(row).isCollection()) + { + Scholar.debug("drag on row: " + row + " orient: " + orient); return true; + } else return false; - } Scholar.CollectionTreeView.prototype.drop = function(row, orient) { - //you can't really do anything here, look to overlay.js - ScholarCollectionsDragObserver + var dataSet = nsTransferable.get(this.getSupportedFlavours(),nsDragAndDrop.getDragData, true); + var data = dataSet.first.first; + var dataType = data.flavour.contentType; + var ids = data.data.split(','); + + if(dataType == 'scholar/collection') + { + var oldCount = this.rowCount; + + var targetCollectionID; + if(this.canDrop(row,orient)) + targetCollectionID = this._getItemAtRow(row).ref.getID(); + + var droppedCollection = Scholar.Collections.get(ids[0]); + droppedCollection.changeParent(targetCollectionID); + this.refresh(); + this._treebox.rowCountChanged(0,this.rowCount-oldCount); + this._treebox.invalidate(); + } + else if(dataType == 'scholar/item' && this.canDrop(row, orient)) + { + var targetCollection = this._getItemAtRow(row).ref; + for(var i = 0; i @@ -57,7 +58,8 @@ id="items-tree" enableColumnDrag="true" onkeypress="if(event.keyCode == event.DOM_VK_BACK_SPACE || event.keyCode == event.DOM_VK_DELETE){ ScholarPane.deleteItemSelection(); return false; }" onselect="ScholarPane.itemSelected();" - ondraggesture="if (event.target.localName == 'treechildren') nsDragAndDrop.startDrag(event,ScholarItemsDragObserver);" + ondraggesture="if (event.target.localName == 'treechildren') nsDragAndDrop.startDrag(event,ScholarPane.getItemsView());" + ondragover="nsDragAndDrop.dragOver(event,ScholarPane.getItemsView())" ondragdrop="nsDragAndDrop.drop(event,ScholarPane.getItemsView())" flex="1"> -