commit d252a09cd37c193e6ceb20f01136a43b55c4fd96
parent 72fbee55239fdda78972a211097be3b72f457e35
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 27 Jul 2017 02:29:50 -0400
Update Quick Copy menu options based on current settings and URL
Show "Copy Citation" and "Copy Bibliography" when a bib format is
selected and "Copy as BibTeX", etc., when an export is selected. If a
site-specific setting is in effect from the last active URL, use that
instead.
If no regular items are selected in bib mode, the menu options are
disabled.
This also now filters non-regular items out when in bib mode -- before
if you selected a combination it would include a bunch of 'n.d.' lines.
Closes #1155, Disable Copy Citation menu option when a translator is
selected for Quick Copy
Diffstat:
5 files changed, 102 insertions(+), 28 deletions(-)
diff --git a/chrome/content/zotero/standalone/standalone.js b/chrome/content/zotero/standalone/standalone.js
@@ -52,6 +52,11 @@ const ZoteroStandalone = new function() {
document.getElementById('menu_errorConsole').hidden = false;
}
+ document.getElementById('key_copyCitation')
+ .setAttribute('key', Zotero.Keys.getKeyForCommand('copySelectedItemCitationsToClipboard'));
+ document.getElementById('key_copyBibliography')
+ .setAttribute('key', Zotero.Keys.getKeyForCommand('copySelectedItemsToClipboard'));
+
ZoteroStandalone.DebugOutput.init();
Zotero.hideZoteroPaneOverlays();
@@ -132,6 +137,31 @@ const ZoteroStandalone = new function() {
}
}
+
+ this.updateQuickCopyOptions = function () {
+ var format = Zotero.QuickCopy.getFormatFromURL(Zotero.QuickCopy.lastActiveURL);
+ format = Zotero.QuickCopy.unserializeSetting(format);
+
+ var copyCitation = document.getElementById('menu_copyCitation');
+ var copyBibliography = document.getElementById('menu_copyBibliography');
+ var copyExport = document.getElementById('menu_copyExport');
+
+ copyCitation.hidden = format.mode != 'bibliography';
+ copyBibliography.hidden = format.mode != 'bibliography';
+ copyExport.hidden = format.mode != 'export';
+ if (format.mode == 'export') {
+ try {
+ let obj = Zotero.Translators.get(format.id);
+ copyExport.label = Zotero.getString('quickCopy.copyAs', obj.label);
+ }
+ catch (e) {
+ Zotero.logError(e);
+ copyExport.hidden = true;
+ }
+ }
+ };
+
+
this.updateAddonsPane = function (doc) {
// Hide unsigned add-on verification warnings
//
diff --git a/chrome/content/zotero/standalone/standalone.xul b/chrome/content/zotero/standalone/standalone.xul
@@ -73,6 +73,12 @@
key="&importCmd.key;"
command="cmd_zotero_importFromClipboard"
modifiers="accel shift alt"/>
+ <key id="key_copyCitation"
+ command="cmd_zotero_copyCitation"
+ modifiers="accel shift"/>
+ <key id="key_copyBibliography"
+ command="cmd_zotero_copyBibliography"
+ modifiers="accel shift"/>
</keyset>
<keyset id="editMenuKeys"/>
@@ -136,17 +142,28 @@
</menupopup>
</menu>
- <menu id="menu_edit">
+ <menu id="menu_edit"
+ onpopupshowing="ZoteroStandalone.updateQuickCopyOptions()">
<menupopup id="menu_EditPopup">
<menuitem id="menu_undo"/>
<menuitem id="menu_redo"/>
<menuseparator/>
<menuitem id="menu_cut"/>
<menuitem id="menu_copy"/>
- <menuitem id="menu_copyCitation" label="©CitationCmd.label;"
- command="cmd_zotero_copyCitation"/>
- <menuitem id="menu_copyBibliography" label="©BibliographyCmd.label;"
- command="cmd_zotero_copyBibliography"/>
+ <menuitem id="menu_copyCitation"
+ label="©CitationCmd.label;"
+ command="cmd_zotero_copyCitation"
+ key="key_copyCitation"
+ hidden="true"/>
+ <menuitem id="menu_copyBibliography"
+ label="©BibliographyCmd.label;"
+ command="cmd_zotero_copyBibliography"
+ key="key_copyBibliography"
+ hidden="true"/>
+ <menuitem id="menu_copyExport"
+ key="key_copyBibliography"
+ command="cmd_zotero_copyBibliography"
+ hidden="true"/>
<menuitem id="menu_paste"/>
<menuitem id="menu_delete"/>
<menuseparator/>
diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js
@@ -726,12 +726,6 @@ var ZoteroPane = new function()
case 'toggleTagSelector':
ZoteroPane_Local.toggleTagSelector();
break;
- case 'copySelectedItemCitationsToClipboard':
- ZoteroPane_Local.copySelectedItemsToClipboard(true)
- break;
- case 'copySelectedItemsToClipboard':
- ZoteroPane_Local.copySelectedItemsToClipboard();
- break;
case 'sync':
Zotero.Sync.Runner.sync();
break;
@@ -749,6 +743,14 @@ var ZoteroPane = new function()
this.markFeedRead();
}
break;
+
+ // Handled by <key>s in standalone.js, pointing to <command>s in zoteroPane.xul,
+ // which are enabled or disabled by this.updateQuickCopyCommands(), called by
+ // this.itemSelected()
+ case 'copySelectedItemCitationsToClipboard':
+ case 'copySelectedItemsToClipboard':
+ return;
+
default:
throw ('Command "' + command + '" not found in ZoteroPane_Local.handleKeyDown()');
}
@@ -1396,6 +1398,8 @@ var ZoteroPane = new function()
// selection hasn't changed, because the selected items might have been modified.
this.updateItemPaneButtons(selectedItems);
+ this.updateQuickCopyCommands(selectedItems);
+
// Check if selection has actually changed. The onselect event that calls this
// can be called in various situations where the selection didn't actually change,
// such as whenever selectEventsSuppressed is set to false.
@@ -1695,6 +1699,25 @@ var ZoteroPane = new function()
}
+ /**
+ * Update the <command> elements that control the shortcut keys and the enabled state of the
+ * "Copy Citation"/"Copy Bibliography"/"Copy as" menu options. When disabled, the shortcuts are
+ * still caught in handleKeyPress so that we can show an alert about not having references selected.
+ */
+ this.updateQuickCopyCommands = function (selectedItems) {
+ var format = Zotero.QuickCopy.getFormatFromURL(Zotero.QuickCopy.lastActiveURL);
+ format = Zotero.QuickCopy.unserializeSetting(format);
+ if (format.mode == 'bibliography') {
+ var canCopy = selectedItems.some(item => item.isRegularItem());
+ }
+ else {
+ var canCopy = true;
+ }
+ document.getElementById('cmd_zotero_copyCitation').setAttribute('disabled', !canCopy);
+ document.getElementById('cmd_zotero_copyBibliography').setAttribute('disabled', !canCopy);
+ };
+
+
this.checkPDFConverter = function () {
if (Zotero.Fulltext.pdfConverterIsRegistered()) {
return true;
@@ -2129,32 +2152,30 @@ var ZoteroPane = new function()
return;
}
- // Make sure at least one item is a regular item
- //
+ var format = Zotero.QuickCopy.getFormatFromURL(Zotero.QuickCopy.lastActiveURL);
+ format = Zotero.QuickCopy.unserializeSetting(format);
+
+ // In bibliography mode, remove notes and attachments
+ if (format.mode == 'bibliography') {
+ items = items.filter(item => item.isRegularItem());
+ }
+
// DEBUG: We could copy notes via keyboard shortcut if we altered
// Z_F_I.copyItemsToClipboard() to use Z.QuickCopy.getContentFromItems(),
// but 1) we'd need to override that function's drag limit and 2) when I
// tried it the OS X clipboard seemed to be getting text vs. HTML wrong,
// automatically converting text/html to plaintext rather than using
// text/unicode. (That may be fixable, however.)
- var canCopy = false;
- for (let i = 0; i < items.length; i++) {
- let item = items[i];
- if (item.isRegularItem()) {
- canCopy = true;
- break;
- }
- }
- if (!canCopy) {
- var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+ //
+ // This isn't currently shown, because the commands are disabled when not relevant, so this
+ // function isn't called
+ if (!items.length) {
+ let ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
ps.alert(null, "", Zotero.getString("fileInterface.noReferencesError"));
return;
}
- var format = Zotero.QuickCopy.getFormatFromURL(Zotero.QuickCopy.lastActiveURL);
- format = Zotero.QuickCopy.unserializeSetting(format);
-
// determine locale preference
var locale = format.locale ? format.locale : Zotero.Prefs.get('export.quickCopy.locale');
diff --git a/chrome/content/zotero/zoteroPane.xul b/chrome/content/zotero/zoteroPane.xul
@@ -53,8 +53,12 @@
<command id="cmd_zotero_importFromClipboard" oncommand="Zotero_File_Interface.importFromClipboard();"/>
<command id="cmd_zotero_exportLibrary" oncommand="Zotero_File_Interface.exportFile();"/>
<command id="cmd_zotero_advancedSearch" oncommand="ZoteroPane_Local.openAdvancedSearchWindow();"/>
- <command id="cmd_zotero_copyCitation" oncommand="ZoteroPane_Local.copySelectedItemsToClipboard(true);"/>
- <command id="cmd_zotero_copyBibliography" oncommand="ZoteroPane_Local.copySelectedItemsToClipboard();"/>
+ <command id="cmd_zotero_copyCitation"
+ oncommand="ZoteroPane_Local.copySelectedItemsToClipboard(true);"
+ disabled="true"/>
+ <command id="cmd_zotero_copyBibliography"
+ oncommand="ZoteroPane_Local.copySelectedItemsToClipboard();"
+ disabled="true"/>
<command id="cmd_zotero_createTimeline" oncommand="Zotero_Timeline_Interface.loadTimeline();"/>
<command id="cmd_zotero_rtfScan" oncommand="window.openDialog('chrome://zotero/content/rtfScan.xul', 'rtfScan', 'chrome,centerscreen')"/>
<command id="cmd_zotero_newCollection" oncommand="ZoteroPane_Local.newCollection()"/>
diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties
@@ -701,6 +701,8 @@ fileInterface.exportError = An error occurred while trying to export the selecte
fileInterface.importOPML = Import Feeds from OPML
fileInterface.OPMLFeedFilter = OPML Feed List
+quickCopy.copyAs = Copy as %S
+
quickSearch.mode.titleCreatorYear = Title, Creator, Year
quickSearch.mode.fieldsAndTags = All Fields & Tags
quickSearch.mode.everything = Everything