diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js index d6afd2a4a0..7dd4591c43 100644 --- a/chrome/content/zotero/fileInterface.js +++ b/chrome/content/zotero/fileInterface.js @@ -214,6 +214,47 @@ var Zotero_File_Interface = new function() { } } + + /** + * Imports from clipboard + */ + this.importFromClipboard = function () { + var clip = Components.classes["@mozilla.org/widget/clipboard;1"] + .getService(Components.interfaces.nsIClipboard); + if (!clip.hasDataMatchingFlavors(["text/unicode"], 1, clip.kGlobalClipboard)) { + // TODO: localize + var prompt = Components.classes["@mozilla.org/network/default-prompt;1"] + .getService(Components.interfaces.nsIPrompt); + prompt.alert("", "No importable data could be read from the clipboard."); + return; + } + var trans = Components.classes["@mozilla.org/widget/transferable;1"] + .createInstance(Components.interfaces.nsITransferable); + trans.addDataFlavor("text/unicode"); + clip.getData(trans, clip.kGlobalClipboard); + var str = {}; + try { + trans.getTransferData("text/unicode", str, {}); + str = str.value.QueryInterface(Components.interfaces.nsISupportsString).data; + } + catch (e) { + Zotero.debug(e); + return; + } + if (!str) { + Zotero.debug("No clipboard text to import"); + return; + } + + var translate = new Zotero.Translate("import"); + translate.setString(str); + translate.setHandler("translators", function(obj, item) { + _importTranslatorsAvailable(obj, item) + }); + translators = translate.getTranslators(); + } + + function _importTranslatorsAvailable(translation, translators) { if(translators.length) { // create a new collection to take in imported items @@ -236,7 +277,9 @@ var Zotero_File_Interface = new function() { translation.translate(); }); } else { - window.alert(Zotero.getString("fileInterface.fileFormatUnsupported")); + var prompt = Components.classes["@mozilla.org/network/default-prompt;1"] + .getService(Components.interfaces.nsIPrompt); + prompt.alert("", Zotero.getString("fileInterface.fileFormatUnsupported")); } } diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 546f112638..ae4a0ff239 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -555,6 +555,9 @@ var ZoteroPane = new function() case 'copySelectedItemsToClipboard': ZoteroPane.copySelectedItemsToClipboard(); break; + case 'importFromClipboard': + Zotero_File_Interface.importFromClipboard(); + break; default: throw ('Command "' + command + '" not found in ZoteroPane.handleKeyDown()'); } diff --git a/chrome/content/zotero/overlay.xul b/chrome/content/zotero/overlay.xul index b1e015a435..a478712bc3 100644 --- a/chrome/content/zotero/overlay.xul +++ b/chrome/content/zotero/overlay.xul @@ -123,6 +123,7 @@ +