mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Notebooks: Show keyboard shortcut for run cell (#5097)
* Show keyboard shortcut for run cell * PR comment
This commit is contained in:
@@ -14,6 +14,7 @@ import { getErrorMessage } from 'sql/workbench/parts/notebook/notebookUtils';
|
|||||||
import { ICellModel, CellExecutionState } from 'sql/workbench/parts/notebook/models/modelInterfaces';
|
import { ICellModel, CellExecutionState } from 'sql/workbench/parts/notebook/models/modelInterfaces';
|
||||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||||
import { MultiStateAction, IMultiStateData } from 'sql/workbench/parts/notebook/notebookActions';
|
import { MultiStateAction, IMultiStateData } from 'sql/workbench/parts/notebook/notebookActions';
|
||||||
|
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||||
|
|
||||||
let notebookMoreActionMsg = localize('notebook.failed', "Please select active cell and try again");
|
let notebookMoreActionMsg = localize('notebook.failed', "Please select active cell and try again");
|
||||||
const emptyExecutionCountLabel = '[ ]';
|
const emptyExecutionCountLabel = '[ ]';
|
||||||
@@ -67,13 +68,14 @@ export class RunCellAction extends MultiStateAction<CellExecutionState> {
|
|||||||
private _executionChangedDisposable: IDisposable;
|
private _executionChangedDisposable: IDisposable;
|
||||||
private _context: CellContext;
|
private _context: CellContext;
|
||||||
constructor(context: CellContext, @INotificationService private notificationService: INotificationService,
|
constructor(context: CellContext, @INotificationService private notificationService: INotificationService,
|
||||||
@IConnectionManagementService private connectionManagementService: IConnectionManagementService) {
|
@IConnectionManagementService private connectionManagementService: IConnectionManagementService,
|
||||||
|
@IKeybindingService private keybindingService: IKeybindingService) {
|
||||||
super(RunCellAction.ID, new IMultiStateData<CellExecutionState>([
|
super(RunCellAction.ID, new IMultiStateData<CellExecutionState>([
|
||||||
{ key: CellExecutionState.Hidden, value: { label: emptyExecutionCountLabel, className: '', tooltip: '', hideIcon: true } },
|
{ key: CellExecutionState.Hidden, value: { label: emptyExecutionCountLabel, className: '', tooltip: '', hideIcon: true } },
|
||||||
{ key: CellExecutionState.Stopped, value: { label: '', className: 'toolbarIconRun', tooltip: localize('runCell', 'Run cell') } },
|
{ key: CellExecutionState.Stopped, value: { label: '', className: 'toolbarIconRun', tooltip: localize('runCell', "Run cell"), commandId: 'notebook.command.runactivecell' } },
|
||||||
{ key: CellExecutionState.Running, value: { label: '', className: 'toolbarIconStop', tooltip: localize('stopCell', 'Cancel execution') } },
|
{ key: CellExecutionState.Running, value: { label: '', className: 'toolbarIconStop', tooltip: localize('stopCell', "Cancel execution") } },
|
||||||
{ key: CellExecutionState.Error, value: { label: '', className: 'toolbarIconRunError', tooltip: localize('errorRunCell', 'Error on last run. Click to run again') } },
|
{ key: CellExecutionState.Error, value: { label: '', className: 'toolbarIconRunError', tooltip: localize('errorRunCell', "Error on last run. Click to run again") } },
|
||||||
], CellExecutionState.Hidden));
|
], CellExecutionState.Hidden), keybindingService);
|
||||||
this.ensureContextIsUpdated(context);
|
this.ensureContextIsUpdated(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { noKernel } from 'sql/workbench/services/notebook/common/sessionManager'
|
|||||||
import { IConnectionDialogService } from 'sql/workbench/services/connection/common/connectionDialogService';
|
import { IConnectionDialogService } from 'sql/workbench/services/connection/common/connectionDialogService';
|
||||||
import { NotebookModel } from 'sql/workbench/parts/notebook/models/notebookModel';
|
import { NotebookModel } from 'sql/workbench/parts/notebook/models/notebookModel';
|
||||||
import { generateUri } from 'sql/platform/connection/common/utils';
|
import { generateUri } from 'sql/platform/connection/common/utils';
|
||||||
|
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||||
|
|
||||||
const msgLoading = localize('loading', "Loading kernels...");
|
const msgLoading = localize('loading', "Loading kernels...");
|
||||||
const msgChanging = localize('changing', "Changing kernel...");
|
const msgChanging = localize('changing', "Changing kernel...");
|
||||||
@@ -107,6 +108,7 @@ export interface IActionStateData {
|
|||||||
label?: string;
|
label?: string;
|
||||||
tooltip?: string;
|
tooltip?: string;
|
||||||
hideIcon?: boolean;
|
hideIcon?: boolean;
|
||||||
|
commandId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class IMultiStateData<T> {
|
export class IMultiStateData<T> {
|
||||||
@@ -149,6 +151,10 @@ export class IMultiStateData<T> {
|
|||||||
return this.getStateValueOrDefault<string>((data) => data.tooltip, '');
|
return this.getStateValueOrDefault<string>((data) => data.tooltip, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get commandId(): string {
|
||||||
|
return this.getStateValueOrDefault<string>((data) => data.commandId, '');
|
||||||
|
}
|
||||||
|
|
||||||
private getStateValueOrDefault<U>(getter: (data: IActionStateData) => U, defaultVal?: U): U {
|
private getStateValueOrDefault<U>(getter: (data: IActionStateData) => U, defaultVal?: U): U {
|
||||||
let data = this._stateMap.get(this._state);
|
let data = this._stateMap.get(this._state);
|
||||||
return data ? getter(data) : defaultVal;
|
return data ? getter(data) : defaultVal;
|
||||||
@@ -158,14 +164,24 @@ export class IMultiStateData<T> {
|
|||||||
|
|
||||||
export abstract class MultiStateAction<T> extends Action {
|
export abstract class MultiStateAction<T> extends Action {
|
||||||
|
|
||||||
constructor(id: string, protected states: IMultiStateData<T>) {
|
constructor(id: string, protected states: IMultiStateData<T>, private _keybindingService: IKeybindingService) {
|
||||||
super(id, '');
|
super(id, '');
|
||||||
this.updateLabelAndIcon();
|
this.updateLabelAndIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateLabelAndIcon() {
|
private updateLabelAndIcon() {
|
||||||
|
let keyboardShortcut: string;
|
||||||
|
try {
|
||||||
|
// If a keyboard shortcut exists for the command id passed in, append that to the label
|
||||||
|
if (this.states.commandId !== '') {
|
||||||
|
let binding = this._keybindingService.lookupKeybinding(this.states.commandId);
|
||||||
|
keyboardShortcut = binding ? binding.getLabel() : undefined;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
this.label = this.states.label;
|
this.label = this.states.label;
|
||||||
this.tooltip = this.states.tooltip;
|
this.tooltip = keyboardShortcut ? this.states.tooltip + ` (${keyboardShortcut})` : this.states.tooltip;
|
||||||
this.class = this.states.classes;
|
this.class = this.states.classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user