Improve popup actions when read-only or multiple annotations selected

Fixes #2046
This commit is contained in:
Martynas Bagdonas 2021-04-28 12:41:43 +03:00
parent 3c3c1ba88a
commit 65329dbf27
2 changed files with 23 additions and 21 deletions

View file

@ -311,7 +311,7 @@ class ReaderInstance {
popup.openPopupAtScreen(data.x, data.y, true); popup.openPopupAtScreen(data.x, data.y, true);
} }
_openAnnotationPopup(x, y, annotationID, colors, selectedColor) { _openAnnotationPopup(x, y, ids, colors, selectedColor, readOnly) {
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 () {
@ -319,32 +319,33 @@ class ReaderInstance {
}); });
let menuitem; let menuitem;
// Add to note // Add to note
if (this._window.ZoteroContextPane.getActiveEditor()) { menuitem = this._window.document.createElement('menuitem');
menuitem = this._window.document.createElement('menuitem'); menuitem.setAttribute('label', 'Add to Note');
menuitem.setAttribute('label', 'Add to Note'); let hasActiveEditor = this._window.ZoteroContextPane.getActiveEditor();
menuitem.addEventListener('command', () => { menuitem.setAttribute('disabled', !hasActiveEditor);
let data = { menuitem.addEventListener('command', () => {
action: 'popupCmd', let data = {
cmd: 'addToNote', action: 'popupCmd',
id: annotationID cmd: 'addToNote',
}; ids
this._postMessage(data); };
}); this._postMessage(data);
popup.appendChild(menuitem); });
// Separator popup.appendChild(menuitem);
popup.appendChild(this._window.document.createElement('menuseparator')); // Separator
} popup.appendChild(this._window.document.createElement('menuseparator'));
// Colors // Colors
for (let color of colors) { for (let color of colors) {
menuitem = this._window.document.createElement('menuitem'); menuitem = this._window.document.createElement('menuitem');
menuitem.setAttribute('label', color[0]); menuitem.setAttribute('label', color[0]);
menuitem.className = 'menuitem-iconic'; menuitem.className = 'menuitem-iconic';
menuitem.setAttribute('disabled', readOnly);
menuitem.setAttribute('image', this._getColorIcon(color[1], color[1] === selectedColor)); menuitem.setAttribute('image', this._getColorIcon(color[1], color[1] === selectedColor));
menuitem.addEventListener('command', () => { menuitem.addEventListener('command', () => {
let data = { let data = {
action: 'popupCmd', action: 'popupCmd',
cmd: 'setAnnotationColor', cmd: 'setAnnotationColor',
id: annotationID, ids,
color: color[1] color: color[1]
}; };
this._postMessage(data); this._postMessage(data);
@ -356,11 +357,12 @@ class ReaderInstance {
// Delete // Delete
menuitem = this._window.document.createElement('menuitem'); menuitem = this._window.document.createElement('menuitem');
menuitem.setAttribute('label', 'Delete'); menuitem.setAttribute('label', 'Delete');
menuitem.setAttribute('disabled', readOnly);
menuitem.addEventListener('command', () => { menuitem.addEventListener('command', () => {
let data = { let data = {
action: 'popupCmd', action: 'popupCmd',
cmd: 'deleteAnnotation', cmd: 'deleteAnnotation',
id: annotationID ids
}; };
this._postMessage(data); this._postMessage(data);
}); });
@ -469,8 +471,8 @@ class ReaderInstance {
return; return;
} }
case 'openAnnotationPopup': { case 'openAnnotationPopup': {
let { x, y, id, colors, selectedColor } = message; let { x, y, ids, colors, selectedColor, readOnly } = message;
this._openAnnotationPopup(x, y, id, colors, selectedColor); this._openAnnotationPopup(x, y, ids, colors, selectedColor, readOnly);
return; return;
} }
case 'openColorPopup': { case 'openColorPopup': {

@ -1 +1 @@
Subproject commit a2ed2bde4914f08d0cbc92668ac959894897f9cf Subproject commit ac0b6bcc362df7691497cdb5c0766ee1fd3f5bf8