PDF reader: Add page label update option to annotation popup (#2267)

This commit is contained in:
Martynas Bagdonas 2021-12-08 11:56:11 +02:00 committed by Dan Stillman
parent 3cb5340b26
commit 2cd756b7ae
3 changed files with 65 additions and 32 deletions

View file

@ -447,7 +447,7 @@ class ReaderInstance {
popup.openPopupAtScreen(data.x, data.y, true); popup.openPopupAtScreen(data.x, data.y, true);
} }
_openAnnotationPopup(x, y, ids, colors, selectedColor, readOnly, enableAddToNote) { _openAnnotationPopup(data) {
let popup = this._window.document.createElement('menupopup'); let popup = this._window.document.createElement('menupopup');
this._popupset.appendChild(popup); this._popupset.appendChild(popup);
popup.addEventListener('popuphidden', function () { popup.addEventListener('popuphidden', function () {
@ -458,33 +458,61 @@ class ReaderInstance {
menuitem = this._window.document.createElement('menuitem'); menuitem = this._window.document.createElement('menuitem');
menuitem.setAttribute('label', Zotero.getString('pdfReader.addToNote')); menuitem.setAttribute('label', Zotero.getString('pdfReader.addToNote'));
let hasActiveEditor = this._window.ZoteroContextPane && this._window.ZoteroContextPane.getActiveEditor(); let hasActiveEditor = this._window.ZoteroContextPane && this._window.ZoteroContextPane.getActiveEditor();
menuitem.setAttribute('disabled', !hasActiveEditor || !enableAddToNote); menuitem.setAttribute('disabled', !hasActiveEditor || !data.enableAddToNote);
menuitem.addEventListener('command', () => { menuitem.addEventListener('command', () => {
let data = { this._postMessage({
action: 'popupCmd', action: 'popupCmd',
cmd: 'addToNote', cmd: 'addToNote',
ids ids: data.ids
}; });
this._postMessage(data);
}); });
popup.appendChild(menuitem); popup.appendChild(menuitem);
// Separator // Separator
popup.appendChild(this._window.document.createElement('menuseparator')); popup.appendChild(this._window.document.createElement('menuseparator'));
// Colors // Colors
for (let color of colors) { for (let color of data.colors) {
menuitem = this._window.document.createElement('menuitem'); menuitem = this._window.document.createElement('menuitem');
menuitem.setAttribute('label', Zotero.getString(color[0])); menuitem.setAttribute('label', Zotero.getString(color[0]));
menuitem.className = 'menuitem-iconic'; menuitem.className = 'menuitem-iconic';
menuitem.setAttribute('disabled', readOnly); menuitem.setAttribute('disabled', data.readOnly);
menuitem.setAttribute('image', this._getColorIcon(color[1], color[1] === selectedColor)); menuitem.setAttribute('image', this._getColorIcon(color[1], color[1] === data.selectedColor));
menuitem.addEventListener('command', () => { menuitem.addEventListener('command', () => {
let data = { this._postMessage({
action: 'popupCmd', action: 'popupCmd',
cmd: 'setAnnotationColor', cmd: 'setAnnotationColor',
ids, ids: data.ids,
color: color[1] color: color[1]
}; });
this._postMessage(data); });
popup.appendChild(menuitem);
}
// Separator
popup.appendChild(this._window.document.createElement('menuseparator'));
// Change page number
if (data.enableChangePageNumber) {
menuitem = this._window.document.createElement('menuitem');
menuitem.setAttribute('label', Zotero.getString('pdfReader.changePageNumber'));
menuitem.setAttribute('disabled', data.readOnly);
menuitem.addEventListener('command', () => {
this._postMessage({
action: 'popupCmd',
cmd: 'openPageLabelPopup',
data
});
});
popup.appendChild(menuitem);
}
// Edit highlighted text
if (data.enableEditHighlightedText) {
menuitem = this._window.document.createElement('menuitem');
menuitem.setAttribute('label', Zotero.getString('pdfReader.editHighlightedText'));
menuitem.setAttribute('disabled', data.readOnly);
menuitem.addEventListener('command', () => {
this._postMessage({
action: 'popupCmd',
cmd: 'editHighlightedText',
data
});
}); });
popup.appendChild(menuitem); popup.appendChild(menuitem);
} }
@ -493,42 +521,40 @@ class ReaderInstance {
// Delete // Delete
menuitem = this._window.document.createElement('menuitem'); menuitem = this._window.document.createElement('menuitem');
menuitem.setAttribute('label', Zotero.getString('general.delete')); menuitem.setAttribute('label', Zotero.getString('general.delete'));
menuitem.setAttribute('disabled', readOnly); menuitem.setAttribute('disabled', data.readOnly);
menuitem.addEventListener('command', () => { menuitem.addEventListener('command', () => {
let data = { this._postMessage({
action: 'popupCmd', action: 'popupCmd',
cmd: 'deleteAnnotation', cmd: 'deleteAnnotation',
ids ids: data.ids
}; });
this._postMessage(data);
}); });
popup.appendChild(menuitem); popup.appendChild(menuitem);
popup.openPopupAtScreen(x, y, true); popup.openPopupAtScreen(data.x, data.y, true);
} }
_openColorPopup(elementID, colors, selectedColor) { _openColorPopup(data) {
let popup = this._window.document.createElement('menupopup'); let popup = this._window.document.createElement('menupopup');
this._popupset.appendChild(popup); this._popupset.appendChild(popup);
popup.addEventListener('popuphidden', function () { popup.addEventListener('popuphidden', function () {
popup.remove(); popup.remove();
}); });
let menuitem; let menuitem;
for (let color of colors) { for (let color of data.colors) {
menuitem = this._window.document.createElement('menuitem'); menuitem = this._window.document.createElement('menuitem');
menuitem.setAttribute('label', Zotero.getString(color[0])); menuitem.setAttribute('label', Zotero.getString(color[0]));
menuitem.className = 'menuitem-iconic'; menuitem.className = 'menuitem-iconic';
menuitem.setAttribute('image', this._getColorIcon(color[1], color[1] === selectedColor)); menuitem.setAttribute('image', this._getColorIcon(color[1], color[1] === data.selectedColor));
menuitem.addEventListener('command', () => { menuitem.addEventListener('command', () => {
let data = { this._postMessage({
action: 'popupCmd', action: 'popupCmd',
cmd: 'setColor', cmd: 'setColor',
color: color[1] color: color[1]
}; });
this._postMessage(data);
}); });
popup.appendChild(menuitem); popup.appendChild(menuitem);
} }
let element = this._iframeWindow.document.getElementById(elementID); let element = this._iframeWindow.document.getElementById(data.elementID);
popup.openPopup(element, 'after_start', 0, 0, true); popup.openPopup(element, 'after_start', 0, 0, true);
} }
@ -617,17 +643,15 @@ class ReaderInstance {
return; return;
} }
case 'openPagePopup': { case 'openPagePopup': {
this._openPagePopup(message); this._openPagePopup(message.data);
return; return;
} }
case 'openAnnotationPopup': { case 'openAnnotationPopup': {
let { x, y, ids, colors, selectedColor, readOnly, enableAddToNote } = message; this._openAnnotationPopup(message.data);
this._openAnnotationPopup(x, y, ids, colors, selectedColor, readOnly, enableAddToNote);
return; return;
} }
case 'openColorPopup': { case 'openColorPopup': {
let { elementID, colors, selectedColor } = message; this._openColorPopup(message.data);
this._openColorPopup(elementID, colors, selectedColor);
return; return;
} }
case 'openURL': { case 'openURL': {

View file

@ -47,6 +47,7 @@ general.delete = Delete
general.remove = Remove general.remove = Remove
general.import = Import general.import = Import
general.export = Export general.export = Export
general.update = Update
general.moreInformation = More Information general.moreInformation = More Information
general.seeForMoreInformation = See %S for more information. general.seeForMoreInformation = See %S for more information.
general.open = Open %S general.open = Open %S
@ -1365,6 +1366,14 @@ pdfReader.promptTransferFromPDF.text = Annotations stored in the PDF file will b
pdfReader.promptTransferToPDF.title = Store Annotations in File pdfReader.promptTransferToPDF.title = Store Annotations in File
pdfReader.promptTransferToPDF.text = Annotations will be transferred to the PDF file and will no longer be editable in %S. pdfReader.promptTransferToPDF.text = Annotations will be transferred to the PDF file and will no longer be editable in %S.
pdfReader.promptPasswordProtected = The operation is not supported for password-protected PDF files. pdfReader.promptPasswordProtected = The operation is not supported for password-protected PDF files.
pdfReader.changePageNumber = Change Page Number…
pdfReader.editHighlightedText = Edit Highlighted Text
pdfReader.thisAnnotation = This annotation
pdfReader.selectedAnnotations = Selected annotations
pdfReader.thisPage = This page
pdfReader.thisPageAndLaterPages = This page and later pages
pdfReader.allPages = All pages
pdfReader.autoDetect = Auto-Detect
spellCheck.checkSpelling = Check Spelling spellCheck.checkSpelling = Check Spelling
spellCheck.addRemoveDictionaries = Add/Remove Dictionaries… spellCheck.addRemoveDictionaries = Add/Remove Dictionaries…

@ -1 +1 @@
Subproject commit 86259b8ea386831ff8c40422aa85f896270352f0 Subproject commit ad19758c589219ee1ee643c74ec895e11e3296be