diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index 7e0106550..29b52f6eb 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -202,6 +202,7 @@ Zotero.Translate.Sandbox = { // TODO: This used to only be used for some modes. Since it's now used for everything with // async saving, there's probably a bunch of code for the non-queued mode that can be removed. translate.saveQueue.push(item); + translate._savingItems++; }, /** @@ -1539,71 +1540,74 @@ Zotero.Translate.Base.prototype = { * Saves items to the database, taking care to defer attachmentProgress notifications * until after save */ - _saveItems: function (items) { + _saveItems: Zotero.Promise.coroutine(function* (items) { var itemDoneEventsDispatched = false; var deferredProgress = []; var attachmentsWithProgress = []; - this._savingItems++; - return this._itemSaver.saveItems( - items.slice(), - function (attachment, progress, error) { - var attachmentIndex = this._savingAttachments.indexOf(attachment); - if(progress === false || progress === 100) { - if(attachmentIndex !== -1) { - this._savingAttachments.splice(attachmentIndex, 1); + try { + var newItems = yield this._itemSaver.saveItems( + items.slice(), + function (attachment, progress, error) { + var attachmentIndex = this._savingAttachments.indexOf(attachment); + if(progress === false || progress === 100) { + if(attachmentIndex !== -1) { + this._savingAttachments.splice(attachmentIndex, 1); + } + } else if(attachmentIndex === -1) { + this._savingAttachments.push(attachment); } - } else if(attachmentIndex === -1) { - this._savingAttachments.push(attachment); - } - - if(itemDoneEventsDispatched) { - // itemDone event has already fired, so we can fire attachmentProgress - // notifications - this._runHandler("attachmentProgress", attachment, progress, error); - this._checkIfDone(); - } else { - // Defer until after we fire the itemDone event - deferredProgress.push([attachment, progress, error]); - attachmentsWithProgress.push(attachment); - } - }.bind(this) - ) - .then(function (newItems) { - // Remove attachments not being saved from item.attachments - for(var i=0; i