From 65329dbf27a6ee3a69ba83ad12a033619cf9dce5 Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Wed, 28 Apr 2021 12:41:43 +0300 Subject: [PATCH] Improve popup actions when read-only or multiple annotations selected Fixes #2046 --- chrome/content/zotero/xpcom/reader.js | 42 ++++++++++++++------------- pdf-reader | 2 +- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/chrome/content/zotero/xpcom/reader.js b/chrome/content/zotero/xpcom/reader.js index c4bf8386a3..88de3010b6 100644 --- a/chrome/content/zotero/xpcom/reader.js +++ b/chrome/content/zotero/xpcom/reader.js @@ -311,7 +311,7 @@ class ReaderInstance { 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'); this._popupset.appendChild(popup); popup.addEventListener('popuphidden', function () { @@ -319,32 +319,33 @@ class ReaderInstance { }); let menuitem; // Add to note - if (this._window.ZoteroContextPane.getActiveEditor()) { - menuitem = this._window.document.createElement('menuitem'); - menuitem.setAttribute('label', 'Add to Note'); - menuitem.addEventListener('command', () => { - let data = { - action: 'popupCmd', - cmd: 'addToNote', - id: annotationID - }; - this._postMessage(data); - }); - popup.appendChild(menuitem); - // Separator - popup.appendChild(this._window.document.createElement('menuseparator')); - } + menuitem = this._window.document.createElement('menuitem'); + menuitem.setAttribute('label', 'Add to Note'); + let hasActiveEditor = this._window.ZoteroContextPane.getActiveEditor(); + menuitem.setAttribute('disabled', !hasActiveEditor); + menuitem.addEventListener('command', () => { + let data = { + action: 'popupCmd', + cmd: 'addToNote', + ids + }; + this._postMessage(data); + }); + popup.appendChild(menuitem); + // Separator + popup.appendChild(this._window.document.createElement('menuseparator')); // Colors for (let color of colors) { menuitem = this._window.document.createElement('menuitem'); menuitem.setAttribute('label', color[0]); menuitem.className = 'menuitem-iconic'; + menuitem.setAttribute('disabled', readOnly); menuitem.setAttribute('image', this._getColorIcon(color[1], color[1] === selectedColor)); menuitem.addEventListener('command', () => { let data = { action: 'popupCmd', cmd: 'setAnnotationColor', - id: annotationID, + ids, color: color[1] }; this._postMessage(data); @@ -356,11 +357,12 @@ class ReaderInstance { // Delete menuitem = this._window.document.createElement('menuitem'); menuitem.setAttribute('label', 'Delete'); + menuitem.setAttribute('disabled', readOnly); menuitem.addEventListener('command', () => { let data = { action: 'popupCmd', cmd: 'deleteAnnotation', - id: annotationID + ids }; this._postMessage(data); }); @@ -469,8 +471,8 @@ class ReaderInstance { return; } case 'openAnnotationPopup': { - let { x, y, id, colors, selectedColor } = message; - this._openAnnotationPopup(x, y, id, colors, selectedColor); + let { x, y, ids, colors, selectedColor, readOnly } = message; + this._openAnnotationPopup(x, y, ids, colors, selectedColor, readOnly); return; } case 'openColorPopup': { diff --git a/pdf-reader b/pdf-reader index a2ed2bde49..ac0b6bcc36 160000 --- a/pdf-reader +++ b/pdf-reader @@ -1 +1 @@ -Subproject commit a2ed2bde4914f08d0cbc92668ac959894897f9cf +Subproject commit ac0b6bcc362df7691497cdb5c0766ee1fd3f5bf8