From 71248b591d7dee7f11669b3354c5595f0c24912f Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 26 Dec 2021 23:50:15 -0500 Subject: [PATCH] Better handling of export option for notes in items list context menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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) --- chrome/content/zotero/zoteroPane.js | 26 +++++++++++++++----- chrome/locale/en-US/zotero/zotero.properties | 2 ++ test/tests/zoteroPaneTest.js | 24 +++++++++++++++++- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index abbd91053d..63389adc3e 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -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)); diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index 834ab8535f..9284822831 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -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… diff --git a/test/tests/zoteroPaneTest.js b/test/tests/zoteroPaneTest.js index cfc0384d44..d4b775515e 100644 --- a/test/tests/zoteroPaneTest.js +++ b/test/tests/zoteroPaneTest.js @@ -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('

Foo

'); + 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') + ); }); }); })