Gray out "Import Annotations…" in reader window when no annotations

Fixes #4416
This commit is contained in:
Martynas Bagdonas 2024-07-22 14:41:13 +03:00
parent 74ec6620e3
commit c2575d2a14
2 changed files with 18 additions and 1 deletions

View file

@ -94,7 +94,7 @@
<tooltip id="iframeTooltip" page="true"/>
<menubar>
<menu id="fileMenu" label="&fileMenu.label;" accesskey="&fileMenu.accesskey;">
<menu id="fileMenu" label="&fileMenu.label;" accesskey="&fileMenu.accesskey;" onpopupshowing="onFileMenuOpen()">
<menupopup id="menu_FilePopup">
<menuitem
id="menu_transferFromPDF"

View file

@ -1215,6 +1215,7 @@ class ReaderWindow extends ReaderInstance {
this._window.addEventListener('DOMContentLoaded', (event) => {
if (event.target === this._window.document) {
this._popupset = this._window.document.getElementById('zotero-reader-popupset');
this._window.onFileMenuOpen = this._onFileMenuOpen.bind(this);
this._window.onGoMenuOpen = this._onGoMenuOpen.bind(this);
this._window.onViewMenuOpen = this._onViewMenuOpen.bind(this);
this._window.reader = this;
@ -1251,6 +1252,22 @@ class ReaderWindow extends ReaderInstance {
this._window.document.title = title;
}
_onFileMenuOpen() {
let item = Zotero.Items.get(this._item.id);
let library = Zotero.Libraries.get(item.libraryID);
if (item
&& library.filesEditable
&& library.editable
&& !(item.deleted || item.parentItem && item.parentItem.deleted)) {
let annotations = item.getAnnotations();
let canTransferFromPDF = annotations.find(x => x.annotationIsExternal);
this._window.document.getElementById('menu_transferFromPDF').setAttribute('disabled', !canTransferFromPDF);
}
else {
this._window.document.getElementById('menu_transferFromPDF').setAttribute('disabled', true);
}
}
_onViewMenuOpen() {
if (this._type === 'pdf' || this._type === 'epub') {
this._window.document.getElementById('view-menuitem-no-spreads').setAttribute('checked', this._internalReader.spreadMode === 0);