From d96938f6cdb1cc8ca8ad53e66950502f630e3452 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Mon, 1 Jul 2024 12:19:04 -0400 Subject: [PATCH] Attachments box: Build Add menu locally instead of cloning Avoids having to refactor various ZP methods to be aware of the current tab. --- .../content/zotero/elements/attachmentsBox.js | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/elements/attachmentsBox.js b/chrome/content/zotero/elements/attachmentsBox.js index a9b9ef30f2..12cb12af07 100644 --- a/chrome/content/zotero/elements/attachmentsBox.js +++ b/chrome/content/zotero/elements/attachmentsBox.js @@ -34,7 +34,13 @@ - + + + + + + + `); _attachmentIDs = []; @@ -81,9 +87,23 @@ this._attachments = this.querySelector('.attachments-container'); - this._addPopup = document.getElementById('zotero-add-attachment-popup').cloneNode(true); - this._addPopup.id = ''; - this.querySelector('popupset').append(this._addPopup); + this._addPopup = this.querySelector('.add-popup'); + + let [addFile, addLink, addWebLink] = this._addPopup.children; + this._addPopup.addEventListener('popupshowing', () => { + let canAddAny = this.item?.isRegularItem() && this.item.library.editable; + addFile.disabled = addLink.disabled = !(canAddAny && this.item.library.filesEditable); + addWebLink.disabled = !canAddAny; + }); + addFile.addEventListener('command', () => { + ZoteroPane.addAttachmentFromDialog(false, this.item.id); + }); + addLink.addEventListener('command', () => { + ZoteroPane.addAttachmentFromDialog(true, this.item.id); + }); + addWebLink.addEventListener('command', () => { + ZoteroPane.addAttachmentFromURI(true, this.item.id); + }); this.usePreview = Zotero.Prefs.get('showAttachmentPreview'); this._preview = this.querySelector('attachment-preview'); @@ -207,7 +227,6 @@ _handleAdd = (event) => { this._section.open = true; - ZoteroPane.updateAddAttachmentMenu(this._addPopup); this._addPopup.openPopup(event.detail.button, 'after_end'); };