commands running from electron

This commit is contained in:
Jan Prochazka
2021-03-15 20:48:43 +01:00
parent 21feb3a042
commit d4a35fb414
8 changed files with 102 additions and 29 deletions

View File

@@ -1,7 +1,7 @@
<script lang="ts" context="module">
import { commands } from '../stores';
import { get } from 'svelte/store';
export function handleCommandKeyDown(e) {
let keyText = '';
if (e.ctrlKey) keyText += 'Ctrl+';
@@ -15,6 +15,7 @@
const command: any = Object.values(commandsValue).find(
(x: any) =>
x.enabled &&
!x.isGroupCommand &&
x.keyText &&
x.keyText
.toLowerCase()

View File

@@ -44,8 +44,8 @@
'text'
);
$: filteredItems = (parentCommand ? parentCommand.getSubCommands() : sortedComands).filter(x =>
filterName(filter, x.text)
$: filteredItems = (parentCommand ? parentCommand.getSubCommands() : sortedComands).filter(
x => !x.isGroupCommand && filterName(filter, x.text)
);
function handleCommand(command) {

View File

@@ -1,5 +1,6 @@
import { tick } from 'svelte';
import { commands } from '../stores';
import { GlobalCommand } from './registerCommand';
let isInvalidated = false;
@@ -12,17 +13,23 @@ export default async function invalidateCommands() {
commands.update(dct => {
let res = null;
for (const key of Object.keys(dct)) {
const command = dct[key];
for (const command of Object.values(dct) as GlobalCommand[]) {
if (command.isGroupCommand) continue;
const { testEnabled } = command;
let enabled = command.enabled;
if (testEnabled) enabled = testEnabled();
if (enabled != command.enabled) {
if (!res) res = { ...dct };
res[key] = {
...command,
enabled,
};
res[command.id].enabled = enabled;
}
}
if (res) {
const values = Object.values(res) as GlobalCommand[];
// test enabled for group commands
for (const command of values) {
if (!command.isGroupCommand) continue;
const groupSources = values.filter(x => x.group == command.group && !x.isGroupCommand && x.enabled);
command.enabled = groupSources.length > 0;
}
}
return res || dct;

View File

@@ -7,10 +7,12 @@ export interface SubCommand {
export interface GlobalCommand {
id: string;
category: string;
category: string; // null for group commands
isGroupCommand?: boolean;
name: string;
text?: string /* category: name */;
keyText?: string;
group?: string;
getSubCommands?: () => SubCommand[];
onClick?: Function;
testEnabled?: () => boolean;
@@ -20,6 +22,7 @@ export interface GlobalCommand {
enabled?: boolean;
showDisabled?: boolean;
toolbarName?: string;
menuName?: string;
toolbarOrder?: number;
disableHandleKeyText?: string;
}
@@ -46,3 +49,4 @@ export default function registerCommand(command: GlobalCommand) {
// });
// }
}

View File

@@ -5,7 +5,7 @@ import { ThemeDefinition } from 'dbgate-types';
import ConnectionModal from '../modals/ConnectionModal.svelte';
import { showModal } from '../modals/modalTools';
import newQuery from '../query/newQuery';
import saveTabFile, { saveTabEnabledStore } from '../utility/saveTabFile';
import saveTabFile from '../utility/saveTabFile';
import openNewTab from '../utility/openNewTab';
function themeCommand(theme: ThemeDefinition) {
@@ -109,6 +109,15 @@ registerCommand({
},
});
registerCommand({
id: 'group.save',
category: null,
isGroupCommand: true,
name: 'Save',
keyText: 'Ctrl+S',
group: 'save',
});
export function registerFileCommands({
idPrefix,
category,
@@ -122,6 +131,7 @@ export function registerFileCommands({
}) {
registerCommand({
id: idPrefix + '.save',
group: 'save',
category,
name: 'Save',
keyText: 'Ctrl+S',