Skip to content

Commit 425fb1c

Browse files
committed
Notebook action cleanup, add more to f1
1 parent a4f436b commit 425fb1c

1 file changed

Lines changed: 39 additions & 45 deletions

File tree

src/vs/workbench/contrib/notebook/browser/contrib/notebookActions.ts

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const COPY_CELL_UP_COMMAND_ID = 'workbench.notebook.cell.copyUp';
3232
const COPY_CELL_DOWN_COMMAND_ID = 'workbench.notebook.cell.copyDown';
3333

3434
const EXECUTE_CELL_COMMAND_ID = 'workbench.notebook.cell.execute';
35-
const EXECUTE_ACTIVE_CELL_COMMAND_ID = 'workbench.notebook.cell.executeActive';
3635
const CANCEL_CELL_COMMAND_ID = 'workbench.notebook.cell.cancelExecution';
3736
const EXECUTE_NOTEBOOK_COMMAND_ID = 'workbench.notebook.executeNotebook';
3837
const CANCEL_NOTEBOOK_COMMAND_ID = 'workbench.notebook.cancelExecution';
@@ -70,7 +69,7 @@ registerAction2(class extends Action2 {
7069
}
7170

7271
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> {
73-
if (!context) {
72+
if (!isCellActionContext(context)) {
7473
context = getActiveCellContext(accessor);
7574
if (!context) {
7675
return;
@@ -85,13 +84,15 @@ registerAction2(class extends Action2 {
8584
constructor() {
8685
super({
8786
id: CANCEL_CELL_COMMAND_ID,
88-
title: localize('notebookActions.cancel', "Stop Execution"),
89-
icon: { id: 'codicon/primitive-square' }
87+
title: localize('notebookActions.cancel', "Stop Cell Execution"),
88+
category: NOTEBOOK_ACTIONS_CATEGORY,
89+
icon: { id: 'codicon/primitive-square' },
90+
f1: true
9091
});
9192
}
9293

9394
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> {
94-
if (!context) {
95+
if (!isCellActionContext(context)) {
9596
context = getActiveCellContext(accessor);
9697
if (!context) {
9798
return;
@@ -212,7 +213,9 @@ registerAction2(class extends Action2 {
212213
constructor() {
213214
super({
214215
id: EXECUTE_NOTEBOOK_COMMAND_ID,
215-
title: localize('notebookActions.executeNotebook', "Execute Notebook")
216+
title: localize('notebookActions.executeNotebook', "Execute Notebook"),
217+
category: NOTEBOOK_ACTIONS_CATEGORY,
218+
f1: true
216219
});
217220
}
218221

@@ -231,7 +234,9 @@ registerAction2(class extends Action2 {
231234
constructor() {
232235
super({
233236
id: CANCEL_NOTEBOOK_COMMAND_ID,
234-
title: localize('notebookActions.cancelNotebook', "Cancel Notebook Execution")
237+
title: localize('notebookActions.cancelNotebook', "Cancel Notebook Execution"),
238+
category: NOTEBOOK_ACTIONS_CATEGORY,
239+
f1: true
235240
});
236241
}
237242

@@ -246,29 +251,6 @@ registerAction2(class extends Action2 {
246251
}
247252
});
248253

249-
registerAction2(class extends Action2 {
250-
constructor() {
251-
super({
252-
id: EXECUTE_ACTIVE_CELL_COMMAND_ID,
253-
title: localize('notebookActions.executeNotebookCell', "Execute Notebook Active Cell")
254-
});
255-
}
256-
257-
async run(accessor: ServicesAccessor): Promise<void> {
258-
let editorService = accessor.get(IEditorService);
259-
let editor = getActiveNotebookEditor(editorService);
260-
261-
if (!editor) {
262-
return;
263-
}
264-
265-
let activeCell = editor.getActiveCell();
266-
if (activeCell) {
267-
return editor.executeNotebookCell(activeCell);
268-
}
269-
}
270-
});
271-
272254
registerAction2(class extends Action2 {
273255
constructor() {
274256
super({
@@ -368,7 +350,7 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
368350

369351
MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
370352
command: {
371-
id: EXECUTE_ACTIVE_CELL_COMMAND_ID,
353+
id: EXECUTE_CELL_COMMAND_ID,
372354
title: localize('notebookActions.menu.execute', "Execute Notebook Cell"),
373355
icon: { id: 'codicon/run' }
374356
},
@@ -386,7 +368,9 @@ registerAction2(class extends Action2 {
386368
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey)),
387369
primary: KeyCode.KEY_Y,
388370
weight: KeybindingWeight.WorkbenchContrib
389-
}
371+
},
372+
category: NOTEBOOK_ACTIONS_CATEGORY,
373+
f1: true
390374
});
391375
}
392376

@@ -404,7 +388,9 @@ registerAction2(class extends Action2 {
404388
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey)),
405389
primary: KeyCode.KEY_M,
406390
weight: KeybindingWeight.WorkbenchContrib
407-
}
391+
},
392+
category: NOTEBOOK_ACTIONS_CATEGORY,
393+
f1: true
408394
});
409395
}
410396

@@ -481,6 +467,10 @@ export interface INotebookCellActionContext {
481467
notebookEditor: INotebookEditor;
482468
}
483469

470+
function isCellActionContext(context: any): context is INotebookCellActionContext {
471+
return context && !!context.cell && !!context.notebookEditor;
472+
}
473+
484474
function getActiveCellContext(accessor: ServicesAccessor): INotebookCellActionContext | undefined {
485475
const editorService = accessor.get(IEditorService);
486476

@@ -510,7 +500,7 @@ abstract class InsertCellCommand extends Action2 {
510500
}
511501

512502
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> {
513-
if (!context) {
503+
if (!isCellActionContext(context)) {
514504
context = getActiveCellContext(accessor);
515505
if (!context) {
516506
return;
@@ -641,7 +631,7 @@ registerAction2(class extends Action2 {
641631
}
642632

643633
run(accessor: ServicesAccessor, context?: INotebookCellActionContext) {
644-
if (!context) {
634+
if (!isCellActionContext(context)) {
645635
context = getActiveCellContext(accessor);
646636
if (!context) {
647637
return;
@@ -671,7 +661,7 @@ registerAction2(class extends Action2 {
671661
}
672662

673663
run(accessor: ServicesAccessor, context?: INotebookCellActionContext) {
674-
if (!context) {
664+
if (!isCellActionContext(context)) {
675665
context = getActiveCellContext(accessor);
676666
if (!context) {
677667
return;
@@ -709,7 +699,7 @@ registerAction2(class extends Action2 {
709699
}
710700

711701
run(accessor: ServicesAccessor, context?: INotebookCellActionContext) {
712-
if (!context) {
702+
if (!isCellActionContext(context)) {
713703
context = getActiveCellContext(accessor);
714704
if (!context) {
715705
return;
@@ -755,7 +745,7 @@ registerAction2(class extends Action2 {
755745
}
756746

757747
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) {
758-
if (!context) {
748+
if (!isCellActionContext(context)) {
759749
context = getActiveCellContext(accessor);
760750
if (!context) {
761751
return;
@@ -789,7 +779,7 @@ registerAction2(class extends Action2 {
789779
}
790780

791781
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) {
792-
if (!context) {
782+
if (!isCellActionContext(context)) {
793783
context = getActiveCellContext(accessor);
794784
if (!context) {
795785
return;
@@ -805,12 +795,14 @@ registerAction2(class extends Action2 {
805795
super(
806796
{
807797
id: COPY_CELL_UP_COMMAND_ID,
808-
title: localize('notebookActions.copyCellUp', "Copy Cell Up")
798+
title: localize('notebookActions.copyCellUp', "Copy Cell Up"),
799+
category: NOTEBOOK_ACTIONS_CATEGORY,
800+
f1: true
809801
});
810802
}
811803

812804
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) {
813-
if (!context) {
805+
if (!isCellActionContext(context)) {
814806
context = getActiveCellContext(accessor);
815807
if (!context) {
816808
return;
@@ -826,12 +818,14 @@ registerAction2(class extends Action2 {
826818
super(
827819
{
828820
id: COPY_CELL_DOWN_COMMAND_ID,
829-
title: localize('notebookActions.copyCellDown', "Copy Cell Down")
821+
title: localize('notebookActions.copyCellDown', "Copy Cell Down"),
822+
category: NOTEBOOK_ACTIONS_CATEGORY,
823+
f1: true
830824
});
831825
}
832826

833827
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) {
834-
if (!context) {
828+
if (!isCellActionContext(context)) {
835829
context = getActiveCellContext(accessor);
836830
if (!context) {
837831
return;
@@ -856,7 +850,7 @@ registerAction2(class extends Action2 {
856850
}
857851

858852
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> {
859-
if (!context) {
853+
if (!isCellActionContext(context)) {
860854
context = getActiveCellContext(accessor);
861855
if (!context) {
862856
return;
@@ -895,7 +889,7 @@ registerAction2(class extends Action2 {
895889
}
896890

897891
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> {
898-
if (!context) {
892+
if (!isCellActionContext(context)) {
899893
context = getActiveCellContext(accessor);
900894
if (!context) {
901895
return;

0 commit comments

Comments
 (0)