mac - fixed command+C, command+v

This commit is contained in:
Jan Prochazka
2022-04-18 10:42:50 +02:00
parent f78d37159e
commit 0122b0accc
6 changed files with 84 additions and 7 deletions

View File

@@ -86,7 +86,7 @@ function commandItem(item) {
}
function buildMenu() {
let template = _cloneDeepWith(mainMenuDefinition, item => {
let template = _cloneDeepWith(mainMenuDefinition({ editMenu: true }), item => {
if (item.divider) {
return { type: 'separator' };
}
@@ -164,6 +164,9 @@ ipcMain.on('app-started', async (event, arg) => {
}
});
ipcMain.on('window-action', async (event, arg) => {
if (!mainWindow) {
return;
}
switch (arg) {
case 'minimize':
mainWindow.minimize();
@@ -199,6 +202,23 @@ ipcMain.on('window-action', async (event, arg) => {
case 'zoomreset':
mainWindow.webContents.zoomLevel = 0;
break;
// edit
case 'undo':
mainWindow.webContents.undo();
break;
case 'redo':
mainWindow.webContents.redo();
break;
case 'cut':
mainWindow.webContents.cut();
break;
case 'copy':
mainWindow.webContents.copy();
break;
case 'paste':
mainWindow.webContents.paste();
break;
}
});

View File

@@ -1,4 +1,4 @@
module.exports = [
module.exports = ({ editMenu }) => [
{
label: 'File',
submenu: [
@@ -34,6 +34,20 @@ module.exports = [
],
},
editMenu
? {
label: 'Edit',
submenu: [
{ command: 'edit.undo' },
{ command: 'edit.redo' },
{ divider: true },
{ command: 'edit.cut' },
{ command: 'edit.copy' },
{ command: 'edit.paste' },
],
}
: null,
// {
// label: 'Edit',
// submenu: [

View File

@@ -690,6 +690,50 @@ registerCommand({
onClick: () => getElectron().send('window-action', 'zoomreset'),
});
registerCommand({
id: 'edit.undo',
category: 'Edit',
name: 'Undo',
keyText: 'CtrlOrCommand+Z',
testEnabled: () => getElectron() != null,
onClick: () => getElectron().send('window-action', 'undo'),
});
registerCommand({
id: 'edit.redo',
category: 'Edit',
name: 'Redo',
testEnabled: () => getElectron() != null,
onClick: () => getElectron().send('window-action', 'redo'),
});
registerCommand({
id: 'edit.cut',
category: 'Edit',
name: 'Cut',
keyText: 'CtrlOrCommand+X',
testEnabled: () => getElectron() != null,
onClick: () => getElectron().send('window-action', 'cut'),
});
registerCommand({
id: 'edit.copy',
category: 'Edit',
name: 'Copy',
keyText: 'CtrlOrCommand+C',
testEnabled: () => getElectron() != null,
onClick: () => getElectron().send('window-action', 'copy'),
});
registerCommand({
id: 'edit.paste',
category: 'Edit',
name: 'Paste',
keyText: 'CtrlOrCommand+V',
testEnabled: () => getElectron() != null,
onClick: () => getElectron().send('window-action', 'paste'),
});
const electron = getElectron();
if (electron) {
electron.addEventListener('run-command', (e, commandId) => runCommand(commandId));

View File

@@ -47,7 +47,7 @@
name: 'Insert new row',
toolbarName: 'New row',
icon: 'icon add',
keyText: 'Insert',
keyText: isMac() ? 'Command+I' : 'Insert',
testEnabled: () => getCurrentDataGrid()?.getGrider()?.editable,
onClick: () => getCurrentDataGrid().insertNewRow(),
});
@@ -191,7 +191,6 @@
id: 'dataGrid.clearFilter',
category: 'Data grid',
name: 'Clear filter',
keyText: 'CtrlOrCommand+I',
testEnabled: () => getCurrentDataGrid()?.clearFilterEnabled(),
onClick: () => getCurrentDataGrid().clearFilter(),
});
@@ -306,7 +305,7 @@
import EditJsonModal from '../modals/EditJsonModal.svelte';
import { apiCall } from '../utility/api';
import getElectron from '../utility/getElectron';
import { isCtrlOrCommandKey } from '../utility/common';
import { isCtrlOrCommandKey, isMac } from '../utility/common';
export let onLoadNextData = undefined;
export let grider = undefined;

View File

@@ -16,7 +16,7 @@
{#if !isMac()}
<div class="icon"><img src="logo192.png" width="20" height="20" /></div>
<div class="menu">
<HorizontalMenu items={mainMenuDefinition} />
<HorizontalMenu items={mainMenuDefinition({ editMenu: !!electron })} />
</div>
{/if}
<div class="title">{title}</div>

View File

@@ -76,7 +76,7 @@
const rect = domMainMenu.getBoundingClientRect();
const left = rect.right;
const top = rect.top;
const items = mainMenuDefinition;
const items = mainMenuDefinition({ editMenu: false });
currentDropDownMenu.set({ left, top, items });
}