diff --git a/packages/web/src/commands/CommandListener.svelte b/packages/web/src/commands/CommandListener.svelte index 80dcae3a..2e92772f 100644 --- a/packages/web/src/commands/CommandListener.svelte +++ b/packages/web/src/commands/CommandListener.svelte @@ -1,7 +1,8 @@ diff --git a/packages/web/src/commands/invalidateCommands.ts b/packages/web/src/commands/invalidateCommands.ts index 5f9a11fe..6d0568f8 100644 --- a/packages/web/src/commands/invalidateCommands.ts +++ b/packages/web/src/commands/invalidateCommands.ts @@ -30,6 +30,9 @@ export default async function invalidateCommands() { if (!command.isGroupCommand) continue; const groupSources = values.filter(x => x.group == command.group && !x.isGroupCommand && x.enabled); command.enabled = groupSources.length > 0; + for(const source of groupSources) { + source.keyTextFromGroup = command.keyText; + } } } return res || dct; diff --git a/packages/web/src/commands/registerCommand.ts b/packages/web/src/commands/registerCommand.ts index fad4a3d2..5a5ae9ec 100644 --- a/packages/web/src/commands/registerCommand.ts +++ b/packages/web/src/commands/registerCommand.ts @@ -12,6 +12,7 @@ export interface GlobalCommand { name: string; text?: string /* category: name */; keyText?: string; + keyTextFromGroup?: string; // automatically filled from group group?: string; getSubCommands?: () => SubCommand[]; onClick?: Function; diff --git a/packages/web/src/commands/runCommand.ts b/packages/web/src/commands/runCommand.ts index 26251c21..5212f12e 100644 --- a/packages/web/src/commands/runCommand.ts +++ b/packages/web/src/commands/runCommand.ts @@ -1,9 +1,26 @@ -import { get } from 'svelte/store'; -import { commands } from '../stores'; +import { getCommands } from '../stores'; import { GlobalCommand } from './registerCommand'; -export default function runCommand(commandId: string) { - const commandsValue = get(commands); - const command: GlobalCommand = commandsValue[commandId]; - if (command.enabled) command.onClick(); +export default function runCommand(id) { + const commandsValue = getCommands(); + const command = commandsValue[id]; + if (command) { + if (!command.enabled) return; + if (command.isGroupCommand) { + runGroupCommand(command.group); + } else { + if (command.onClick) { + command.onClick(); + } + } + } +} + +window['dbgate_runCommand'] = runCommand; + +export function runGroupCommand(group) { + const commandsValue = getCommands(); + const values = Object.values(commandsValue) as GlobalCommand[]; + const real = values.find(x => x.group == group && !x.isGroupCommand && x.enabled); + if (real && real.onClick) real.onClick(); } diff --git a/packages/web/src/commands/stdCommands.ts b/packages/web/src/commands/stdCommands.ts index ef430d3d..f6ea157b 100644 --- a/packages/web/src/commands/stdCommands.ts +++ b/packages/web/src/commands/stdCommands.ts @@ -134,7 +134,7 @@ export function registerFileCommands({ group: 'save', category, name: 'Save', - keyText: 'Ctrl+S', + // keyText: 'Ctrl+S', icon: 'icon save', toolbar: true, testEnabled: () => getCurrentEditor() != null, diff --git a/packages/web/src/datagrid/DataGridCore.svelte b/packages/web/src/datagrid/DataGridCore.svelte index 863848a6..8dfb8d18 100644 --- a/packages/web/src/datagrid/DataGridCore.svelte +++ b/packages/web/src/datagrid/DataGridCore.svelte @@ -19,7 +19,7 @@ group: 'save', category: 'Data grid', name: 'Save', - keyText: 'Ctrl+S', + // keyText: 'Ctrl+S', toolbar: true, icon: 'icon save', testEnabled: () => getCurrentDataGrid()?.getGrider()?.allowSave, diff --git a/packages/web/src/modals/DropDownMenu.svelte b/packages/web/src/modals/DropDownMenu.svelte index 933a8d6b..84832d87 100644 --- a/packages/web/src/modals/DropDownMenu.svelte +++ b/packages/web/src/modals/DropDownMenu.svelte @@ -31,7 +31,7 @@ if (command) { return { text: command.name, - keyText: command.keyText, + keyText: command.keyText || command.keyTextFromGroup, onClick: command.onClick, disabled: !command.enabled, }; diff --git a/packages/web/src/stores.ts b/packages/web/src/stores.ts index f58b3030..6fb35e8b 100644 --- a/packages/web/src/stores.ts +++ b/packages/web/src/stores.ts @@ -90,15 +90,3 @@ commands.subscribe(value => { } }); export const getCommands = () => commandsValue; -export function runCommand(id) { - const command = commandsValue[id]; - if (command) { - if (command.isGroupCommand) { - const values = Object.values(commandsValue) as GlobalCommand[]; - const real = values.find(x => x.group == command.group && !x.isGroupCommand && x.enabled); - if (real && real.onClick) real.onClick(); - } - command.onClick(); - } -} -window['dbgate_runCommand'] = runCommand; diff --git a/packages/web/src/widgets/Toolbar.svelte b/packages/web/src/widgets/Toolbar.svelte index 6496c6a3..4e12e60c 100644 --- a/packages/web/src/widgets/Toolbar.svelte +++ b/packages/web/src/widgets/Toolbar.svelte @@ -1,7 +1,7 @@