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,27 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { HeaderFilter } from 'sql/base/browser/ui/table/plugins/headerFilter.plugin';
import { Table } from 'sql/base/browser/ui/table/table';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
export const InTable = new RawContextKey<boolean>('inTable', true);
export const FilteringEnabled = new RawContextKey<boolean>('filteringEnabled', false);
export class TableContext implements IDisposable {
private _inTable: IContextKey<boolean>;
private _filteringEnabled: IContextKey<boolean>;
constructor(contextKeyService: IContextKeyService, table: Table<Slick.SlickData>) {
this._inTable = InTable.bindTo(contextKeyService);
this._filteringEnabled = FilteringEnabled.bindTo(contextKeyService);
this._inTable.set(true);
this._filteringEnabled.set(table.grid.getPlugins().find(p => p instanceof HeaderFilter) !== undefined);
}
dispose(): void {
}
}

View File

@@ -0,0 +1,61 @@
/*---------------------------------------------------------------------------------------------
* 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 { TableContext } from 'sql/workbench/services/table/browser/tableContext';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
export const SERVICE_ID = 'tableService';
export const ITableService = createDecorator<ITableService>(SERVICE_ID);
/**
* Service to manage the table components used by the application.
*/
export interface ITableService {
_serviceBrand: undefined;
/**
* Register a table
*/
registerTable(table: Table<any>): IDisposable;
/**
* Get the table that has the focus.
*/
getActiveTable(): Table<any> | undefined;
}
export class TableService implements ITableService {
_serviceBrand: undefined;
private _tables: Map<number, Table<any>> = new Map<number, Table<any>>();
private _currentId: number = 1;
constructor(@IContextKeyService private readonly _contextKeyService: IContextKeyService) { }
registerTable(table: Table<any>): IDisposable {
const id = this._currentId++;
this._tables.set(id, table);
const service = this._contextKeyService.createScoped(table.grid.getContainerNode());
const context = new TableContext(service, table);
return {
dispose: () => {
this._tables.delete(id);
service.dispose();
context.dispose();
}
};
}
getActiveTable(): Table<any> | undefined {
for (const table of this._tables.values()) {
if (table?.grid.getContainerNode().contains(document.activeElement)) {
return table;
}
}
return undefined;
}
}