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

@@ -53,6 +53,7 @@ import { IDisposableDataProvider } from 'sql/base/common/dataProvider';
import { ITextResourcePropertiesService } from 'vs/editor/common/services/textResourceConfiguration';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
import { ITableService } from 'sql/workbench/services/table/browser/tableService';
const labelDisplay = nls.localize("insights.item", "Item");
const valueDisplay = nls.localize("insights.value", "Value");
@@ -90,7 +91,8 @@ class InsightTableView extends ViewPane {
@IThemeService themeService: IThemeService,
@ITelemetryService telemetryService: ITelemetryService,
@IAccessibilityService private _accessibilityService: IAccessibilityService,
@IQuickInputService private _quickInputService: IQuickInputService
@IQuickInputService private _quickInputService: IQuickInputService,
@ITableService private readonly _tableService: ITableService
) {
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService);
}
@@ -100,6 +102,7 @@ class InsightTableView extends ViewPane {
columns: this.columns,
dataProvider: this.data
}, this.tableOptions);
this._register(this._tableService.registerTable(this._table));
}
protected override layoutBody(size: number): void {

View File

@@ -50,6 +50,7 @@ import { MediaDeviceType } from 'sql/workbench/contrib/backup/common/constants';
import { ITextResourcePropertiesService } from 'vs/editor/common/services/textResourceConfiguration';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
import { ITableService } from 'sql/workbench/services/table/browser/tableService';
interface FileListElement {
logicalFileName: string;
@@ -161,7 +162,8 @@ export class RestoreDialog extends Modal {
@ILogService logService: ILogService,
@ITextResourcePropertiesService textResourcePropertiesService: ITextResourcePropertiesService,
@IAccessibilityService private _accessibilityService: IAccessibilityService,
@IQuickInputService private _quickInputService: IQuickInputService
@IQuickInputService private _quickInputService: IQuickInputService,
@ITableService private readonly _tableService: ITableService
) {
super(localize('RestoreDialogTitle', "Restore database"), TelemetryKeys.ModalDialogName.Restore, telemetryService, layoutService, clipboardService, themeService, logService, textResourcePropertiesService, contextKeyService, { hasErrors: true, width: 'wide', hasSpinner: true });
// view model
@@ -317,6 +319,7 @@ export class RestoreDialog extends Modal {
this._restorePlanTable.setTableTitle(localize('restorePlan', "Restore plan"));
this._restorePlanTable.setSelectionModel(new RowSelectionModel({ selectActiveRow: false }));
this._restorePlanTable.onSelectedRowsChanged((e, data) => this.backupFileCheckboxChanged(e, data));
this._register(this._tableService.registerTable(this._restorePlanTable));
// Content in general tab
const generalTab = DOM.$('.restore-dialog');
@@ -366,6 +369,7 @@ export class RestoreDialog extends Modal {
this._fileListTable = this._register(new Table<FileListElement>(this._fileListTableContainer, this._accessibilityService, this._quickInputService,
{ dataProvider: this._fileListData, columns }, { enableColumnReorder: false }));
this._fileListTable.setSelectionModel(new RowSelectionModel());
this._register(this._tableService.registerTable(this._fileListTable));
// Content in options tab
const optionsContentElement = DOM.$('.restore-dialog');

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;
}
}