group commands

This commit is contained in:
Jan Prochazka
2021-03-15 21:06:15 +01:00
parent d4a35fb414
commit 321d5d71de
9 changed files with 49 additions and 28 deletions

View File

@@ -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();
}