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:
Anthony Dresser
2018-09-11 17:10:53 -07:00
committed by Karl Burtram
parent c559ac7be9
commit 89e6d363e2
6 changed files with 47 additions and 24 deletions

View File

@@ -296,15 +296,7 @@ class GridTable<T> 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<T> = {
@@ -344,6 +336,10 @@ class GridTable<T> 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<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[] {
let actions = [];
@@ -436,7 +446,6 @@ class GridTable<T> 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<T> extends Disposable implements IView {
return TPromise.as(actions);
},
getActionsContext: () => {
return <IGridActionContext>{
cell,
selection,
runner: this.runner,
batchId: this.resultSet.batchId,
resultId: this.resultSet.id,
table: this.table,
tableState: this.state
};
return this.generateContext(cell);
}
});
}