Skip to content

Commit

Permalink
use native clipboard on macos
Browse files Browse the repository at this point in the history
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 chaiNNer-org#958 chaiNNer-org#1590
  • Loading branch information
stonerl committed Aug 1, 2023
1 parent 0e6191d commit 6390bd3
Showing 1 changed file with 134 additions and 70 deletions.
204 changes: 134 additions & 70 deletions src/main/gui/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit 6390bd3

Please sign in to comment.