From 2db17f9eca5e55f12ca11b09a0932bf2eb5fb913 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 8 Apr 2021 06:55:14 +0200 Subject: [PATCH] menu.placeTag --- packages/web/src/commands/registerCommand.ts | 22 +++--- packages/web/src/datagrid/DataGridCore.svelte | 67 ++++++++----------- .../web/src/datagrid/SqlDataGridCore.svelte | 3 + packages/web/src/utility/contextMenu.ts | 37 ++++++++-- 4 files changed, 76 insertions(+), 53 deletions(-) diff --git a/packages/web/src/commands/registerCommand.ts b/packages/web/src/commands/registerCommand.ts index 9425ab0f..63209237 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 97c81968..113ae80d 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} -
+
0) { + tagged.splice(index, 1); + res.push(current); + } else { + index++; + } + } + } else { + res.push(menu); + } } } export function extractMenuItems(menu) { const res = []; - doExtractMenuItems(menu, res); + const tagged = []; + doExtractMenuItems(menu, res, tagged); + + // append tagged, which were not appended by placeTag + res.push(...tagged); return res; }