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 5f080a8
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 119 deletions.
3 changes: 0 additions & 3 deletions backend/src/nodes/impl/clipboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
from .clipboard_linux import LinuxClipboard

DEFAULT_CLIPBOARD = LinuxClipboard()
elif sys.platform == "darwin":
from .clipboard_darwin import DarwinClipboard

DEFAULT_CLIPBOARD = DarwinClipboard()
else:
raise NotImplementedError("No suitable clipboard found.")
except Exception as e:
Expand Down
35 changes: 0 additions & 35 deletions backend/src/nodes/impl/clipboard/clipboard_darwin.py

This file was deleted.

13 changes: 2 additions & 11 deletions backend/src/packages/chaiNNer_standard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sanic.log import logger

from api import KB, MB, Dependency, add_package
from system import is_arm_mac, is_windows
from system import is_windows

package = add_package(
__file__,
Expand Down Expand Up @@ -76,16 +76,7 @@
],
)

if is_arm_mac:
package.add_dependency(
Dependency(
display_name="Pasteboard",
pypi_name="pasteboard",
version="0.3.3",
size_estimate=19 * KB,
)
)
elif is_windows:
if is_windows:
package.add_dependency(
Dependency(
display_name="Pywin32",
Expand Down
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 5f080a8

Please sign in to comment.