diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js index 225f52fc6..31c9c0282 100644 --- a/chrome/content/zotero/fileInterface.js +++ b/chrome/content/zotero/fileInterface.js @@ -41,55 +41,56 @@ var Zotero_File_Exporter = function() { * Performs the actual export operation **/ Zotero_File_Exporter.prototype.save = function() { - var translation = new Zotero.Translate.Export(); - var translators = translation.getTranslators(); - - // present options dialog - var io = {translators:translators} - window.openDialog("chrome://zotero/content/exportOptions.xul", - "_blank", "chrome,modal,centerscreen,resizable=no", io); - if(!io.selectedTranslator) { - return false; - } - - const nsIFilePicker = Components.interfaces.nsIFilePicker; - var fp = Components.classes["@mozilla.org/filepicker;1"] - .createInstance(nsIFilePicker); - fp.init(window, Zotero.getString("fileInterface.export"), nsIFilePicker.modeSave); - - // set file name and extension - if(io.displayOptions.exportFileData) { - // if the result will be a folder, don't append any extension or use - // filters - fp.defaultString = this.name; - fp.appendFilters(Components.interfaces.nsIFilePicker.filterAll); - } else { - // if the result will be a file, append an extension and use filters - fp.defaultString = this.name+(io.selectedTranslator.target ? "."+io.selectedTranslator.target : ""); - fp.defaultExtension = io.selectedTranslator.target; - fp.appendFilter(io.selectedTranslator.label, "*."+(io.selectedTranslator.target ? io.selectedTranslator.target : "*")); - } - - var rv = fp.show(); - if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { - if(this.collection) { - translation.setCollection(this.collection); - } else if(this.items) { - translation.setItems(this.items); + var translation = new Zotero.Translate.Export(), + me = this; + translation.getTranslators().then(function(translators) { + // present options dialog + var io = {translators:translators} + window.openDialog("chrome://zotero/content/exportOptions.xul", + "_blank", "chrome,modal,centerscreen,resizable=no", io); + if(!io.selectedTranslator) { + return false; } - translation.setLocation(fp.file); - translation.setTranslator(io.selectedTranslator); - translation.setDisplayOptions(io.displayOptions); - translation.setHandler("itemDone", Zotero_File_Interface.updateProgress); - translation.setHandler("done", this._exportDone); - Zotero.UnresponsiveScriptIndicator.disable(); - Zotero_File_Interface.Progress.show( - Zotero.getString("fileInterface.itemsExported") - ); - translation.translate() - } - return false; + const nsIFilePicker = Components.interfaces.nsIFilePicker; + var fp = Components.classes["@mozilla.org/filepicker;1"] + .createInstance(nsIFilePicker); + fp.init(window, Zotero.getString("fileInterface.export"), nsIFilePicker.modeSave); + + // set file name and extension + if(io.displayOptions.exportFileData) { + // if the result will be a folder, don't append any extension or use + // filters + fp.defaultString = me.name; + fp.appendFilters(Components.interfaces.nsIFilePicker.filterAll); + } else { + // if the result will be a file, append an extension and use filters + fp.defaultString = me.name+(io.selectedTranslator.target ? "."+io.selectedTranslator.target : ""); + fp.defaultExtension = io.selectedTranslator.target; + fp.appendFilter(io.selectedTranslator.label, "*."+(io.selectedTranslator.target ? io.selectedTranslator.target : "*")); + } + + var rv = fp.show(); + if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { + if(me.collection) { + translation.setCollection(me.collection); + } else if(me.items) { + translation.setItems(me.items); + } + + translation.setLocation(fp.file); + translation.setTranslator(io.selectedTranslator); + translation.setDisplayOptions(io.displayOptions); + translation.setHandler("itemDone", Zotero_File_Interface.updateProgress); + translation.setHandler("done", me._exportDone); + Zotero.UnresponsiveScriptIndicator.disable(); + Zotero_File_Interface.Progress.show( + Zotero.getString("fileInterface.itemsExported") + ); + translation.translate() + } + return false; + }).done(); } /* @@ -207,9 +208,7 @@ var Zotero_File_Interface = new function() { } var translation = new Zotero.Translate.Import(); - if(!file) { - var translators = translation.getTranslators(); - + (file ? Q(file) : translation.getTranslators().then(function(translators) { const nsIFilePicker = Components.interfaces.nsIFilePicker; var fp = Components.classes["@mozilla.org/filepicker;1"] .createInstance(nsIFilePicker); @@ -225,15 +224,17 @@ var Zotero_File_Interface = new function() { return false; } - file = fp.file; - } - - translation.setLocation(file); - // get translators again, bc now we can check against the file - translation.setHandler("translators", function(obj, item) { - _importTranslatorsAvailable(obj, item, createNewCollection); - }); - translators = translation.getTranslators(); + return fp.file; + })).then(function(file) { + if(!file) return; // no file if user cancelled + + translation.setLocation(file); + // get translators again, bc now we can check against the file + translation.setHandler("translators", function(obj, item) { + _importTranslatorsAvailable(obj, item, createNewCollection); + }); + translators = translation.getTranslators(); + }).done(); } diff --git a/chrome/content/zotero/lookup.js b/chrome/content/zotero/lookup.js index 6fc52b44d..21cf2c96f 100644 --- a/chrome/content/zotero/lookup.js +++ b/chrome/content/zotero/lookup.js @@ -115,31 +115,32 @@ const Zotero_Lookup = new function () { translate.setSearch(item); // be lenient about translators - var translators = translate.getTranslators(); - translate.setTranslator(translators); + translate.getTranslators().then(function(translators) { + translate.setTranslator(translators); - translate.setHandler("done", function(translate, success) { - notDone--; - successful += success; + translate.setHandler("done", function(translate, success) { + notDone--; + successful += success; - if(!notDone) { //i.e. done - Zotero_Lookup.toggleProgress(false); - if(successful) { - document.getElementById("zotero-lookup-panel").hidePopup(); - } else { - var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Components.interfaces.nsIPromptService); - prompts.alert(window, Zotero.getString("lookup.failure.title"), - Zotero.getString("lookup.failure.description")); + if(!notDone) { //i.e. done + Zotero_Lookup.toggleProgress(false); + if(successful) { + document.getElementById("zotero-lookup-panel").hidePopup(); + } else { + var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] + .getService(Components.interfaces.nsIPromptService); + prompts.alert(window, Zotero.getString("lookup.failure.title"), + Zotero.getString("lookup.failure.description")); + } } - } - }); + }); - translate.setHandler("itemDone", function(obj, item) { - if(collection) collection.addItem(item.id); + translate.setHandler("itemDone", function(obj, item) { + if(collection) collection.addItem(item.id); + }); + + translate.translate(libraryID); }); - - translate.translate(libraryID); })(item); } diff --git a/chrome/content/zotero/tools/testTranslators/testTranslators.js b/chrome/content/zotero/tools/testTranslators/testTranslators.js index fedc1ef26..bd170febe 100644 --- a/chrome/content/zotero/tools/testTranslators/testTranslators.js +++ b/chrome/content/zotero/tools/testTranslators/testTranslators.js @@ -466,12 +466,13 @@ function init() { // get translators, with code for unsupported translators if(!viewerMode) { - Zotero.Translators.getAllForType(translatorType, new function() { + Zotero.Translators.getAllForType(translatorType, true). + then(new function() { var type = translatorType; return function(translators) { haveTranslators(translators, type); } - }, true); + }); } } diff --git a/chrome/content/zotero/tools/testTranslators/translatorTester.js b/chrome/content/zotero/tools/testTranslators/translatorTester.js index ac4c6c499..001aa67f1 100644 --- a/chrome/content/zotero/tools/testTranslators/translatorTester.js +++ b/chrome/content/zotero/tools/testTranslators/translatorTester.js @@ -48,7 +48,8 @@ Zotero_TranslatorTesters = new function() { var testers = []; var waitingForTranslators = TEST_TYPES.length; for(var i=0; i www.nature.com) - var m = /^(https?:\/\/)([^\/]+)/i.exec(uri); - if(m) { - // First, drop the 0- if it exists (this is an III invention) - var host = m[2]; - if(host.substr(0, 2) === "0-") host = host.substr(2); - var hostnames = host.split("."); - for(var i=1; i www.nature.com) + var m = /^(https?:\/\/)([^\/]+)/i.exec(uri); + if(m) { + // First, drop the 0- if it exists (this is an III invention) + var host = m[2]; + if(host.substr(0, 2) === "0-") host = host.substr(2); + var hostnames = host.split("."); + for(var i=1; i