diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index 463b29c941..7cacab00cc 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -78,10 +78,8 @@ Zotero.Translate.ItemSaver.prototype = { Zotero.debug("Translate: Beginning transaction"); Zotero.DB.beginTransaction(); - this._timer = Components.classes["@mozilla.org/timer;1"]. - createInstance(Components.interfaces.nsITimer); - this._timer.initWithCallback(this, 0, Components.interfaces.nsITimer.TYPE_ONE_SHOT); - + var me = this; + Zotero.setTimeout(function() { me._closeTransaction() }, 0); Zotero.showZoteroPaneProgressMeter(Zotero.getString("ingester.scraping"), false); } @@ -514,15 +512,9 @@ Zotero.Translate.ItemSaver.prototype = { }, /** - * Implements nsITimer.notify, closing the transaction when the current code block finishes - * executing. + * Closes the transaction when the current code block finishes executing. */ - "notify":function() { - if(Zotero.waiting) { - this._timer.initWithCallback(this, 0, Components.interfaces.nsITimer.TYPE_ONE_SHOT); - return; - } - + "_closeTransaction":function() { Zotero.debug("Translate: Closing transaction"); Zotero.hideZoteroPaneOverlay(); Zotero.DB.commitTransaction(); diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index cc673908d3..20b18d1e00 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -1523,17 +1523,19 @@ if(appInfo.platformVersion[0] >= 2) { }; /** - * Emulates the behavior of window.setTimeout, but ensures that timeouts do not get called + * Emulates the behavior of window.setTimeout, but ensures that callbacks do not get called * during Zotero.wait() * - * @param {Function} func The function to be called - * @param {Integer} ms The number of milliseconds to wait before calling func + * @param {Function} func The function to be called + * @param {Integer} ms The number of milliseconds to wait before calling func + * @param {Boolean} runWhenWaiting True if the callback should be run even if Zotero.wait() + * is executing */ - this.setTimeout = function(func, ms) { + this.setTimeout = function(func, ms, runWhenWaiting) { var timer = Components.classes["@mozilla.org/timer;1"]. createInstance(Components.interfaces.nsITimer); var timerCallback = {"notify":function() { - if(_waiting) { + if(_waiting && !runWhenWaiting) { // if our callback gets called during Zotero.wait(), queue it to be set again // when Zotero.wait() completes _waitTimers.push(timer); diff --git a/components/zotero-command-line-handler.js b/components/zotero-command-line-handler.js index 5939210f3b..e78c125905 100644 --- a/components/zotero-command-line-handler.js +++ b/components/zotero-command-line-handler.js @@ -62,9 +62,7 @@ ZoteroCommandLineHandler.prototype = { // Not quite sure why this is necessary to get the appropriate scoping var Zotero = this.Zotero; - var timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer); - timer.initWithCallback({notify:function() { Zotero.Integration.execCommand(agent, command, docId) }}, 0, - Components.interfaces.nsITimer.TYPE_ONE_SHOT); + Zotero.setTimeout(function() { Zotero.Integration.execCommand(agent, command, docId) }, 0); } // handler for Windows IPC commands