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)
This commit is contained in:
parent
18101f12ae
commit
1532a1dd14
7 changed files with 57 additions and 1 deletions
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()');
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -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">
|
||||
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue