Show "Add Notes from Annotations" when multiple items are selected

Closes #2277
This commit is contained in:
Dan Stillman 2021-12-15 16:37:21 -05:00
parent 964f5cec90
commit b28db2c8f9
3 changed files with 64 additions and 22 deletions

View file

@ -2817,12 +2817,17 @@ var ZoteroPane = new function()
}
}
// "Find Available PDFs"
// "Add Notes from Annotation" and "Find Available PDFs"
if (collectionTreeRow.filesEditable
&& !collectionTreeRow.isDuplicates()
&& !collectionTreeRow.isFeed()
&& items.some(item => item.isRegularItem())) {
show.push(m.findPDF, m.sep3);
&& !collectionTreeRow.isFeed()) {
if (items.some(item => attachmentsWithExtractableAnnotations(item).length)) {
show.push(m.createNoteFromAnnotations, m.sep3);
}
if (items.some(item => item.isRegularItem())) {
show.push(m.findPDF, m.sep3);
}
}
let canCreateParent = true;
@ -2884,7 +2889,8 @@ var ZoteroPane = new function()
popup.textContent = '';
let eligibleAttachments = Zotero.Items.get(item.getAttachments())
.filter(item => item.isPDFAttachment());
let attachmentsWithAnnotations = eligibleAttachments.filter(x => x.getAnnotations().some(x => x.annotationType != 'ink'));
let attachmentsWithAnnotations = eligibleAttachments
.filter(item => isAttachmentWithExtractableAnnotations(item));
if (attachmentsWithAnnotations.length) {
// Display submenu if there's more than one PDF attachment, even if
// there's only attachment with annotations, so it's clear which one
@ -3030,6 +3036,8 @@ var ZoteroPane = new function()
}
// Set labels, plural if necessary
menu.childNodes[m.createNoteFromAnnotations].setAttribute('label', Zotero.getString('pane.items.menu.addNoteFromAnnotations' + multiple));
menu.childNodes[m.createNoteFromAnnotationsMenu].setAttribute('label', Zotero.getString('pane.items.menu.addNoteFromAnnotations' + multiple));
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));
@ -3074,6 +3082,18 @@ var ZoteroPane = new function()
}
};
function attachmentsWithExtractableAnnotations(item) {
return Zotero.Items.get(item.getAttachments())
.filter(item => isAttachmentWithExtractableAnnotations(item));
}
function isAttachmentWithExtractableAnnotations(item) {
return item.isPDFAttachment() && item.getAnnotations().some(x => x.annotationType != 'ink');
}
this.openPreferences = function (paneID, action) {
Zotero.warn("ZoteroPane.openPreferences() is deprecated"
+ " -- use Zotero.Utilities.Internal.openPreferences() instead");
@ -4433,7 +4453,7 @@ var ZoteroPane = new function()
};
this.createNoteFromAnnotationsForAttachment = async function (attachment) {
this.createNoteFromAnnotationsForAttachment = async function (attachment, { skipSelect } = {}) {
if (!this.canEdit()) {
this.displayCannotEditLibraryMessage();
return;
@ -4441,7 +4461,10 @@ var ZoteroPane = new function()
var note = await Zotero.EditorInstance.createNoteFromAnnotations(
attachment.getAnnotations().filter(x => x.annotationType != 'ink'), attachment.parentID
);
await this.selectItem(note.id);
if (!skipSelect) {
await this.selectItem(note.id);
}
return note;
};
@ -4450,19 +4473,38 @@ var ZoteroPane = new function()
this.displayCannotEditLibraryMessage();
return;
}
var item = this.getSelectedItems()[0];
var attachment;
if (item.isRegularItem()) {
attachment = Zotero.Items.get(item.getAttachments())
.find(x => x.isPDFAttachment() && x.getAnnotations().some(x => x.annotationType != 'ink'));
var items = this.getSelectedItems();
var itemIDsToSelect = [];
for (let item of items) {
let attachments = [];
if (item.isRegularItem()) {
// Find all child attachments with non-ink annotations
attachments.push(
...Zotero.Items.get(item.getAttachments())
.filter((x) => {
return x.isPDFAttachment()
&& x.getAnnotations().some(x => x.annotationType != 'ink');
})
);
}
else if (item.isFileAttachment()) {
attachments.push(item);
}
else if (items.length == 1) {
throw new Error("Not a regular item or file attachment");
}
else {
continue;
}
for (let attachment of attachments) {
let note = await this.createNoteFromAnnotationsForAttachment(
attachment,
{ skipSelect: true }
);
itemIDsToSelect.push(note.id);
}
}
else if (item.isFileAttachment()) {
attachment = item;
}
else {
throw new Error("Not a regular item or file attachment");
}
return this.createNoteFromAnnotationsForAttachment(attachment);
await this.selectItems(itemIDsToSelect);
};
this.createEmptyParent = async function (item) {

View file

@ -282,10 +282,8 @@
<menuitem class="menuitem-iconic zotero-menuitem-attach-note" label="&zotero.items.menu.attach.note;" oncommand="ZoteroPane_Local.newNote(false, this.parentNode.getAttribute('itemKey'))"/>
<menuitem class="menuitem-iconic zotero-menuitem-create-note-from-annotations"
label="&zotero.items.menu.attach.noteFromAnnotations;"
oncommand="ZoteroPane.createNoteFromAnnotationsFromSelected()"/>
<menu class="menuitem-iconic zotero-menuitem-create-note-from-annotations"
label="&zotero.items.menu.attach.noteFromAnnotations;">
<menu class="menuitem-iconic zotero-menuitem-create-note-from-annotations">
<menupopup id="create-note-from-annotations-popup"/>
</menu>

View file

@ -322,6 +322,8 @@ pane.items.remove.multiple = Are you sure you want to remove the selected items
pane.items.removeFromPublications.title = Remove from My Publications
pane.items.removeFromPublications = Are you sure you want to remove the selected item from My Publications?
pane.items.removeFromPublications.multiple = Are you sure you want to remove the selected items from My Publications?
pane.items.menu.addNoteFromAnnotations = Add Note from Annotations
pane.items.menu.addNoteFromAnnotations.multiple = Add Notes from Annotations
pane.items.menu.findAvailablePDF = Find Available PDF
pane.items.menu.findAvailablePDF.multiple = Find Available PDFs
pane.items.menu.remove = Remove Item from Collection…