Fix dragging external files onto library root
This commit is contained in:
parent
b01487dccc
commit
e282a5643f
2 changed files with 52 additions and 58 deletions
|
@ -60,7 +60,7 @@ Zotero.Attachments = new function(){
|
||||||
throw new Error("parentItemID and collections cannot both be provided");
|
throw new Error("parentItemID and collections cannot both be provided");
|
||||||
}
|
}
|
||||||
|
|
||||||
var attachmentItem, itemID, newFile, contentType;
|
var attachmentItem, itemID, newFile, contentType, destDir;
|
||||||
try {
|
try {
|
||||||
yield Zotero.DB.executeTransaction(function* () {
|
yield Zotero.DB.executeTransaction(function* () {
|
||||||
// Create a new attachment
|
// Create a new attachment
|
||||||
|
|
|
@ -2227,72 +2227,66 @@ Zotero.CollectionTreeView.prototype.drop = Zotero.Promise.coroutine(function* (r
|
||||||
var parentCollectionID = false;
|
var parentCollectionID = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var commitNotifier = Zotero.Notifier.begin();
|
for (var i=0; i<data.length; i++) {
|
||||||
try {
|
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') {
|
if (url.indexOf('file:///') == 0) {
|
||||||
var url = data[i];
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||||
|
.getService(Components.interfaces.nsIWindowMediator);
|
||||||
if (url.indexOf('file:///') == 0) {
|
var win = wm.getMostRecentWindow("navigator:browser");
|
||||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
// If dragging currently loaded page, only convert to
|
||||||
.getService(Components.interfaces.nsIWindowMediator);
|
// file if not an HTML document
|
||||||
var win = wm.getMostRecentWindow("navigator:browser");
|
if (win.content.location.href != url ||
|
||||||
// If dragging currently loaded page, only convert to
|
win.content.document.contentType != 'text/html') {
|
||||||
// file if not an HTML document
|
var nsIFPH = Components.classes["@mozilla.org/network/protocol;1?name=file"]
|
||||||
if (win.content.location.href != url ||
|
.getService(Components.interfaces.nsIFileProtocolHandler);
|
||||||
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]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
yield Zotero.Attachments.importFromFile({
|
|
||||||
file: file,
|
|
||||||
libraryID: targetLibraryID,
|
|
||||||
collections: [parentCollectionID]
|
|
||||||
});
|
|
||||||
// If moving, delete original file
|
|
||||||
if (dragData.dropEffect == 'move') {
|
|
||||||
try {
|
try {
|
||||||
file.remove(false);
|
var file = nsIFPH.getFileFromURLSpec(url);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
Components.utils.reportError("Error deleting original file " + file.path + " after drag");
|
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 ? [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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue