Added context menu option in electron for all input fields AB#16922 (#570)
* Added context menu option in electron for all input fields * Reverted single quote change on comments * Fixed typo
This commit is contained in:
Родитель
99e5b2ae09
Коммит
faf11890c7
|
@ -1,4 +1,4 @@
|
|||
import { app, ipcMain, BrowserWindow, dialog, BrowserWindowConstructorOptions } from "electron";
|
||||
import { app, ipcMain, BrowserWindow, dialog, BrowserWindowConstructorOptions, Menu } from "electron";
|
||||
import { IpcMainProxy } from "./common/ipcMainProxy";
|
||||
import LocalFileSystem from "./providers/storage/localFileSystem";
|
||||
|
||||
|
@ -38,6 +38,8 @@ function createWindow() {
|
|||
mainWindow = null;
|
||||
});
|
||||
|
||||
registerContextMenu(mainWindow);
|
||||
|
||||
ipcMainProxy = new IpcMainProxy(ipcMain, mainWindow);
|
||||
ipcMainProxy.register("RELOAD_APP", onReloadApp);
|
||||
ipcMainProxy.register("TOGGLE_DEV_TOOLS", onToggleDevTools);
|
||||
|
@ -59,6 +61,42 @@ function onToggleDevTools(sender: any, show: boolean) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds standard cut/copy/paste/etc context menu comments when right clicking input elements
|
||||
* @param browserWindow The browser window to apply the context-menu items
|
||||
*/
|
||||
function registerContextMenu(browserWindow: BrowserWindow): void {
|
||||
const selectionMenu = Menu.buildFromTemplate([
|
||||
{ role: "copy", accelerator: "CmdOrCtrl+C" },
|
||||
{ type: "separator" },
|
||||
{ role: "selectall", accelerator: "CmdOrCtrl+A" },
|
||||
]);
|
||||
|
||||
const inputMenu = Menu.buildFromTemplate([
|
||||
{ role: "undo", accelerator: "CmdOrCtrl+Z" },
|
||||
{ role: "redo", accelerator: "CmdOrCtrl+Shift+Z" },
|
||||
{ type: "separator" },
|
||||
{ role: "cut", accelerator: "CmdOrCtrl+X" },
|
||||
{ role: "copy", accelerator: "CmdOrCtrl+C" },
|
||||
{ role: "paste", accelerator: "CmdOrCtrl+V" },
|
||||
{ type: "separator" },
|
||||
{ role: "selectall", accelerator: "CmdOrCtrl+A" },
|
||||
]);
|
||||
|
||||
browserWindow.webContents.on("context-menu", (e, props) => {
|
||||
const { selectionText, isEditable } = props;
|
||||
if (isEditable) {
|
||||
inputMenu.popup({
|
||||
window: browserWindow,
|
||||
});
|
||||
} else if (selectionText && selectionText.trim() !== "") {
|
||||
selectionMenu.popup({
|
||||
window: browserWindow,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
|
|
Загрузка…
Ссылка в новой задаче