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
This commit is contained in:
Dan Stillman 2017-07-27 02:29:50 -04:00
parent 72fbee5523
commit d252a09cd3
5 changed files with 102 additions and 28 deletions

View file

@ -52,6 +52,11 @@ const ZoteroStandalone = new function() {
document.getElementById('menu_errorConsole').hidden = false; 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(); ZoteroStandalone.DebugOutput.init();
Zotero.hideZoteroPaneOverlays(); 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) { this.updateAddonsPane = function (doc) {
// Hide unsigned add-on verification warnings // Hide unsigned add-on verification warnings
// //

View file

@ -73,6 +73,12 @@
key="&importCmd.key;" key="&importCmd.key;"
command="cmd_zotero_importFromClipboard" command="cmd_zotero_importFromClipboard"
modifiers="accel shift alt"/> 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>
<keyset id="editMenuKeys"/> <keyset id="editMenuKeys"/>
@ -136,17 +142,28 @@
</menupopup> </menupopup>
</menu> </menu>
<menu id="menu_edit"> <menu id="menu_edit"
onpopupshowing="ZoteroStandalone.updateQuickCopyOptions()">
<menupopup id="menu_EditPopup"> <menupopup id="menu_EditPopup">
<menuitem id="menu_undo"/> <menuitem id="menu_undo"/>
<menuitem id="menu_redo"/> <menuitem id="menu_redo"/>
<menuseparator/> <menuseparator/>
<menuitem id="menu_cut"/> <menuitem id="menu_cut"/>
<menuitem id="menu_copy"/> <menuitem id="menu_copy"/>
<menuitem id="menu_copyCitation" label="&copyCitationCmd.label;" <menuitem id="menu_copyCitation"
command="cmd_zotero_copyCitation"/> label="&copyCitationCmd.label;"
<menuitem id="menu_copyBibliography" label="&copyBibliographyCmd.label;" command="cmd_zotero_copyCitation"
command="cmd_zotero_copyBibliography"/> key="key_copyCitation"
hidden="true"/>
<menuitem id="menu_copyBibliography"
label="&copyBibliographyCmd.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_paste"/>
<menuitem id="menu_delete"/> <menuitem id="menu_delete"/>
<menuseparator/> <menuseparator/>

View file

@ -726,12 +726,6 @@ var ZoteroPane = new function()
case 'toggleTagSelector': case 'toggleTagSelector':
ZoteroPane_Local.toggleTagSelector(); ZoteroPane_Local.toggleTagSelector();
break; break;
case 'copySelectedItemCitationsToClipboard':
ZoteroPane_Local.copySelectedItemsToClipboard(true)
break;
case 'copySelectedItemsToClipboard':
ZoteroPane_Local.copySelectedItemsToClipboard();
break;
case 'sync': case 'sync':
Zotero.Sync.Runner.sync(); Zotero.Sync.Runner.sync();
break; break;
@ -749,6 +743,14 @@ var ZoteroPane = new function()
this.markFeedRead(); this.markFeedRead();
} }
break; 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: default:
throw ('Command "' + command + '" not found in ZoteroPane_Local.handleKeyDown()'); 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. // selection hasn't changed, because the selected items might have been modified.
this.updateItemPaneButtons(selectedItems); this.updateItemPaneButtons(selectedItems);
this.updateQuickCopyCommands(selectedItems);
// Check if selection has actually changed. The onselect event that calls this // 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, // can be called in various situations where the selection didn't actually change,
// such as whenever selectEventsSuppressed is set to false. // 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 () { this.checkPDFConverter = function () {
if (Zotero.Fulltext.pdfConverterIsRegistered()) { if (Zotero.Fulltext.pdfConverterIsRegistered()) {
return true; return true;
@ -2129,32 +2152,30 @@ var ZoteroPane = new function()
return; 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 // DEBUG: We could copy notes via keyboard shortcut if we altered
// Z_F_I.copyItemsToClipboard() to use Z.QuickCopy.getContentFromItems(), // 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 // 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, // tried it the OS X clipboard seemed to be getting text vs. HTML wrong,
// automatically converting text/html to plaintext rather than using // automatically converting text/html to plaintext rather than using
// text/unicode. (That may be fixable, however.) // text/unicode. (That may be fixable, however.)
var canCopy = false; //
for (let i = 0; i < items.length; i++) { // This isn't currently shown, because the commands are disabled when not relevant, so this
let item = items[i]; // function isn't called
if (item.isRegularItem()) { if (!items.length) {
canCopy = true; let ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
break;
}
}
if (!canCopy) {
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService); .getService(Components.interfaces.nsIPromptService);
ps.alert(null, "", Zotero.getString("fileInterface.noReferencesError")); ps.alert(null, "", Zotero.getString("fileInterface.noReferencesError"));
return; return;
} }
var format = Zotero.QuickCopy.getFormatFromURL(Zotero.QuickCopy.lastActiveURL);
format = Zotero.QuickCopy.unserializeSetting(format);
// determine locale preference // determine locale preference
var locale = format.locale ? format.locale : Zotero.Prefs.get('export.quickCopy.locale'); var locale = format.locale ? format.locale : Zotero.Prefs.get('export.quickCopy.locale');

View file

@ -53,8 +53,12 @@
<command id="cmd_zotero_importFromClipboard" oncommand="Zotero_File_Interface.importFromClipboard();"/> <command id="cmd_zotero_importFromClipboard" oncommand="Zotero_File_Interface.importFromClipboard();"/>
<command id="cmd_zotero_exportLibrary" oncommand="Zotero_File_Interface.exportFile();"/> <command id="cmd_zotero_exportLibrary" oncommand="Zotero_File_Interface.exportFile();"/>
<command id="cmd_zotero_advancedSearch" oncommand="ZoteroPane_Local.openAdvancedSearchWindow();"/> <command id="cmd_zotero_advancedSearch" oncommand="ZoteroPane_Local.openAdvancedSearchWindow();"/>
<command id="cmd_zotero_copyCitation" oncommand="ZoteroPane_Local.copySelectedItemsToClipboard(true);"/> <command id="cmd_zotero_copyCitation"
<command id="cmd_zotero_copyBibliography" oncommand="ZoteroPane_Local.copySelectedItemsToClipboard();"/> 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_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_rtfScan" oncommand="window.openDialog('chrome://zotero/content/rtfScan.xul', 'rtfScan', 'chrome,centerscreen')"/>
<command id="cmd_zotero_newCollection" oncommand="ZoteroPane_Local.newCollection()"/> <command id="cmd_zotero_newCollection" oncommand="ZoteroPane_Local.newCollection()"/>

View file

@ -701,6 +701,8 @@ fileInterface.exportError = An error occurred while trying to export the selecte
fileInterface.importOPML = Import Feeds from OPML fileInterface.importOPML = Import Feeds from OPML
fileInterface.OPMLFeedFilter = OPML Feed List fileInterface.OPMLFeedFilter = OPML Feed List
quickCopy.copyAs = Copy as %S
quickSearch.mode.titleCreatorYear = Title, Creator, Year quickSearch.mode.titleCreatorYear = Title, Creator, Year
quickSearch.mode.fieldsAndTags = All Fields & Tags quickSearch.mode.fieldsAndTags = All Fields & Tags
quickSearch.mode.everything = Everything quickSearch.mode.everything = Everything