Show "Add Notes from Annotations" when multiple items are selected
Closes #2277
This commit is contained in:
parent
964f5cec90
commit
b28db2c8f9
3 changed files with 64 additions and 22 deletions
|
@ -2817,12 +2817,17 @@ var ZoteroPane = new function()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// "Find Available PDFs"
|
// "Add Notes from Annotation" and "Find Available PDFs"
|
||||||
if (collectionTreeRow.filesEditable
|
if (collectionTreeRow.filesEditable
|
||||||
&& !collectionTreeRow.isDuplicates()
|
&& !collectionTreeRow.isDuplicates()
|
||||||
&& !collectionTreeRow.isFeed()
|
&& !collectionTreeRow.isFeed()) {
|
||||||
&& items.some(item => item.isRegularItem())) {
|
if (items.some(item => attachmentsWithExtractableAnnotations(item).length)) {
|
||||||
show.push(m.findPDF, m.sep3);
|
show.push(m.createNoteFromAnnotations, m.sep3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (items.some(item => item.isRegularItem())) {
|
||||||
|
show.push(m.findPDF, m.sep3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let canCreateParent = true;
|
let canCreateParent = true;
|
||||||
|
@ -2884,7 +2889,8 @@ var ZoteroPane = new function()
|
||||||
popup.textContent = '';
|
popup.textContent = '';
|
||||||
let eligibleAttachments = Zotero.Items.get(item.getAttachments())
|
let eligibleAttachments = Zotero.Items.get(item.getAttachments())
|
||||||
.filter(item => item.isPDFAttachment());
|
.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) {
|
if (attachmentsWithAnnotations.length) {
|
||||||
// Display submenu if there's more than one PDF attachment, even if
|
// Display submenu if there's more than one PDF attachment, even if
|
||||||
// there's only attachment with annotations, so it's clear which one
|
// 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
|
// 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.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.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.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) {
|
this.openPreferences = function (paneID, action) {
|
||||||
Zotero.warn("ZoteroPane.openPreferences() is deprecated"
|
Zotero.warn("ZoteroPane.openPreferences() is deprecated"
|
||||||
+ " -- use Zotero.Utilities.Internal.openPreferences() instead");
|
+ " -- 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()) {
|
if (!this.canEdit()) {
|
||||||
this.displayCannotEditLibraryMessage();
|
this.displayCannotEditLibraryMessage();
|
||||||
return;
|
return;
|
||||||
|
@ -4441,7 +4461,10 @@ var ZoteroPane = new function()
|
||||||
var note = await Zotero.EditorInstance.createNoteFromAnnotations(
|
var note = await Zotero.EditorInstance.createNoteFromAnnotations(
|
||||||
attachment.getAnnotations().filter(x => x.annotationType != 'ink'), attachment.parentID
|
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();
|
this.displayCannotEditLibraryMessage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var item = this.getSelectedItems()[0];
|
var items = this.getSelectedItems();
|
||||||
var attachment;
|
var itemIDsToSelect = [];
|
||||||
if (item.isRegularItem()) {
|
for (let item of items) {
|
||||||
attachment = Zotero.Items.get(item.getAttachments())
|
let attachments = [];
|
||||||
.find(x => x.isPDFAttachment() && x.getAnnotations().some(x => x.annotationType != 'ink'));
|
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()) {
|
await this.selectItems(itemIDsToSelect);
|
||||||
attachment = item;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new Error("Not a regular item or file attachment");
|
|
||||||
}
|
|
||||||
return this.createNoteFromAnnotationsForAttachment(attachment);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.createEmptyParent = async function (item) {
|
this.createEmptyParent = async function (item) {
|
||||||
|
|
|
@ -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-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"
|
<menuitem class="menuitem-iconic zotero-menuitem-create-note-from-annotations"
|
||||||
label="&zotero.items.menu.attach.noteFromAnnotations;"
|
|
||||||
oncommand="ZoteroPane.createNoteFromAnnotationsFromSelected()"/>
|
oncommand="ZoteroPane.createNoteFromAnnotationsFromSelected()"/>
|
||||||
<menu class="menuitem-iconic zotero-menuitem-create-note-from-annotations"
|
<menu class="menuitem-iconic zotero-menuitem-create-note-from-annotations">
|
||||||
label="&zotero.items.menu.attach.noteFromAnnotations;">
|
|
||||||
<menupopup id="create-note-from-annotations-popup"/>
|
<menupopup id="create-note-from-annotations-popup"/>
|
||||||
</menu>
|
</menu>
|
||||||
|
|
||||||
|
|
|
@ -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.title = Remove from My Publications
|
||||||
pane.items.removeFromPublications = Are you sure you want to remove the selected item 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.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 = Find Available PDF
|
||||||
pane.items.menu.findAvailablePDF.multiple = Find Available PDFs
|
pane.items.menu.findAvailablePDF.multiple = Find Available PDFs
|
||||||
pane.items.menu.remove = Remove Item from Collection…
|
pane.items.menu.remove = Remove Item from Collection…
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue