From aed604ddc01b95dc9c52f4da20b1c4261d99defb Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Wed, 28 Aug 2024 23:36:15 -0400 Subject: [PATCH] Add "Paste and Search" option to lookup context menu (#4636) --- chrome/content/zotero/lookup.js | 26 +++++++++++++++++++++++--- chrome/content/zotero/zoteroPane.xhtml | 3 ++- chrome/locale/en-US/zotero/zotero.ftl | 3 +++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/lookup.js b/chrome/content/zotero/lookup.js index 789dff1b66..6abc11f2ba 100644 --- a/chrome/content/zotero/lookup.js +++ b/chrome/content/zotero/lookup.js @@ -209,9 +209,7 @@ var Zotero_Lookup = new function () { this.getActivePanel = function() { - var mlPanel = document.getElementById("zotero-lookup-multiline"); - if (mlPanel.hidden) return document.getElementById("zotero-lookup-singleLine"); - return mlPanel; + return document.getElementById("zotero-lookup-multiline"); }; @@ -254,6 +252,28 @@ var Zotero_Lookup = new function () { } }; + this.onContextMenu = function (event, textBox) { + event.preventDefault(); + let menu = goBuildEditContextMenu().cloneNode(true); + goUpdateGlobalEditMenuItems(true); + let pasteMenuitem = menu.querySelector("menuitem[data-action='paste']"); + let pasteCommand = document.getElementById("cmd_paste"); + + let pasteAndSearchMenuitem = document.createXULElement("menuitem"); + document.l10n.setAttributes(pasteAndSearchMenuitem, "text-action-paste-and-search"); + pasteAndSearchMenuitem.disabled = pasteCommand.hasAttribute("disabled"); // no 'disabled' property + pasteAndSearchMenuitem.addEventListener("command", () => { + pasteCommand.doCommand(); + this.accept(textBox); + }); + pasteMenuitem.after(pasteAndSearchMenuitem); + + document.querySelector("popupset").append(menu); + menu.addEventListener("popuphiding", () => menu.remove(), + { once: true }); + menu.openPopupAtScreen(event.screenX, event.screenY, true); + }; + this.setMultiline = function (on) { var mlTxtBox = document.getElementById("zotero-lookup-textbox"); diff --git a/chrome/content/zotero/zoteroPane.xhtml b/chrome/content/zotero/zoteroPane.xhtml index 422cf695ee..9160421da1 100644 --- a/chrome/content/zotero/zoteroPane.xhtml +++ b/chrome/content/zotero/zoteroPane.xhtml @@ -1223,7 +1223,7 @@ class="zotero-tb-button" tooltiptext="&zotero.toolbar.lookup.label;" type="panel" - onmousedown="if (this.disabled) { event.preventDefault(); return; } Zotero_Lookup.showPanel(this)" + onmousedown="Zotero_Lookup.handleToolbarButtonMouseDown(event)" />