Add context menu for React textboxes to Create Parent Dialog

This commit is contained in:
Fletcher Hazlehurst 2021-02-22 20:14:07 -07:00
parent d9cf53725a
commit 60d8beece3
2 changed files with 64 additions and 1 deletions

View file

@ -78,3 +78,27 @@ function doManualEntry() {
io.dataOut = { parent: false };
window.close();
}
// Support context menus on HTML text boxes
//
// Adapted from editMenuOverlay.js in Fx68
window.addEventListener("contextmenu", e => {
const HTML_NS = "http://www.w3.org/1999/xhtml";
let needsContextMenu =
e.target.ownerDocument == document &&
!e.defaultPrevented &&
e.target.parentNode.nodeName != "moz-input-box" &&
((["textarea", "input"].includes(e.target.localName) &&
e.target.namespaceURI == HTML_NS) ||
e.target.closest("search-textbox"));
if (!needsContextMenu) {
return;
}
let popup = document.getElementById("contentAreaContextMenu");
popup.openPopupAtScreen(e.screenX, e.screenY, true);
// Don't show any other context menu at the same time. There can be a
// context menu from an ancestor too but we only want to show this one.
e.preventDefault();
});

View file

@ -5,7 +5,12 @@
<?xml-stylesheet href="chrome://zotero-platform/content/overlay.css" type="text/css"?>
<?xml-stylesheet href="chrome://zotero-platform/content/zotero-react-client.css"?>
<!DOCTYPE window SYSTEM "chrome://zotero/locale/zotero.dtd">
<?xul-overlay href="chrome://zotero/content/standalone/editMenuOverlay.xul"?>
<!DOCTYPE dialog [
<!ENTITY % textcontextDTD SYSTEM "chrome://global/locale/textcontext.dtd" > %textcontextDTD;
<!ENTITY % zoteroDTD SYSTEM "chrome://zotero/locale/zotero.dtd"> %zoteroDTD;
]>
<dialog
id="zotero-parent-dialog"
@ -23,11 +28,45 @@
xmlns:html="http://www.w3.org/1999/xhtml"
style="padding:20px 15px;width:400px;">
<script src="chrome://global/content/globalOverlay.js"/>
<script src="include.js"/>
<script src="lookup.js"/>
<script src="createParentDialog.js"/>
<script src="components/createParent/createParent.js"/>
<commandset id="mainCommandSet">
<commandset id="editMenuCommands"/>
</commandset>
<menupopup id="contentAreaContextMenu">
<menuitem id="context-undo"
label="&undoCmd.label;"
accesskey="&undoCmd.accesskey;"
command="cmd_undo"/>
<menuseparator id="context-sep-undo"/>
<menuitem id="context-cut"
label="&cutCmd.label;"
accesskey="&cutCmd.accesskey;"
command="cmd_cut"/>
<menuitem id="context-copy"
label="&copyCmd.label;"
accesskey="&copyCmd.accesskey;"
command="cmd_copy"/>
<menuitem id="context-paste"
label="&pasteCmd.label;"
accesskey="&pasteCmd.accesskey;"
command="cmd_paste"/>
<menuitem id="context-delete"
label="&deleteCmd.label;"
accesskey="&deleteCmd.accesskey;"
command="cmd_delete"/>
<menuseparator id="context-sep-paste"/>
<menuitem id="context-selectall"
label="&selectAllCmd.label;"
accesskey="&selectAllCmd.accesskey;"
command="cmd_selectAll"/>
</menupopup>
<vbox id="zotero-create-parent-container" flex="1">
<html:div id="create-parent" />
</vbox>