From 2399f044e1d9ef7bff6432d0da9f2898b3f62c12 Mon Sep 17 00:00:00 2001 From: David Norton Date: Wed, 14 Jun 2006 15:51:05 +0000 Subject: [PATCH] [Drag and Drop] in the Collections Tree: Now checks to make sure that the correct type is being dragged, and that you aren't dropping a folder into subfolders, etc. [Drag and Drop] in Items Tree: You can drag items from one window into another, directly into the Items list. [Editing] Close the edit box and save when you click on its label --- .../content/scholar/collectionTreeView.js | 45 ++++++++++++++++--- .../chromeFiles/content/scholar/itemPane.js | 1 + .../content/scholar/itemTreeView.js | 26 ++++++++--- .../chromeFiles/content/scholar/overlay.xul | 1 + 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/chrome/chromeFiles/content/scholar/collectionTreeView.js b/chrome/chromeFiles/content/scholar/collectionTreeView.js index 9de2a9d251..43dd238f4d 100644 --- a/chrome/chromeFiles/content/scholar/collectionTreeView.js +++ b/chrome/chromeFiles/content/scholar/collectionTreeView.js @@ -272,10 +272,35 @@ Scholar.CollectionTreeView.prototype._refreshHashMap = function() Scholar.CollectionTreeView.prototype.canDrop = function(row, orient) { - if((row == 0 && orient == 1) || orient == 0) - return true; - else + if(typeof row == 'object') //workaround... two different services call canDrop (nsDragAndDrop, and the tree) return false; + + try + { + var dataSet = nsTransferable.get(this.getSupportedFlavours(),nsDragAndDrop.getDragData, true); + } + catch (e) + { + //a work around a limitation in nsDragAndDrop.js -- the mDragSession is not set until the drag moves over another control. (this will only happen if the first drag is from the collection list) + nsDragAndDrop.mDragSession = nsDragAndDrop.mDragService.getCurrentSession(); + return false; + } + var data = dataSet.first.first; + var dataType = data.flavour.contentType; + var rowCollection = this._getItemAtRow(row).ref; + + if(orient == 1 && row == 0 && dataType == 'scholar/collection') + { + return true; + } + else if(orient == 0) + { + if(dataType == 'scholar/item' || dataType == "text/x-moz-url") + return true; + else if(dataType='scholar/collection' && data.data != rowCollection.getID() && !Scholar.Collections.get(data.data).hasDescendent('collection',rowCollection.getID()) ) + return true; + } + return false; } Scholar.CollectionTreeView.prototype.drop = function(row, orient) @@ -283,7 +308,6 @@ Scholar.CollectionTreeView.prototype.drop = function(row, orient) 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') { @@ -292,10 +316,10 @@ Scholar.CollectionTreeView.prototype.drop = function(row, orient) var targetCollectionID; if(this._getItemAtRow(row).isCollection()) targetCollectionID = this._getItemAtRow(row).ref.getID(); - var droppedCollection = Scholar.Collections.get(ids[0]); + var droppedCollection = Scholar.Collections.get(data.data); droppedCollection.changeParent(targetCollectionID); - var selectRow = this._collectionRowMap[ids[0]]; + var selectRow = this._collectionRowMap[data.data]; if(selectRow == null) selectRow = this._collectionRowMap[targetCollectionID]; @@ -307,10 +331,18 @@ Scholar.CollectionTreeView.prototype.drop = function(row, orient) } else if(dataType == 'scholar/item' && this.canDrop(row, orient)) { + var ids = data.data.split(','); var targetCollection = this._getItemAtRow(row).ref; for(var i = 0; i