www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 1532a1dd14920296583dab259baf26793d670f0a
parent 18101f12ae3602342ec538017a234f91ec687596
Author: Dan Stillman <dstillman@zotero.org>
Date:   Wed,  6 May 2009 01:45:57 +0000

Addresses #635, In-content translator

Adds "Import from Clipboard" Actions menu option, based on original patch from en205

Also available via keyboard shortcut (Cmd-Shift-V/Ctrl-Alt-V)


Diffstat:
Mchrome/content/zotero/fileInterface.js | 45++++++++++++++++++++++++++++++++++++++++++++-
Mchrome/content/zotero/overlay.js | 3+++
Mchrome/content/zotero/overlay.xul | 1+
Mchrome/content/zotero/preferences/preferences.xul | 6++++++
Mchrome/locale/en-US/zotero/preferences.dtd | 1+
Mchrome/locale/en-US/zotero/zotero.dtd | 1+
Mdefaults/preferences/zotero.js | 1+
7 files changed, 57 insertions(+), 1 deletion(-)

diff --git 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 @@ -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 @@ -123,6 +123,7 @@ <toolbarbutton id="zotero-tb-actions-menu" tooltiptext="&zotero.toolbar.actions.label;" type="menu"> <menupopup id="zotero-tb-actions-popup" onpopupshowing="document.getElementById('cmd_zotero_reportErrors').setAttribute('disabled', Zotero.getErrors().length == 0)"> <menuitem id="zotero-tb-actions-import" label="&zotero.toolbar.import.label;" oncommand="Zotero_File_Interface.importFile();"/> + <menuitem id="zotero-tb-actions-import-clipboard" label="&zotero.toolbar.importFromClipboard;" oncommand="Zotero_File_Interface.importFromClipboard();" /> <menuitem id="zotero-tb-actions-export" label="&zotero.toolbar.export.label;" oncommand="Zotero_File_Interface.exportFile();"/> <menuitem id="zotero-tb-actions-rtfScan" label="&zotero.toolbar.rtfScan.label;" oncommand="window.openDialog('chrome://zotero/content/rtfScan.xul', 'rtfScan', 'chrome,centerscreen')"/> <menuitem hidden="true" id="zotero-tb-actions-zeroconf-update" diff --git a/chrome/content/zotero/preferences/preferences.xul b/chrome/content/zotero/preferences/preferences.xul @@ -580,6 +580,7 @@ To add a new preference: <preference id="pref-keys-toggleTagSelector" name="extensions.zotero.keys.toggleTagSelector" type="string"/> <preference id="pref-keys-copySelectedItemCitationsToClipboard" name="extensions.zotero.keys.copySelectedItemCitationsToClipboard" type="string"/> <preference id="pref-keys-copySelectedItemsToClipboard" name="extensions.zotero.keys.copySelectedItemsToClipboard" type="string"/> + <preference id="pref-keys-importFromClipboard" name="extensions.zotero.keys.importFromClipboard" type="string"/> <preference id="pref-keys-overrideGlobal" name="extensions.zotero.keys.overrideGlobal" type="bool"/> </preferences> @@ -645,6 +646,11 @@ To add a new preference: <textbox id="textbox-copySelectedItemsToClipboard" maxlength="1" size="1" preference="pref-keys-copySelectedItemsToClipboard" onchange="updateQuickCopyInstructions()"/> </row> + <row> + <label value="&zotero.preferences.keys.importFromClipboard;" control="textbox-importFromClipboard"/> + <label/> + <textbox id="textbox-importFromClipboard" maxlength="1" size="1" preference="pref-keys-importFromClipboard"/> + </row> </rows> </grid> diff --git a/chrome/locale/en-US/zotero/preferences.dtd b/chrome/locale/en-US/zotero/preferences.dtd @@ -81,6 +81,7 @@ <!ENTITY zotero.preferences.keys.toggleTagSelector "Toggle Tag Selector"> <!ENTITY zotero.preferences.keys.copySelectedItemCitationsToClipboard "Copy Selected Item Citations to Clipboard"> <!ENTITY zotero.preferences.keys.copySelectedItemsToClipboard "Copy Selected Items to Clipboard"> +<!ENTITY zotero.preferences.keys.importFromClipboard "Import from Clipboard"> <!ENTITY zotero.preferences.keys.overrideGlobal "Try to override conflicting shortcuts"> <!ENTITY zotero.preferences.keys.changesTakeEffect "Changes take effect in new windows only"> diff --git a/chrome/locale/en-US/zotero/zotero.dtd b/chrome/locale/en-US/zotero/zotero.dtd @@ -66,6 +66,7 @@ <!ENTITY zotero.toolbar.tagSelector.label "Show/Hide Tag Selector"> <!ENTITY zotero.toolbar.actions.label "Actions"> <!ENTITY zotero.toolbar.import.label "Import..."> +<!ENTITY zotero.toolbar.importFromClipboard "Import from Clipboard"> <!ENTITY zotero.toolbar.export.label "Export Library..."> <!ENTITY zotero.toolbar.rtfScan.label "RTF Scan..."> <!ENTITY zotero.toolbar.timeline.label "Create Timeline"> diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js @@ -57,6 +57,7 @@ pref("extensions.zotero.keys.newNote", 'O'); pref("extensions.zotero.keys.toggleTagSelector", 'T'); pref("extensions.zotero.keys.copySelectedItemCitationsToClipboard", 'A'); pref("extensions.zotero.keys.copySelectedItemsToClipboard", 'C'); +pref("extensions.zotero.keys.importFromClipboard", 'V'); // Fulltext indexing pref("extensions.zotero.fulltext.textMaxLength", 500000);