diff --git a/src/sql/base/browser/ui/table/plugins/additionalKeyBindings.plugin.ts b/src/sql/base/browser/ui/table/plugins/additionalKeyBindings.plugin.ts index a535743606..5711f8c049 100644 --- a/src/sql/base/browser/ui/table/plugins/additionalKeyBindings.plugin.ts +++ b/src/sql/base/browser/ui/table/plugins/additionalKeyBindings.plugin.ts @@ -52,7 +52,13 @@ export class AdditionalKeyBindings implements Slick.Plugin { } else if (event.equals(KeyCode.End | KeyMod.CtrlCmd)) { this.grid.setActiveCell(this.grid.getDataLength() - 1, this.grid.getColumns().length - 1); } 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 { handled = false; } diff --git a/src/sql/base/browser/ui/table/plugins/copyKeybind.plugin.ts b/src/sql/base/browser/ui/table/plugins/copyKeybind.plugin.ts index 0300ca3323..9069e748a2 100644 --- a/src/sql/base/browser/ui/table/plugins/copyKeybind.plugin.ts +++ b/src/sql/base/browser/ui/table/plugins/copyKeybind.plugin.ts @@ -38,8 +38,8 @@ export class CopyKeybind implements Slick.Plugin { let selectionModel = this.grid.getSelectionModel(); let ranges: Slick.Range[]; // check to see if we can get the range from the model directly - if (selectionModel && (selectionModel).getSelectedRanges) { - ranges = (selectionModel).getSelectedRanges(); + if (selectionModel) { + ranges = selectionModel.getSelectedRanges(); } else { let selectedRows = this.grid.getSelectedRows(); let startColumn = 0; diff --git a/src/sql/base/browser/ui/table/table.ts b/src/sql/base/browser/ui/table/table.ts index b9ff3a7de4..12ea8923b6 100644 --- a/src/sql/base/browser/ui/table/table.ts +++ b/src/sql/base/browser/ui/table/table.ts @@ -166,6 +166,10 @@ export class Table extends Widget implements IThemabl this._grid.setData(this._data, true); } + getData(): Slick.DataProvider { + return this._data; + } + get columns(): Slick.Column[] { return this._grid.getColumns(); } diff --git a/src/sql/parts/query/editor/actions.ts b/src/sql/parts/query/editor/actions.ts index cffafdac33..ac8ba1fdaa 100644 --- a/src/sql/parts/query/editor/actions.ts +++ b/src/sql/parts/query/editor/actions.ts @@ -11,13 +11,14 @@ import { localize } from 'vs/nls'; import { TPromise } from 'vs/base/common/winjs.base'; import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; 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 { SaveFormat } from 'sql/parts/grid/common/interfaces'; import { Table } from 'sql/base/browser/ui/table/table'; import { GridTableState } from 'sql/parts/query/editor/gridPanel'; 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 { cell: { row: number; cell: number; }; @@ -26,6 +27,7 @@ export interface IGridActionContext { batchId: number; resultId: number; table: Table; + selectionModel: CellSelectionModel; tableState: GridTableState; } @@ -113,7 +115,7 @@ export class SelectAllGridAction extends Action { } public run(context: IGridActionContext): TPromise { - 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); } } diff --git a/src/sql/parts/query/editor/gridPanel.ts b/src/sql/parts/query/editor/gridPanel.ts index 0de90406b9..f814686c4d 100644 --- a/src/sql/parts/query/editor/gridPanel.ts +++ b/src/sql/parts/query/editor/gridPanel.ts @@ -296,15 +296,7 @@ class GridTable extends Disposable implements IView { let numberColumn = new RowNumberColumn({ numberOfRows: this.resultSet.rowCount }); let copyHandler = new CopyKeybind(); copyHandler.onCopy(e => { - new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, false).run({ - selection: e, - batchId: this.resultSet.batchId, - resultId: this.resultSet.id, - cell: this.table.grid.getActiveCell(), - runner: this.runner, - table: this.table, - tableState: this.state - }); + new CopyResultAction(CopyResultAction.COPY_ID, CopyResultAction.COPY_LABEL, false).run(this.generateContext()); }); this.columns.unshift(numberColumn.getColumnDefinition()); let tableOptions: Slick.GridOptions = { @@ -344,6 +336,10 @@ class GridTable extends Disposable implements IView { 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 }); // change actionbar on maximize change @@ -367,6 +363,20 @@ class GridTable extends Disposable implements IView { } } + private generateContext(cell?: Slick.Cell): IGridActionContext { + const selection = this.selectionModel.getSelectedRanges(); + return { + 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[] { let actions = []; @@ -436,7 +446,6 @@ class GridTable extends Disposable implements IView { } private contextMenu(e: ITableMouseEvent): void { - const selection = this.selectionModel.getSelectedRanges(); const { cell } = e; this.contextMenuService.showContextMenu({ getAnchor: () => e.anchor, @@ -463,15 +472,7 @@ class GridTable extends Disposable implements IView { return TPromise.as(actions); }, getActionsContext: () => { - return { - cell, - selection, - runner: this.runner, - batchId: this.resultSet.batchId, - resultId: this.resultSet.id, - table: this.table, - tableState: this.state - }; + return this.generateContext(cell); } }); } diff --git a/src/typings/globals/slickgrid/index.d.ts b/src/typings/globals/slickgrid/index.d.ts index 57db849b3c..d36180847c 100644 --- a/src/typings/globals/slickgrid/index.d.ts +++ b/src/typings/globals/slickgrid/index.d.ts @@ -764,6 +764,16 @@ declare namespace Slick { **/ destroy(): void; + /** + * Sets selected ranges for the grid + */ + setSelectedRanges(ranges: Slick.Range[]); + + /** + * Gets selected ranges for the grid + */ + getSelectedRanges(): Slick.Range[]; + onSelectedRangesChanged: Slick.Event; }