Skip to content

Commit

Permalink
Update Quick Copy menu options based on current settings and URL
Browse files Browse the repository at this point in the history
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 zotero#1155, Disable Copy Citation menu option when a translator is
selected for Quick Copy
  • Loading branch information
dstillman committed Jul 28, 2017
1 parent 72fbee5 commit d252a09
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 28 deletions.
30 changes: 30 additions & 0 deletions chrome/content/zotero/standalone/standalone.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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
//
Expand Down
27 changes: 22 additions & 5 deletions chrome/content/zotero/standalone/standalone.xul
Expand Up @@ -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"/>

Expand Down Expand Up @@ -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="&copyCitationCmd.label;"
command="cmd_zotero_copyCitation"/>
<menuitem id="menu_copyBibliography" label="&copyBibliographyCmd.label;"
command="cmd_zotero_copyBibliography"/>
<menuitem id="menu_copyCitation"
label="&copyCitationCmd.label;"
command="cmd_zotero_copyCitation"
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_delete"/>
<menuseparator/>
Expand Down
63 changes: 42 additions & 21 deletions chrome/content/zotero/zoteroPane.js
Expand Up @@ -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;
Expand All @@ -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()');
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');

Expand Down
8 changes: 6 additions & 2 deletions chrome/content/zotero/zoteroPane.xul
Expand Up @@ -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()"/>
Expand Down
2 changes: 2 additions & 0 deletions chrome/locale/en-US/zotero/zotero.properties
Expand Up @@ -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
Expand Down

0 comments on commit d252a09

Please sign in to comment.