mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Selection in grid context (#2527)
* update action context on selection change * correctly add ranges rather than a new range for every row * add required functions to typings
This commit is contained in:
committed by
Karl Burtram
parent
c559ac7be9
commit
89e6d363e2
@@ -52,7 +52,13 @@ export class AdditionalKeyBindings<T> implements Slick.Plugin<T> {
|
|||||||
} else if (event.equals(KeyCode.End | KeyMod.CtrlCmd)) {
|
} else if (event.equals(KeyCode.End | KeyMod.CtrlCmd)) {
|
||||||
this.grid.setActiveCell(this.grid.getDataLength() - 1, this.grid.getColumns().length - 1);
|
this.grid.setActiveCell(this.grid.getDataLength() - 1, this.grid.getColumns().length - 1);
|
||||||
} else if (event.equals(KeyCode.KEY_A | KeyMod.CtrlCmd)) {
|
} else if (event.equals(KeyCode.KEY_A | KeyMod.CtrlCmd)) {
|
||||||
this.grid.setSelectedRows(range(this.grid.getDataLength()));
|
// check if we can set the rows directly on the selectionModel, its cleaner
|
||||||
|
let selectionModel = this.grid.getSelectionModel();
|
||||||
|
if (selectionModel) {
|
||||||
|
selectionModel.setSelectedRanges([new Slick.Range(0, 0, this.grid.getDataLength() - 1, this.grid.getColumns().length - 1)]);
|
||||||
|
} else {
|
||||||
|
this.grid.setSelectedRows(range(this.grid.getDataLength()));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
handled = false;
|
handled = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ export class CopyKeybind<T> implements Slick.Plugin<T> {
|
|||||||
let selectionModel = this.grid.getSelectionModel();
|
let selectionModel = this.grid.getSelectionModel();
|
||||||
let ranges: Slick.Range[];
|
let ranges: Slick.Range[];
|
||||||
// check to see if we can get the range from the model directly
|
// check to see if we can get the range from the model directly
|
||||||
if (selectionModel && (<any>selectionModel).getSelectedRanges) {
|
if (selectionModel) {
|
||||||
ranges = (<any>selectionModel).getSelectedRanges();
|
ranges = selectionModel.getSelectedRanges();
|
||||||
} else {
|
} else {
|
||||||
let selectedRows = this.grid.getSelectedRows();
|
let selectedRows = this.grid.getSelectedRows();
|
||||||
let startColumn = 0;
|
let startColumn = 0;
|
||||||
|
|||||||
@@ -166,6 +166,10 @@ export class Table<T extends Slick.SlickData> extends Widget implements IThemabl
|
|||||||
this._grid.setData(this._data, true);
|
this._grid.setData(this._data, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getData(): Slick.DataProvider<T> {
|
||||||
|
return this._data;
|
||||||
|
}
|
||||||
|
|
||||||
get columns(): Slick.Column<T>[] {
|
get columns(): Slick.Column<T>[] {
|
||||||
return this._grid.getColumns();
|
return this._grid.getColumns();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,14 @@ import { localize } from 'vs/nls';
|
|||||||
import { TPromise } from 'vs/base/common/winjs.base';
|
import { TPromise } from 'vs/base/common/winjs.base';
|
||||||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||||
import { ITree } from 'vs/base/parts/tree/browser/tree';
|
import { ITree } from 'vs/base/parts/tree/browser/tree';
|
||||||
|
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||||
|
|
||||||
import QueryRunner from 'sql/parts/query/execution/queryRunner';
|
import QueryRunner from 'sql/parts/query/execution/queryRunner';
|
||||||
import { SaveFormat } from 'sql/parts/grid/common/interfaces';
|
import { SaveFormat } from 'sql/parts/grid/common/interfaces';
|
||||||
import { Table } from 'sql/base/browser/ui/table/table';
|
import { Table } from 'sql/base/browser/ui/table/table';
|
||||||
import { GridTableState } from 'sql/parts/query/editor/gridPanel';
|
import { GridTableState } from 'sql/parts/query/editor/gridPanel';
|
||||||
import { QueryEditor } from './queryEditor';
|
import { QueryEditor } from './queryEditor';
|
||||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
import { CellSelectionModel } from 'sql/base/browser/ui/table/plugins/cellSelectionModel.plugin';
|
||||||
|
|
||||||
export interface IGridActionContext {
|
export interface IGridActionContext {
|
||||||
cell: { row: number; cell: number; };
|
cell: { row: number; cell: number; };
|
||||||
@@ -26,6 +27,7 @@ export interface IGridActionContext {
|
|||||||
batchId: number;
|
batchId: number;
|
||||||
resultId: number;
|
resultId: number;
|
||||||
table: Table<any>;
|
table: Table<any>;
|
||||||
|
selectionModel: CellSelectionModel<any>;
|
||||||
tableState: GridTableState;
|
tableState: GridTableState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +115,7 @@ export class SelectAllGridAction extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public run(context: IGridActionContext): TPromise<boolean> {
|
public run(context: IGridActionContext): TPromise<boolean> {
|
||||||
context.table.setSelectedRows(true);
|
context.selectionModel.setSelectedRanges([new Slick.Range(0, 0, context.table.getData().getLength() - 1, context.table.columns.length - 1)]);
|
||||||
return TPromise.as(true);
|
return TPromise.as(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -296,15 +296,7 @@ class GridTable<T> extends Disposable implements IView {
|
|||||||
let numberColumn = new RowNumberColumn({ numberOfRows: this.resultSet.rowCount });
|
let numberColumn = new RowNumberColumn({ numberOfRows: this.resultSet.rowCount });
|
||||||
let copyHandler = new CopyKeybind();
|
let copyHandler = new CopyKeybind();
|
||||||
copyHandler.onCopy(e => {
|
copyHandler.onCopy(e => {
|
||||||
new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, false).run({
|
new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, false).run(this.generateContext());
|
||||||
selection: e,
|
|
||||||
batchId: this.resultSet.batchId,
|
|
||||||
resultId: this.resultSet.id,
|
|
||||||
cell: this.table.grid.getActiveCell(),
|
|
||||||
runner: this.runner,
|
|
||||||
table: this.table,
|
|
||||||
tableState: this.state
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
this.columns.unshift(numberColumn.getColumnDefinition());
|
this.columns.unshift(numberColumn.getColumnDefinition());
|
||||||
let tableOptions: Slick.GridOptions<T> = {
|
let tableOptions: Slick.GridOptions<T> = {
|
||||||
@@ -344,6 +336,10 @@ class GridTable<T> extends Disposable implements IView {
|
|||||||
tableState: this.state
|
tableState: this.state
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// update context before we run an action
|
||||||
|
this.selectionModel.onSelectedRangesChanged.subscribe(e => {
|
||||||
|
this.actionBar.context = this.generateContext();
|
||||||
|
});
|
||||||
this.actionBar.push(actions, { icon: true, label: false });
|
this.actionBar.push(actions, { icon: true, label: false });
|
||||||
|
|
||||||
// change actionbar on maximize change
|
// change actionbar on maximize change
|
||||||
@@ -367,6 +363,20 @@ class GridTable<T> extends Disposable implements IView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private generateContext(cell?: Slick.Cell): IGridActionContext {
|
||||||
|
const selection = this.selectionModel.getSelectedRanges();
|
||||||
|
return <IGridActionContext>{
|
||||||
|
cell,
|
||||||
|
selection,
|
||||||
|
runner: this.runner,
|
||||||
|
batchId: this.resultSet.batchId,
|
||||||
|
resultId: this.resultSet.id,
|
||||||
|
table: this.table,
|
||||||
|
tableState: this.state,
|
||||||
|
selectionModel: this.selectionModel
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private getCurrentActions(): IAction[] {
|
private getCurrentActions(): IAction[] {
|
||||||
|
|
||||||
let actions = [];
|
let actions = [];
|
||||||
@@ -436,7 +446,6 @@ class GridTable<T> extends Disposable implements IView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private contextMenu(e: ITableMouseEvent): void {
|
private contextMenu(e: ITableMouseEvent): void {
|
||||||
const selection = this.selectionModel.getSelectedRanges();
|
|
||||||
const { cell } = e;
|
const { cell } = e;
|
||||||
this.contextMenuService.showContextMenu({
|
this.contextMenuService.showContextMenu({
|
||||||
getAnchor: () => e.anchor,
|
getAnchor: () => e.anchor,
|
||||||
@@ -463,15 +472,7 @@ class GridTable<T> extends Disposable implements IView {
|
|||||||
return TPromise.as(actions);
|
return TPromise.as(actions);
|
||||||
},
|
},
|
||||||
getActionsContext: () => {
|
getActionsContext: () => {
|
||||||
return <IGridActionContext>{
|
return this.generateContext(cell);
|
||||||
cell,
|
|
||||||
selection,
|
|
||||||
runner: this.runner,
|
|
||||||
batchId: this.resultSet.batchId,
|
|
||||||
resultId: this.resultSet.id,
|
|
||||||
table: this.table,
|
|
||||||
tableState: this.state
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/typings/globals/slickgrid/index.d.ts
vendored
10
src/typings/globals/slickgrid/index.d.ts
vendored
@@ -764,6 +764,16 @@ declare namespace Slick {
|
|||||||
**/
|
**/
|
||||||
destroy(): void;
|
destroy(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets selected ranges for the grid
|
||||||
|
*/
|
||||||
|
setSelectedRanges(ranges: Slick.Range[]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets selected ranges for the grid
|
||||||
|
*/
|
||||||
|
getSelectedRanges(): Slick.Range[];
|
||||||
|
|
||||||
onSelectedRangesChanged: Slick.Event<E>;
|
onSelectedRangesChanged: Slick.Event<E>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user