Better handling of export option for notes in items list context menu

- Show "Export Note…"/"Export Notes…" if only notes or attachments
  selected
- Don't show export option if only attachments and no embedded notes
  (was previously disabled, and still is if all notes or a mixture of
  empty notes and attachments)
This commit is contained in:
Dan Stillman 2021-12-26 23:50:15 -05:00
parent 5c024e2859
commit 71248b591d
3 changed files with 45 additions and 7 deletions

View file

@ -2997,11 +2997,25 @@ var ZoteroPane = new function()
].forEach(x => disable.add(x));
}
if (!disable.has(m.exportItems)
&& items.every(item => item.isNote() || item.isAttachment())
&& !items.some(item => item.note)) {
disable.add(m.exportItems);
// Show "Export Note…" if all notes or attachments
var noteExport = items.every(item => item.isNote() || item.isAttachment());
// Disable export if all notes are empty
if (noteExport) {
// If no non-empty notes, hide if all attachments and disable if all notes or a mixture
// of notes and attachments
if (!items.some(item => item.note)) {
if (items.every(item => item.isAttachment())) {
show.delete(m.exportItems);
}
else {
disable.add(m.exportItems);
}
}
}
// Disable Create Bibliography if no regular items
if (show.has(m.createBib) && !items.some(item => item.isRegularItem())) {
show.delete(m.createBib);
}
if ((!collectionTreeRow.editable || collectionTreeRow.isPublications()) && !collectionTreeRow.isFeed()) {
@ -3050,7 +3064,7 @@ var ZoteroPane = new function()
menu.childNodes[m.findPDF].setAttribute('label', Zotero.getString('pane.items.menu.findAvailablePDF' + multiple));
menu.childNodes[m.moveToTrash].setAttribute('label', Zotero.getString('pane.items.menu.moveToTrash' + multiple));
menu.childNodes[m.deleteFromLibrary].setAttribute('label', Zotero.getString('pane.items.menu.delete' + multiple));
menu.childNodes[m.exportItems].setAttribute('label', Zotero.getString('pane.items.menu.export' + multiple));
menu.childNodes[m.exportItems].setAttribute('label', Zotero.getString(`pane.items.menu.export${noteExport ? 'Note' : ''}` + multiple));
menu.childNodes[m.createBib].setAttribute('label', Zotero.getString('pane.items.menu.createBib' + multiple));
menu.childNodes[m.loadReport].setAttribute('label', Zotero.getString('pane.items.menu.generateReport' + multiple));
menu.childNodes[m.createParent].setAttribute('label', Zotero.getString('pane.items.menu.createParent' + multiple));

View file

@ -336,6 +336,8 @@ pane.items.menu.delete = Delete Item…
pane.items.menu.delete.multiple = Delete Items…
pane.items.menu.export = Export Item…
pane.items.menu.export.multiple = Export Items…
pane.items.menu.exportNote = Export Note…
pane.items.menu.exportNote.multiple = Export Notes…
pane.items.menu.createBib = Create Bibliography from Item…
pane.items.menu.createBib.multiple = Create Bibliography from Items…
pane.items.menu.generateReport = Generate Report from Item…

View file

@ -803,12 +803,34 @@ describe("ZoteroPane", function() {
});
describe("#buildItemContextMenu()", function () {
it("should build menu for multiple standalone file attachments", async function () {
it("shouldn't show export or bib options for multiple standalone file attachments without notes", async function () {
var item1 = await importFileAttachment('test.png');
var item2 = await importFileAttachment('test.png');
await zp.selectItems([item1.id, item2.id]);
await zp.buildItemContextMenu();
var menu = win.document.getElementById('zotero-itemmenu');
assert.isTrue(menu.querySelector('.zotero-menuitem-export').hidden);
assert.isTrue(menu.querySelector('.zotero-menuitem-create-bibliography').hidden);
});
it("should show “Export Note…” for standalone file attachment with note", async function () {
var item1 = await importFileAttachment('test.png');
item1.setNote('<p>Foo</p>');
await item1.saveTx();
var item2 = await importFileAttachment('test.png');
await zp.selectItems([item1.id, item2.id]);
await zp.buildItemContextMenu();
var menu = win.document.getElementById('zotero-itemmenu');
var exportMenuItem = menu.querySelector('.zotero-menuitem-export');
assert.isFalse(exportMenuItem.hidden);
assert.equal(
exportMenuItem.getAttribute('label'),
Zotero.getString('pane.items.menu.exportNote.multiple')
);
});
});
})