mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-28 09:35:38 -05:00
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:
27
src/sql/workbench/services/table/browser/tableContext.ts
Normal file
27
src/sql/workbench/services/table/browser/tableContext.ts
Normal 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 {
|
||||
}
|
||||
}
|
||||
61
src/sql/workbench/services/table/browser/tableService.ts
Normal file
61
src/sql/workbench/services/table/browser/tableService.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user