From eb2b06e59c93402420635ffa831aad57ad7ed0d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20F=C3=B6rster?= Date: Tue, 1 Aug 2023 21:31:08 +0200 Subject: [PATCH] use native clipboard on macos On macOS we need the native Edit menu to make all keyboard shortcuts accessable. The shortcuts can copy/cut/paste text and nodes. But using entries from the menu itself only interacts with text. Therefore on macOS a new menu is added: "Nodes" Menu structure: *Nodes | |- Undo |- Redo |-------- |- Cut |- Copy |- Paste |-------- |- Duplicate |- Duplicate with Connections This menus sole purpose is to give the user a menu to interact with Nodes. closes #958 #1590 --- src/main/gui/menu.ts | 204 ++++++++++++++++++++++++++++--------------- 1 file changed, 134 insertions(+), 70 deletions(-) diff --git a/src/main/gui/menu.ts b/src/main/gui/menu.ts index 7696071c79..4ab5e9b2a3 100644 --- a/src/main/gui/menu.ts +++ b/src/main/gui/menu.ts @@ -135,76 +135,140 @@ export const setMainMenu = ({ mainWindow, menuData, enabled = false }: MainMenuA isMac ? { role: 'close', enabled } : { role: 'quit', enabled }, ], }, - { - label: 'Edit', - submenu: [ - { - label: 'Undo', - accelerator: 'CmdOrCtrl+Z', - registerAccelerator: false, - click: () => { - mainWindow.webContents.send('history-undo'); - }, - enabled, - }, - { - label: 'Redo', - accelerator: 'CmdOrCtrl+Y', - registerAccelerator: false, - click: () => { - mainWindow.webContents.send('history-redo'); - }, - enabled, - }, - { type: 'separator' }, - { - label: 'Cut', - accelerator: 'CmdOrCtrl+X', - registerAccelerator: false, - click: () => { - mainWindow.webContents.send('cut'); - }, - enabled, - }, - { - label: 'Copy', - accelerator: 'CmdOrCtrl+C', - registerAccelerator: false, - click: () => { - mainWindow.webContents.send('copy'); - }, - enabled, - }, - { - label: 'Paste', - accelerator: 'CmdOrCtrl+V', - registerAccelerator: false, - click: () => { - mainWindow.webContents.send('paste'); - }, - enabled, - }, - { type: 'separator' }, - { - label: 'Duplicate', - accelerator: 'CmdOrCtrl+D', - registerAccelerator: false, - click: () => { - mainWindow.webContents.send('duplicate'); - }, - enabled, - }, - { - label: 'Duplicate with Connections', - accelerator: 'CmdOrCtrl+Shift+D', - registerAccelerator: false, - click: () => { - mainWindow.webContents.send('duplicate-with-input-edges'); - }, - enabled, - }, - ], - }, + ...(isMac + ? [ + { role: 'editMenu' }, + { + label: 'Nodes', + submenu: [ + { + label: 'Undo', + click: () => { + mainWindow.webContents.send('history-undo'); + }, + enabled, + }, + { + label: 'Redo', + click: () => { + mainWindow.webContents.send('history-redo'); + }, + enabled, + }, + { type: 'separator' }, + { + label: 'Cut', + click: () => { + mainWindow.webContents.send('cut'); + }, + enabled, + }, + { + label: 'Copy', + click: () => { + mainWindow.webContents.send('copy'); + }, + enabled, + }, + { + label: 'Paste', + click: () => { + mainWindow.webContents.send('paste'); + }, + enabled, + }, + { type: 'separator' }, + { + label: 'Duplicate', + accelerator: 'CmdOrCtrl+D', + click: () => { + mainWindow.webContents.send('duplicate'); + }, + enabled, + }, + { + label: 'Duplicate with Connections', + accelerator: 'CmdOrCtrl+Shift+D', + click: () => { + mainWindow.webContents.send('duplicate-with-input-edges'); + }, + enabled, + }, + ], + }, + ] + : [ + { + label: 'Edit', + submenu: [ + { + label: 'Undo', + accelerator: 'CmdOrCtrl+Z', + registerAccelerator: false, + click: () => { + mainWindow.webContents.send('history-undo'); + }, + enabled, + }, + { + label: 'Redo', + accelerator: 'CmdOrCtrl+Y', + registerAccelerator: false, + click: () => { + mainWindow.webContents.send('history-redo'); + }, + enabled, + }, + { type: 'separator' }, + { + label: 'Cut', + accelerator: 'CmdOrCtrl+X', + registerAccelerator: false, + click: () => { + mainWindow.webContents.send('cut'); + }, + enabled, + }, + { + label: 'Copy', + accelerator: 'CmdOrCtrl+C', + registerAccelerator: false, + click: () => { + mainWindow.webContents.send('copy'); + }, + enabled, + }, + { + label: 'Paste', + accelerator: 'CmdOrCtrl+V', + registerAccelerator: false, + click: () => { + mainWindow.webContents.send('paste'); + }, + enabled, + }, + { type: 'separator' }, + { + label: 'Duplicate', + accelerator: 'CmdOrCtrl+D', + registerAccelerator: false, + click: () => { + mainWindow.webContents.send('duplicate'); + }, + enabled, + }, + { + label: 'Duplicate with Connections', + accelerator: 'CmdOrCtrl+Shift+D', + registerAccelerator: false, + click: () => { + mainWindow.webContents.send('duplicate-with-input-edges'); + }, + enabled, + }, + ], + }, + ]), { label: 'View', submenu: [