make table keyboard shortcuts configurable (#22582)

* make table keyboard shortcuts configurable

* fix error

* new slickgrid version

* add comment

* tree grid
This commit is contained in:
Alan Ren
2023-04-03 13:21:00 -07:00
committed by GitHub
parent 38a3312cb6
commit 61b3285eaf
38 changed files with 275 additions and 87 deletions

View File

@@ -0,0 +1,52 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Table } from 'sql/base/browser/ui/table/table';
import { FilteringEnabled, InTable } from 'sql/workbench/services/table/browser/tableContext';
import { ITableService } from 'sql/workbench/services/table/browser/tableService';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { KeybindingWeight, KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { HeaderFilter } from 'sql/base/browser/ui/table/plugins/headerFilter.plugin';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
export const RESIZE_COLUMN_COMMAND_ID = 'table.resizeColumn';
export const SHOW_COLUMN_MENU_COMMAND_ID = 'table.showColumnMenu';
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: RESIZE_COLUMN_COMMAND_ID,
weight: KeybindingWeight.WorkbenchContrib,
when: InTable,
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KeyS,
handler: async (accessor) => {
await handleTableCommand(accessor, async (table) => {
await table.resizeActiveColumn();
});
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: SHOW_COLUMN_MENU_COMMAND_ID,
weight: KeybindingWeight.WorkbenchContrib,
when: ContextKeyExpr.and(InTable, FilteringEnabled),
primary: KeyCode.F3,
handler: async (accessor) => {
await handleTableCommand(accessor, async (table) => {
let plugin = table.grid.getPlugins().find(p => p instanceof HeaderFilter) as HeaderFilter<any>;
if (plugin) {
await plugin.showMenu();
}
});
}
});
async function handleTableCommand(accessor: ServicesAccessor, action: (table: Table<any>) => Promise<void>) {
const tableService = accessor.get(ITableService);
const table = tableService.getActiveTable();
if (table) {
await action(table);
}
}