diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js index f3168f4c35..76e0415a22 100644 --- a/chrome/content/zotero/fileInterface.js +++ b/chrome/content/zotero/fileInterface.js @@ -281,7 +281,7 @@ var Zotero_File_Interface = new function() { args.wrappedJSObject = args; Services.ww.openWindow(null, "chrome://zotero/content/import/importWizard.xul", - "importFile", "chrome,dialog=yes,centerscreen,width=600,height=400", args); + "importFile", "chrome,dialog=yes,centerscreen,width=600,height=400,modal", args); }; @@ -514,12 +514,15 @@ var Zotero_File_Interface = new function() { yield onBeforeImport(translation); } - let failed = false; + var notifierQueue = new Zotero.Notifier.Queue; try { yield translation.translate({ libraryID, collections: importCollection ? [importCollection.id] : null, - linkFiles + linkFiles, + saveOptions: { + notifierQueue + } }); } catch(e) { if (!showProgressWindow) { @@ -535,6 +538,9 @@ var Zotero_File_Interface = new function() { ); return false; } + finally { + yield Zotero.Notifier.commit(notifierQueue); + } var numItems = translation.newItems.length; diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 0988c2acd1..f3de0cefba 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -263,6 +263,7 @@ Zotero.Attachments = new function(){ /** * @param {Object} options - 'file', 'url', 'title', 'contentType', 'charset', 'parentItemID', 'singleFile' + * @param {Object} [options.saveOptions] - Options to pass to Zotero.Item::save() * @return {Promise} */ this.importSnapshotFromFile = Zotero.Promise.coroutine(function* (options) { @@ -279,6 +280,7 @@ Zotero.Attachments = new function(){ var contentType = options.contentType; var charset = options.charset; var parentItemID = options.parentItemID; + var saveOptions = options.saveOptions; if (!parentItemID) { throw new Error("parentItemID not provided"); @@ -302,7 +304,7 @@ Zotero.Attachments = new function(){ // DEBUG: this should probably insert access date too so as to // create a proper item, but at the moment this is only called by // translate.js, which sets the metadata fields itself - itemID = yield attachmentItem.save(); + itemID = yield attachmentItem.save(saveOptions); var storageDir = Zotero.getStorageDirectory(); destDir = this.getStorageDirectory(attachmentItem); @@ -361,7 +363,7 @@ Zotero.Attachments = new function(){ * @param {String} [options.contentType] * @param {String} [options.referrer] * @param {CookieSandbox} [options.cookieSandbox] - * @param {Object} [options.saveOptions] + * @param {Object} [options.saveOptions] - Options to pass to Zotero.Item::save() * @return {Promise} - A promise for the created attachment item */ this.importFromURL = Zotero.Promise.coroutine(function* (options) { @@ -531,7 +533,7 @@ Zotero.Attachments = new function(){ * @param {String} [options.title] * @param {String} options.contentType * @param {String[]} [options.collections] - * @param {Object} [options.saveOptions] + * @param {Object} [options.saveOptions] - Options to pass to Zotero.Item::save() * @return {Zotero.Item} */ this.createURLAttachmentFromTemporaryStorageDirectory = async function (options) { @@ -595,6 +597,7 @@ Zotero.Attachments = new function(){ * Create a link attachment from a URL * * @param {Object} options - 'url', 'parentItemID', 'contentType', 'title', 'collections' + * @param {Object} [options.saveOptions] - Options to pass to Zotero.Item::save() * @return {Promise} - A promise for the created attachment item */ this.linkFromURL = Zotero.Promise.coroutine(function* (options) { @@ -605,6 +608,7 @@ Zotero.Attachments = new function(){ var contentType = options.contentType; var title = options.title; var collections = options.collections; + var saveOptions = options.saveOptions; var schemeRE = /^([a-z][a-z0-9+.-]+):/; var matches = url.match(schemeRE); @@ -657,7 +661,8 @@ Zotero.Attachments = new function(){ linkMode: this.LINK_MODE_LINKED_URL, contentType, parentItemID, - collections + collections, + saveOptions, }); }); @@ -666,6 +671,7 @@ Zotero.Attachments = new function(){ * TODO: what if called on file:// document? * * @param {Object} options - 'document', 'parentItemID', 'collections' + * @param {Object} [options.saveOptions] - Options to pass to Zotero.Item::save() * @return {Promise} */ this.linkFromDocument = Zotero.Promise.coroutine(function* (options) { @@ -674,6 +680,7 @@ Zotero.Attachments = new function(){ var document = options.document; var parentItemID = options.parentItemID; var collections = options.collections; + var saveOptions = options.saveOptions; if (parentItemID && collections) { throw new Error("parentItemID and collections cannot both be provided"); @@ -690,7 +697,8 @@ Zotero.Attachments = new function(){ contentType, charset: document.characterSet, parentItemID, - collections + collections, + saveOptions, }); if (Zotero.Fulltext.isCachedMIMEType(contentType)) { @@ -709,6 +717,7 @@ Zotero.Attachments = new function(){ * Save a snapshot from a Document * * @param {Object} options - 'libraryID', 'document', 'parentItemID', 'forceTitle', 'collections' + * @param {Object} [options.saveOptions] - Options to pass to Zotero.Item::save() * @return {Promise} - A promise for the created attachment item */ this.importFromDocument = Zotero.Promise.coroutine(function* (options) { @@ -719,6 +728,7 @@ Zotero.Attachments = new function(){ var parentItemID = options.parentItemID; var title = options.title; var collections = options.collections; + var saveOptions = options.saveOptions; if (parentItemID && collections) { throw new Error("parentItemID and parentCollectionIDs cannot both be provided"); @@ -796,7 +806,7 @@ Zotero.Attachments = new function(){ attachmentItem.setCollections(collections); } attachmentItem.attachmentPath = 'storage:' + fileName; - var itemID = yield attachmentItem.save(); + var itemID = yield attachmentItem.save(saveOptions); Zotero.Fulltext.queueItem(attachmentItem); diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index ad30d33950..7805e16989 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -551,7 +551,8 @@ Zotero.Translate.ItemSaver.prototype = { title: attachment.title, contentType: attachment.mimeType, parentItemID, - collections: !parentItemID ? this._collections : undefined + collections: !parentItemID ? this._collections : undefined, + saveOptions: this._saveOptions, }); } @@ -605,7 +606,8 @@ Zotero.Translate.ItemSaver.prototype = { parentItemID, contentType: attachment.mimeType || undefined, title: attachment.title || undefined, - collections: !parentItemID ? this._collections : undefined + collections: !parentItemID ? this._collections : undefined, + saveOptions: this._saveOptions, }); } else if (this._linkFiles @@ -615,7 +617,8 @@ Zotero.Translate.ItemSaver.prototype = { newItem = yield Zotero.Attachments.linkFromFile({ file, parentItemID, - collections: !parentItemID ? this._collections : undefined + collections: !parentItemID ? this._collections : undefined, + saveOptions: this._saveOptions, }); if (attachment.title) { newItem.setField("title", attachment.title); @@ -634,7 +637,8 @@ Zotero.Translate.ItemSaver.prototype = { contentType: attachment.mimeType, charset: attachment.charset, parentItemID, - collections: !parentItemID ? this._collections : undefined + collections: !parentItemID ? this._collections : undefined, + saveOptions: this._saveOptions, }); } else { @@ -642,7 +646,8 @@ Zotero.Translate.ItemSaver.prototype = { newItem = yield Zotero.Attachments.importFromFile({ file: file, parentItemID, - collections: !parentItemID ? this._collections : undefined + collections: !parentItemID ? this._collections : undefined, + saveOptions: this._saveOptions, }); if (attachment.title) newItem.setField("title", attachment.title); } @@ -830,7 +835,8 @@ Zotero.Translate.ItemSaver.prototype = { parentItemID, contentType: mimeType, title, - collections: !parentItemID ? this._collections : undefined + collections: !parentItemID ? this._collections : undefined, + saveOptions: this._saveOptions, }); } @@ -846,7 +852,8 @@ Zotero.Translate.ItemSaver.prototype = { document: attachment.document, parentItemID, title, - collections: !parentItemID ? this._collections : undefined + collections: !parentItemID ? this._collections : undefined, + saveOptions: this._saveOptions, }); } @@ -872,7 +879,8 @@ Zotero.Translate.ItemSaver.prototype = { contentType: mimeType, referrer: this._referrer, cookieSandbox: this._cookieSandbox, - collections: !parentItemID ? this._collections : undefined + collections: !parentItemID ? this._collections : undefined, + saveOptions: this._saveOptions, }); }),