Restore menus for attachment/note toolbar buttons and update File menu

We previously switched to just Add File and New Note buttons, but people
are going to want to create child attachments/notes via the toolbar.
This adds menus for those two buttons with clearer wording.

Also:

- Update the File menu with options that correspond to each of the four
  items pane toolbar buttons (including a new menu option for Add by
  Identifier)
- Update the order and wording of the Add Attachment submenu in the
  items list context menu
- Remove File menu options from the reader view that were added
  accidentally during the toolbar redesign
This commit is contained in:
Dan Stillman 2024-01-02 08:14:10 -05:00
parent b15313fc3e
commit 0facc521b2
3 changed files with 207 additions and 75 deletions

View file

@ -1668,16 +1668,28 @@ var ZoteroPane = new function()
*/
this._updateEnabledActionsForRow = function (collectionTreeRow) {
const disableIfNoEdit = [
"menu_newItem",
"cmd_zotero_addByIdentifier",
"menu_attachmentAdd",
"menu_noteAdd",
"cmd_zotero_newCollection",
"cmd_zotero_newSavedSearch",
"cmd_zotero_import",
"cmd_zotero_importFromClipboard",
"zotero-tb-add",
"menu_newItem",
"zotero-tb-lookup",
"cmd_zotero_newStandaloneFileAttachment",
"cmd_zotero_newStandaloneLinkedFileAttachment",
"cmd_zotero_newChildFileAttachment",
"cmd_zotero_newChildLinkedFileAttachment",
"cmd_zotero_newChildURLAttachment",
"cmd_zotero_newStandaloneNote",
"cmd_zotero_newChildNote",
"zotero-tb-add",
"zotero-tb-lookup",
"zotero-tb-attachment-add",
"zotero-tb-note-add",
"zotero-tb-attachment-add"
];
for (let i = 0; i < disableIfNoEdit.length; i++) {
let command = disableIfNoEdit[i];
@ -1937,57 +1949,40 @@ var ZoteroPane = new function()
};
/**
* @return {Promise}
*/
this.updateNoteButtonMenu = function () {
var items = ZoteroPane_Local.getSelectedItems();
var cmd = document.getElementById('cmd_zotero_newChildNote');
cmd.setAttribute("disabled", !this.canEdit() ||
!(items.length == 1 && (items[0].isRegularItem() || !items[0].isTopLevelItem())));
}
this.updateAttachmentButtonMenu = function (popup) {
var items = ZoteroPane_Local.getSelectedItems();
var disabled = !this.canEdit() || !(items.length == 1 && items[0].isRegularItem());
if (disabled) {
this.updateAddAttachmentMenu = function (popup) {
if (!this.canEdit()) {
for (let node of popup.childNodes) {
node.disabled = true;
if (node.tagName == 'menuitem') {
node.disabled = true;
}
}
return;
}
var collectionTreeRow = this.getCollectionTreeRow();
var items = ZoteroPane.getSelectedItems();
var oneItemSelected = items.length == 1 && items[0].isRegularItem();
var canEditFiles = this.canEditFiles();
var prefix = "menuitem-iconic zotero-menuitem-attachments-";
for (var i=0; i<popup.childNodes.length; i++) {
var node = popup.childNodes[i];
var className = node.className;
switch (className) {
case prefix + 'link':
node.disabled = collectionTreeRow.isWithinGroup();
break;
case prefix + 'file':
node.disabled = !canEditFiles;
break;
case prefix + 'web-link':
node.disabled = false;
break;
default:
throw new Error(`Invalid class name '${className}'`);
}
var commandsEnabled = [
['cmd_zotero_newStandaloneFileAttachment', canEditFiles],
['cmd_zotero_newStandaloneLinkedFileAttachment', canEditFiles],
['cmd_zotero_newChildFileAttachment', oneItemSelected && canEditFiles],
['cmd_zotero_newChildLinkedFileAttachment', oneItemSelected && canEditFiles],
['cmd_zotero_newChildURLAttachment', oneItemSelected],
];
for (let command of commandsEnabled) {
document.getElementById(command[0]).setAttribute('disabled', !command[1]);
}
}
};
/**
* @return {Promise}
*/
this.updateNewNoteMenu = function () {
var items = ZoteroPane_Local.getSelectedItems();
var cmd = document.getElementById('cmd_zotero_newChildNote');
cmd.setAttribute("disabled", !this.canEdit() ||
!(items.length == 1 && (items[0].isRegularItem() || !items[0].isTopLevelItem())));
};
/**
* Update the <command> elements that control the shortcut keys and the enabled state of the
@ -3810,7 +3805,7 @@ var ZoteroPane = new function()
// Update attachment submenu
var popup = document.getElementById('zotero-add-attachment-popup')
this.updateAttachmentButtonMenu(popup);
this.updateAddAttachmentMenu(popup);
// Block certain actions on files if no access
if (item.isFileAttachment() && !collectionTreeRow.filesEditable) {

View file

@ -202,9 +202,60 @@
<menupopup id="menu_NewItemPopup"
onpopupshowing="ZoteroStandalone.buildNewItemMenu()"/>
</menu>
<menuitem
class="menu-type-library"
data-l10n-id="menu-add-by-identifier"
command="cmd_zotero_addByIdentifier"
/>
<menu
id="menu_attachmentAdd"
class="menu-type-library"
data-l10n-id="menu-add-attachment">
<menupopup onpopupshowing="ZoteroPane.updateAddAttachmentMenu(this)">
<menuitem
data-l10n-id="menu-add-standalone-file-attachment"
command="cmd_zotero_newStandaloneFileAttachment"
/>
<menuitem
data-l10n-id="menu-add-standalone-linked-file-attachment"
command="cmd_zotero_newStandaloneLinkedFileAttachment"
/>
<menuseparator/>
<menuitem
data-l10n-id="menu-add-child-file-attachment"
command="cmd_zotero_newChildFileAttachment"
/>
<menuitem
data-l10n-id="menu-add-child-linked-file-attachment"
command="cmd_zotero_newChildLinkedFileAttachment"
id="zotero-tb-attachment-add-file-link"
/>
<menuitem
data-l10n-id="menu-add-child-linked-url-attachment"
command="cmd_zotero_newChildURLAttachment"
/>
</menupopup>
</menu>
<menu
id="menu_noteAdd"
class="menu-type-library"
data-l10n-id="menu-new-note">
<menupopup onpopupshowing="ZoteroPane_Local.updateNewNoteMenu()">
<menuitem
data-l10n-id="menu-new-standalone-note"
command="cmd_zotero_newStandaloneNote"
/>
<menuitem
data-l10n-id="menu-new-item-note"
command="cmd_zotero_newChildNote"
/>
</menupopup>
</menu>
<menuseparator/>
<menuitem id="menu_newCollection" class="menu-type-library" label="&zotero.toolbar.newCollection.label;"
command="cmd_zotero_newCollection"/>
<menu id="menu_libraryAdd"
class="menu-type-library"
label="&zotero.toolbar.newLibrary.label;">
<menupopup id="menu_libraryAddPopup">
<menuitem id="menu_groupAdd" label="&zotero.toolbar.newGroup;" oncommand="ZoteroPane_Local.newGroup()"/>
@ -218,19 +269,6 @@
</menu>
</menupopup>
</menu>
<menu id="menu_attachmentAdd" label="&zotero.items.menu.attach;">
<menupopup onpopupshowing="ZoteroPane_Local.updateAttachmentButtonMenu(this)">
<menuitem class="menuitem-iconic zotero-menuitem-attachments-web-link" label="&zotero.items.menu.attach.link.uri;" oncommand="var itemID = ZoteroPane_Local.getSelectedItems()[0].id; ZoteroPane_Local.addAttachmentFromURI(true, itemID);"/>
<menuitem class="menuitem-iconic zotero-menuitem-attachments-file" label="&zotero.items.menu.attach.file;" oncommand="var itemID = ZoteroPane_Local.getSelectedItems()[0].id; ZoteroPane_Local.addAttachmentFromDialog(false, itemID);"/>
<menuitem class="menuitem-iconic zotero-menuitem-attachments-link" label="&zotero.items.menu.attach.fileLink;" oncommand="var itemID = ZoteroPane_Local.getSelectedItems()[0].id; ZoteroPane_Local.addAttachmentFromDialog(true, itemID);" id="zotero-tb-attachment-add-file-link"/>
</menupopup>
</menu>
<menu id="menu_noteAdd" label="&zotero.toolbar.newNote;">
<menupopup onpopupshowing="ZoteroPane_Local.updateNoteButtonMenu()">
<menuitem label="&zotero.toolbar.note.standalone;" command="cmd_zotero_newStandaloneNote"/>
<menuitem label="&zotero.toolbar.note.child;" command="cmd_zotero_newChildNote"/>
</menupopup>
</menu>
<menuitem
id="menu_transferFromPDF"
class="menu-type-reader pdf"
@ -825,6 +863,12 @@
<command id="cmd_zotero_newCollection" oncommand="ZoteroPane_Local.newCollection(ZoteroPane_Local.getSelectedCollection()?.key)"/>
<command id="cmd_zotero_newFeed_fromURL" oncommand="ZoteroPane_Local.newFeedFromURL()"/>
<command id="cmd_zotero_newSavedSearch" oncommand="ZoteroPane_Local.newSearch()"/>
<command id="cmd_zotero_addByIdentifier" oncommand="Zotero_Lookup.showPanel()"/>
<command id="cmd_zotero_newStandaloneFileAttachment" oncommand="ZoteroPane.addAttachmentFromDialog()"/>
<command id="cmd_zotero_newStandaloneLinkedFileAttachment" oncommand="ZoteroPane.addAttachmentFromDialog(true)"/>
<command id="cmd_zotero_newChildFileAttachment" oncommand="ZoteroPane.addAttachmentFromDialog(false, ZoteroPane.getSelectedItems()[0].id)"/>
<command id="cmd_zotero_newChildLinkedFileAttachment" oncommand="ZoteroPane.addAttachmentFromDialog(true, ZoteroPane.getSelectedItems()[0].id)"/>
<command id="cmd_zotero_newChildURLAttachment" oncommand="ZoteroPane.addAttachmentFromURI(true, ZoteroPane.getSelectedItems()[0].id)"/>
<command id="cmd_zotero_newStandaloneNote" oncommand="ZoteroPane_Local.newNote(event.shiftKey);"/>
<command id="cmd_zotero_newChildNote" oncommand="ZoteroPane_Local.newChildNote(event.shiftKey);"/>
</commandset>
@ -913,9 +957,21 @@
<menu class="menu-iconic zotero-menuitem-attach" label="&zotero.items.menu.attach;">
<menupopup id="zotero-add-attachment-popup">
<menuitem class="menuitem-iconic zotero-menuitem-attachments-web-link" label="&zotero.items.menu.attach.link.uri;" oncommand="var itemID = parseInt(this.parentNode.parentNode.parentNode.getAttribute('itemID')); ZoteroPane_Local.addAttachmentFromURI(true, itemID);"/>
<menuitem class="menuitem-iconic zotero-menuitem-attachments-file" label="&zotero.items.menu.attach.file;" oncommand="var itemID = parseInt(this.parentNode.parentNode.parentNode.getAttribute('itemID')); ZoteroPane_Local.addAttachmentFromDialog(false, itemID);"/>
<menuitem class="menuitem-iconic zotero-menuitem-attachments-link" label="&zotero.items.menu.attach.fileLink;" oncommand="var itemID = parseInt(this.parentNode.parentNode.parentNode.getAttribute('itemID')); ZoteroPane_Local.addAttachmentFromDialog(true, itemID);"/>
<menuitem
class="menuitem-iconic zotero-menuitem-attachments-file"
data-l10n-id="item-menu-add-file"
command="cmd_zotero_newChildFileAttachment"
/>
<menuitem
class="menuitem-iconic zotero-menuitem-attachments-link"
data-l10n-id="item-menu-add-linked-file"
command="cmd_zotero_newChildLinkedFileAttachment"
/>
<menuitem
class="menuitem-iconic zotero-menuitem-attachments-web-link"
data-l10n-id="item-menu-add-url"
command="cmd_zotero_newChildURLAttachment"
/>
</menupopup>
</menu>
<menuseparator/>
@ -1017,8 +1073,14 @@
<menupopup onpopupshowing="ZoteroPane_Local.updateNewItemTypes()"></menupopup>
</toolbarbutton>
<toolbarbutton id="zotero-tb-lookup" tabindex="-1" class="zotero-tb-button" tooltiptext="&zotero.toolbar.lookup.label;" type="panel"
onmousedown="if (this.disabled) { event.preventDefault(); return; } Zotero_Lookup.showPanel(this)"/>
<toolbarbutton
id="zotero-tb-lookup"
tabindex="-1"
class="zotero-tb-button"
tooltiptext="&zotero.toolbar.lookup.label;"
type="panel"
onmousedown="if (this.disabled) { event.preventDefault(); return; } Zotero_Lookup.showPanel(this)"
/>
<panel id="zotero-lookup-panel" type="arrow"
onpopupshowing="Zotero_Lookup.onShowing(event)"
@ -1047,14 +1109,54 @@
</panel>
<toolbarbutton
id="zotero-tb-attachment-add"
class="zotero-tb-button"
tabindex="-1"
data-l10n-id="zotero-toolbar-new-attachment"
oncommand="var selected = ZoteroPane.getSelectedItems();if (this.disabled || !selected.length) { event.preventDefault(); return; }; ZoteroPane_Local.addAttachmentFromDialog(false, selected[0].id);">
id="zotero-tb-attachment-add"
class="zotero-tb-button"
tabindex="-1"
data-l10n-id="toolbar-add-attachment"
type="menu"
wantdropmarker="true">
<menupopup onpopupshowing="ZoteroPane.updateAddAttachmentMenu(this)">
<menuitem
data-l10n-id="menu-add-standalone-file-attachment"
command="cmd_zotero_newStandaloneFileAttachment"
/>
<menuitem
data-l10n-id="menu-add-standalone-linked-file-attachment"
command="cmd_zotero_newStandaloneLinkedFileAttachment"
/>
<menuseparator/>
<menuitem
data-l10n-id="menu-add-child-file-attachment"
command="cmd_zotero_newChildFileAttachment"
/>
<menuitem
data-l10n-id="menu-add-child-linked-file-attachment"
command="cmd_zotero_newChildLinkedFileAttachment"
id="zotero-tb-attachment-add-file-link"
/>
<menuitem
data-l10n-id="menu-add-child-linked-url-attachment"
command="cmd_zotero_newChildURLAttachment"
/>
</menupopup>
</toolbarbutton>
<toolbarbutton id="zotero-tb-note-add" class="zotero-tb-button" tooltiptext="&zotero.toolbar.newNote;" oncommand="ZoteroPane_Local.newNote(event.shiftKey);"/>
<toolbarbutton
id="zotero-tb-note-add" class="zotero-tb-button" tooltiptext="&zotero.toolbar.newNote;"
type="menu"
tabindex="-1"
wantdropmarker="true">
<menupopup onpopupshowing="ZoteroPane.updateNewNoteMenu()">
<menuitem
data-l10n-id="menu-new-standalone-note"
command="cmd_zotero_newStandaloneNote"
/>
<menuitem
data-l10n-id="menu-new-item-note"
command="cmd_zotero_newChildNote"
/>
</menupopup>
</toolbarbutton>
<spacer flex="1"/>
<image id="zotero-tb-search-spinner" class="zotero-spinner-16"/>
<quick-search-textbox id="zotero-tb-search" timeout="250"

View file

@ -1,5 +1,29 @@
zotero-toolbar-new-attachment =
.tooltiptext = Add File
add-attachment = Add Attachment
new-note = New Note
menu-add-by-identifier =
.label = Add by Identifier…
menu-add-attachment =
.label = { add-attachment }
menu-add-standalone-file-attachment =
.label = Add File…
menu-add-standalone-linked-file-attachment =
.label = Add Link to File…
menu-add-child-file-attachment =
.label = Attach File…
menu-add-child-linked-file-attachment =
.label = Attach Link to File…
menu-add-child-linked-url-attachment =
.label = Attach Web Link…
menu-new-note =
.label = { new-note }
menu-new-standalone-note =
.label = New Standalone Note
menu-new-item-note =
.label = New Item Note
zotero-toolbar-tabs-menu =
.tooltiptext = List all tabs
zotero-collections-search =
@ -9,6 +33,9 @@ zotero-tabs-menu-filter =
zotero-tabs-menu-close-button =
.tooltiptext = Close Tab
toolbar-add-attachment =
.tooltiptext = { add-attachment }
item-creator-moveDown =
.label = Move Down
item-creator-moveToTop =
@ -29,6 +56,14 @@ item-menu-viewAttachment =
[window] New Window
*[other] Reader
}
item-menu-add-file =
.label = File
item-menu-add-linked-file =
.label = Linked File
item-menu-add-url =
.label = Web Link
itembox-button-openLink =
.title = Open Link
.aria-label = Open Link