diff --git a/packages/web/src/commands/registerCommand.ts b/packages/web/src/commands/registerCommand.ts index 9425ab0fc..632092371 100644 --- a/packages/web/src/commands/registerCommand.ts +++ b/packages/web/src/commands/registerCommand.ts @@ -31,13 +31,19 @@ export interface GlobalCommand { export default function registerCommand(command: GlobalCommand) { const { testEnabled } = command; - commands.update(x => ({ - ...x, - [command.id]: { - text: `${command.category}: ${command.name}`, - ...command, - enabled: !testEnabled, - }, - })); + commands.update(x => { + if (x[command.id]) { + console.error(`Command ${command.id} already registered`); + return x; + } + return { + ...x, + [command.id]: { + text: `${command.category}: ${command.name}`, + ...command, + enabled: !testEnabled, + }, + }; + }); invalidateCommandDefinitions(); } diff --git a/packages/web/src/datagrid/DataGridCore.svelte b/packages/web/src/datagrid/DataGridCore.svelte index 97c81968b..113ae80d4 100644 --- a/packages/web/src/datagrid/DataGridCore.svelte +++ b/packages/web/src/datagrid/DataGridCore.svelte @@ -219,7 +219,7 @@ import DataGridRow from './DataGridRow.svelte'; import { getFilterType, getFilterValueExpression } from 'dbgate-filterparser'; import stableStringify from 'json-stable-stringify'; - import contextMenu from '../utility/contextMenu'; + import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu'; import { tick } from 'svelte'; import { cellIsSelected, @@ -303,10 +303,6 @@ display.reload(); } - export function getTabId() { - return tabid; - } - export function save() { if (onSave) onSave(); } @@ -1015,33 +1011,33 @@ return ['filter', columnRealIndex]; } - function createMenu() { - return [ - { command: 'dataGrid.refresh' }, - { command: 'dataGrid.copyToClipboard' }, - { command: 'dataGrid.export' }, - { command: 'dataGrid.switchToForm', hideDisabled: true }, - { command: 'dataGrid.switchToJson', hideDisabled: true }, - { command: 'dataGrid.editJsonDocument', hideDisabled: true }, - { divider: true }, - { command: 'dataGrid.save' }, - { command: 'dataGrid.revertRowChanges' }, - { command: 'dataGrid.revertAllChanges' }, - { command: 'dataGrid.deleteSelectedRows' }, - { command: 'dataGrid.insertNewRow' }, - { command: 'dataGrid.setNull' }, - { divider: true }, - { command: 'dataGrid.filterSelected' }, - { command: 'dataGrid.clearFilter' }, - { command: 'dataGrid.undo' }, - { command: 'dataGrid.redo' }, - { divider: true }, - { command: 'dataGrid.openQuery' }, - { command: 'dataGrid.openFreeTable' }, - { command: 'dataGrid.openChartFromSelection' }, - { command: 'dataGrid.openActiveChart', hideDisabled: true }, - ]; - } + registerMenu( + { command: 'dataGrid.refresh' }, + { command: 'dataGrid.copyToClipboard' }, + { command: 'dataGrid.export' }, + { command: 'dataGrid.switchToForm', hideDisabled: true }, + { command: 'dataGrid.switchToJson', hideDisabled: true }, + { command: 'dataGrid.editJsonDocument', hideDisabled: true }, + { divider: true }, + { command: 'dataGrid.save' }, + { command: 'dataGrid.revertRowChanges' }, + { command: 'dataGrid.revertAllChanges' }, + { command: 'dataGrid.deleteSelectedRows' }, + { command: 'dataGrid.insertNewRow' }, + { command: 'dataGrid.setNull' }, + { divider: true }, + { command: 'dataGrid.filterSelected' }, + { command: 'dataGrid.clearFilter' }, + { command: 'dataGrid.undo' }, + { command: 'dataGrid.redo' }, + { divider: true }, + { command: 'dataGrid.openQuery' }, + { command: 'dataGrid.openFreeTable' }, + { command: 'dataGrid.openChartFromSelection' }, + { placeTag: 'chart' } + ); + + const menu = getContextMenu(); {#if !display || (!isDynamicStructure && (!columns || columns.length == 0))} @@ -1062,12 +1058,7 @@ {/each} {:else} -