From 3c3c1ba88a8a06ee39f95f4bab05694fc1e17a78 Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Tue, 27 Apr 2021 12:39:10 +0300 Subject: [PATCH] Add "Show in Library" option to PDF reader file menu #2032 --- chrome/content/zotero/reader.xul | 4 +- .../content/zotero/standalone/standalone.xul | 1 + chrome/content/zotero/xpcom/reader.js | 57 ++++++++++--------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/chrome/content/zotero/reader.xul b/chrome/content/zotero/reader.xul index 6aad80bd3b..f38b524e83 100644 --- a/chrome/content/zotero/reader.xul +++ b/chrome/content/zotero/reader.xul @@ -44,8 +44,10 @@ - + + + diff --git a/chrome/content/zotero/standalone/standalone.xul b/chrome/content/zotero/standalone/standalone.xul index 335fcbc378..1f32d39474 100644 --- a/chrome/content/zotero/standalone/standalone.xul +++ b/chrome/content/zotero/standalone/standalone.xul @@ -152,6 +152,7 @@ label="Save As…" oncommand="ZoteroStandalone.onReaderCmd('export')"/> + diff --git a/chrome/content/zotero/xpcom/reader.js b/chrome/content/zotero/xpcom/reader.js index 694bb49c7c..c4bf8386a3 100644 --- a/chrome/content/zotero/xpcom/reader.js +++ b/chrome/content/zotero/xpcom/reader.js @@ -138,6 +138,34 @@ class ReaderInstance { await this._initPromise; this._postMessage({ action: 'setToolbarPlaceholderWidth', width }); } + + menuCmd(cmd) { + if (cmd === 'export') { + let zp = Zotero.getActiveZoteroPane(); + zp.exportPDF(this._itemID); + return; + } + else if (cmd === 'showInLibrary') { + let id = this._itemID; + let item = Zotero.Items.get(this._itemID); + if (item && item.parentItemID) { + id = item.parentItemID; + } + let win = Zotero.getMainWindow(); + if (win) { + win.ZoteroPane.selectItems([id]); + win.Zotero_Tabs.select('zotero-pane'); + win.focus(); + } + return; + } + + let data = { + action: 'menuCmd', + cmd + }; + this._postMessage(data); + } async _setState(state) { let item = Zotero.Items.get(this._itemID); @@ -597,19 +625,6 @@ class ReaderTab extends ReaderInstance { } } - menuCmd(cmd) { - if (cmd === 'export') { - let zp = Zotero.getActiveZoteroPane(); - zp.exportPDF(this._itemID); - return; - } - let data = { - action: 'menuCmd', - cmd - }; - this._postMessage(data); - } - _toggleNoteSidebar(isToggled) { let itemPane = this._window.document.getElementById('zotero-item-pane'); if (itemPane.hidden) { @@ -658,22 +673,8 @@ class ReaderWindow extends ReaderInstance { this._window.addEventListener('DOMContentLoaded', (event) => { if (event.target === this._window.document) { this._window.addEventListener('keypress', this._handleKeyPress); - this._popupset = this._window.document.getElementById('zotero-reader-popupset'); - - this._window.menuCmd = (cmd) => { - if (cmd === 'export') { - let zp = Zotero.getActiveZoteroPane(); - zp.exportPDF(this._itemID); - return; - } - let data = { - action: 'menuCmd', - cmd - }; - this._postMessage(data); - }; - + this._window.menuCmd = this.menuCmd.bind(this); this._iframe = this._window.document.getElementById('reader'); }