Skip to content

Commit

Permalink
use native clipboard on macos (#2031)
Browse files Browse the repository at this point in the history
* 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 #1590

* added a Window menu on mac moved View menu

The View Menu is now located between Edit and Nodes to align it more with the default menu structure on macOS.

Also the Window Menu used on Macs has been added.
  • Loading branch information
stonerl authored Aug 2, 2023
1 parent 29c4a48 commit 5aab59b
Showing 1 changed file with 167 additions and 84 deletions.
251 changes: 167 additions & 84 deletions src/main/gui/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,90 +135,173 @@ 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,
},
],
},
{
label: 'View',
submenu: [
{ role: 'reload', enabled },
{ role: 'forceReload', enabled },
{ type: 'separator' },
{ role: 'resetZoom', enabled },
{ role: 'zoomIn', enabled },
{ role: 'zoomOut', enabled },
{ type: 'separator' },
{ role: 'togglefullscreen' },
...(!app.isPackaged ? [{ type: 'separator' }, { role: 'toggleDevTools' }] : []),
],
},
...(isMac
? [
{ role: 'editMenu' },
{
label: 'View',
submenu: [
{ role: 'reload', enabled },
{ role: 'forceReload', enabled },
{ type: 'separator' },
{ role: 'resetZoom', enabled },
{ role: 'zoomIn', enabled },
{ role: 'zoomOut', enabled },
{ type: 'separator' },
{ role: 'togglefullscreen' },
...(!app.isPackaged
? [{ type: 'separator' }, { role: 'toggleDevTools' }]
: []),
],
},
{
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,
},
],
},
{ role: 'windowMenu' },
]
: [
{
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: [
{ role: 'reload', enabled },
{ role: 'forceReload', enabled },
{ type: 'separator' },
{ role: 'resetZoom', enabled },
{ role: 'zoomIn', enabled },
{ role: 'zoomOut', enabled },
{ type: 'separator' },
{ role: 'togglefullscreen' },
...(!app.isPackaged
? [{ type: 'separator' }, { role: 'toggleDevTools' }]
: []),
],
},
]),
{
role: 'help',
submenu: [
Expand Down

0 comments on commit 5aab59b

Please sign in to comment.