commit e282a5643f86047e57272d09a3382c8af5ae458f
parent b01487dccc080b7de026417c4ca5ba11e62ea0ea
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 27 Dec 2016 03:11:21 -0500
Fix dragging external files onto library root
Diffstat:
2 files changed, 51 insertions(+), 57 deletions(-)
diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js
@@ -60,7 +60,7 @@ Zotero.Attachments = new function(){
throw new Error("parentItemID and collections cannot both be provided");
}
- var attachmentItem, itemID, newFile, contentType;
+ var attachmentItem, itemID, newFile, contentType, destDir;
try {
yield Zotero.DB.executeTransaction(function* () {
// Create a new attachment
diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js
@@ -2227,72 +2227,66 @@ Zotero.CollectionTreeView.prototype.drop = Zotero.Promise.coroutine(function* (r
var parentCollectionID = false;
}
- var commitNotifier = Zotero.Notifier.begin();
- try {
- for (var i=0; i<data.length; i++) {
- var file = data[i];
+ for (var i=0; i<data.length; i++) {
+ var file = data[i];
+
+ if (dataType == 'text/x-moz-url') {
+ var url = data[i];
- if (dataType == 'text/x-moz-url') {
- var url = data[i];
-
- if (url.indexOf('file:///') == 0) {
- var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
- .getService(Components.interfaces.nsIWindowMediator);
- var win = wm.getMostRecentWindow("navigator:browser");
- // If dragging currently loaded page, only convert to
- // file if not an HTML document
- if (win.content.location.href != url ||
- win.content.document.contentType != 'text/html') {
- var nsIFPH = Components.classes["@mozilla.org/network/protocol;1?name=file"]
- .getService(Components.interfaces.nsIFileProtocolHandler);
- try {
- var file = nsIFPH.getFileFromURLSpec(url);
- }
- catch (e) {
- Zotero.debug(e);
- }
+ if (url.indexOf('file:///') == 0) {
+ var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Components.interfaces.nsIWindowMediator);
+ var win = wm.getMostRecentWindow("navigator:browser");
+ // If dragging currently loaded page, only convert to
+ // file if not an HTML document
+ if (win.content.location.href != url ||
+ win.content.document.contentType != 'text/html') {
+ var nsIFPH = Components.classes["@mozilla.org/network/protocol;1?name=file"]
+ .getService(Components.interfaces.nsIFileProtocolHandler);
+ try {
+ var file = nsIFPH.getFileFromURLSpec(url);
+ }
+ catch (e) {
+ Zotero.debug(e);
}
}
-
- // Still string, so remote URL
- if (typeof file == 'string') {
- var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
- .getService(Components.interfaces.nsIWindowMediator);
- var win = wm.getMostRecentWindow("navigator:browser");
- win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack', null, row); // TODO: don't do this
- continue;
- }
-
- // Otherwise file, so fall through
}
- if (dropEffect == 'link') {
- yield Zotero.Attachments.linkFromFile({
- file: file,
- collections: [parentCollectionID]
- });
+ // Still string, so remote URL
+ if (typeof file == 'string') {
+ var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Components.interfaces.nsIWindowMediator);
+ var win = wm.getMostRecentWindow("navigator:browser");
+ win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack', null, row); // TODO: don't do this
+ continue;
}
- else {
- yield Zotero.Attachments.importFromFile({
- file: file,
- libraryID: targetLibraryID,
- collections: [parentCollectionID]
- });
- // If moving, delete original file
- if (dragData.dropEffect == 'move') {
- try {
- file.remove(false);
- }
- catch (e) {
- Components.utils.reportError("Error deleting original file " + file.path + " after drag");
- }
+
+ // Otherwise file, so fall through
+ }
+
+ if (dropEffect == 'link') {
+ yield Zotero.Attachments.linkFromFile({
+ file: file,
+ collections: parentCollectionID ? [parentCollectionID] : undefined
+ });
+ }
+ else {
+ yield Zotero.Attachments.importFromFile({
+ file: file,
+ libraryID: targetLibraryID,
+ collections: parentCollectionID ? [parentCollectionID] : undefined
+ });
+ // If moving, delete original file
+ if (dragData.dropEffect == 'move') {
+ try {
+ file.remove(false);
+ }
+ catch (e) {
+ Components.utils.reportError("Error deleting original file " + file.path + " after drag");
}
}
}
}
- finally {
- Zotero.Notifier.commit(unlock);
- }
}
});