From 425fb1ca3ba4bf254650ba89232ff799614db0a3 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Mon, 6 Apr 2020 14:53:53 -0700 Subject: [PATCH] Notebook action cleanup, add more to f1 --- .../browser/contrib/notebookActions.ts | 84 +++++++++---------- 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/notebookActions.ts b/src/vs/workbench/contrib/notebook/browser/contrib/notebookActions.ts index 04306dcb682..451e8348f53 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/notebookActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/notebookActions.ts @@ -32,7 +32,6 @@ const COPY_CELL_UP_COMMAND_ID = 'workbench.notebook.cell.copyUp'; const COPY_CELL_DOWN_COMMAND_ID = 'workbench.notebook.cell.copyDown'; const EXECUTE_CELL_COMMAND_ID = 'workbench.notebook.cell.execute'; -const EXECUTE_ACTIVE_CELL_COMMAND_ID = 'workbench.notebook.cell.executeActive'; const CANCEL_CELL_COMMAND_ID = 'workbench.notebook.cell.cancelExecution'; const EXECUTE_NOTEBOOK_COMMAND_ID = 'workbench.notebook.executeNotebook'; const CANCEL_NOTEBOOK_COMMAND_ID = 'workbench.notebook.cancelExecution'; @@ -70,7 +69,7 @@ registerAction2(class extends Action2 { } async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise { - if (!context) { + if (!isCellActionContext(context)) { context = getActiveCellContext(accessor); if (!context) { return; @@ -85,13 +84,15 @@ registerAction2(class extends Action2 { constructor() { super({ id: CANCEL_CELL_COMMAND_ID, - title: localize('notebookActions.cancel', "Stop Execution"), - icon: { id: 'codicon/primitive-square' } + title: localize('notebookActions.cancel', "Stop Cell Execution"), + category: NOTEBOOK_ACTIONS_CATEGORY, + icon: { id: 'codicon/primitive-square' }, + f1: true }); } async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise { - if (!context) { + if (!isCellActionContext(context)) { context = getActiveCellContext(accessor); if (!context) { return; @@ -212,7 +213,9 @@ registerAction2(class extends Action2 { constructor() { super({ id: EXECUTE_NOTEBOOK_COMMAND_ID, - title: localize('notebookActions.executeNotebook', "Execute Notebook") + title: localize('notebookActions.executeNotebook', "Execute Notebook"), + category: NOTEBOOK_ACTIONS_CATEGORY, + f1: true }); } @@ -231,7 +234,9 @@ registerAction2(class extends Action2 { constructor() { super({ id: CANCEL_NOTEBOOK_COMMAND_ID, - title: localize('notebookActions.cancelNotebook', "Cancel Notebook Execution") + title: localize('notebookActions.cancelNotebook', "Cancel Notebook Execution"), + category: NOTEBOOK_ACTIONS_CATEGORY, + f1: true }); } @@ -246,29 +251,6 @@ registerAction2(class extends Action2 { } }); -registerAction2(class extends Action2 { - constructor() { - super({ - id: EXECUTE_ACTIVE_CELL_COMMAND_ID, - title: localize('notebookActions.executeNotebookCell', "Execute Notebook Active Cell") - }); - } - - async run(accessor: ServicesAccessor): Promise { - let editorService = accessor.get(IEditorService); - let editor = getActiveNotebookEditor(editorService); - - if (!editor) { - return; - } - - let activeCell = editor.getActiveCell(); - if (activeCell) { - return editor.executeNotebookCell(activeCell); - } - } -}); - registerAction2(class extends Action2 { constructor() { super({ @@ -368,7 +350,7 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitle, { MenuRegistry.appendMenuItem(MenuId.EditorTitle, { command: { - id: EXECUTE_ACTIVE_CELL_COMMAND_ID, + id: EXECUTE_CELL_COMMAND_ID, title: localize('notebookActions.menu.execute', "Execute Notebook Cell"), icon: { id: 'codicon/run' } }, @@ -386,7 +368,9 @@ registerAction2(class extends Action2 { when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey)), primary: KeyCode.KEY_Y, weight: KeybindingWeight.WorkbenchContrib - } + }, + category: NOTEBOOK_ACTIONS_CATEGORY, + f1: true }); } @@ -404,7 +388,9 @@ registerAction2(class extends Action2 { when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey)), primary: KeyCode.KEY_M, weight: KeybindingWeight.WorkbenchContrib - } + }, + category: NOTEBOOK_ACTIONS_CATEGORY, + f1: true }); } @@ -481,6 +467,10 @@ export interface INotebookCellActionContext { notebookEditor: INotebookEditor; } +function isCellActionContext(context: any): context is INotebookCellActionContext { + return context && !!context.cell && !!context.notebookEditor; +} + function getActiveCellContext(accessor: ServicesAccessor): INotebookCellActionContext | undefined { const editorService = accessor.get(IEditorService); @@ -510,7 +500,7 @@ abstract class InsertCellCommand extends Action2 { } async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise { - if (!context) { + if (!isCellActionContext(context)) { context = getActiveCellContext(accessor); if (!context) { return; @@ -641,7 +631,7 @@ registerAction2(class extends Action2 { } run(accessor: ServicesAccessor, context?: INotebookCellActionContext) { - if (!context) { + if (!isCellActionContext(context)) { context = getActiveCellContext(accessor); if (!context) { return; @@ -671,7 +661,7 @@ registerAction2(class extends Action2 { } run(accessor: ServicesAccessor, context?: INotebookCellActionContext) { - if (!context) { + if (!isCellActionContext(context)) { context = getActiveCellContext(accessor); if (!context) { return; @@ -709,7 +699,7 @@ registerAction2(class extends Action2 { } run(accessor: ServicesAccessor, context?: INotebookCellActionContext) { - if (!context) { + if (!isCellActionContext(context)) { context = getActiveCellContext(accessor); if (!context) { return; @@ -755,7 +745,7 @@ registerAction2(class extends Action2 { } async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) { - if (!context) { + if (!isCellActionContext(context)) { context = getActiveCellContext(accessor); if (!context) { return; @@ -789,7 +779,7 @@ registerAction2(class extends Action2 { } async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) { - if (!context) { + if (!isCellActionContext(context)) { context = getActiveCellContext(accessor); if (!context) { return; @@ -805,12 +795,14 @@ registerAction2(class extends Action2 { super( { id: COPY_CELL_UP_COMMAND_ID, - title: localize('notebookActions.copyCellUp', "Copy Cell Up") + title: localize('notebookActions.copyCellUp', "Copy Cell Up"), + category: NOTEBOOK_ACTIONS_CATEGORY, + f1: true }); } async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) { - if (!context) { + if (!isCellActionContext(context)) { context = getActiveCellContext(accessor); if (!context) { return; @@ -826,12 +818,14 @@ registerAction2(class extends Action2 { super( { id: COPY_CELL_DOWN_COMMAND_ID, - title: localize('notebookActions.copyCellDown', "Copy Cell Down") + title: localize('notebookActions.copyCellDown', "Copy Cell Down"), + category: NOTEBOOK_ACTIONS_CATEGORY, + f1: true }); } async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) { - if (!context) { + if (!isCellActionContext(context)) { context = getActiveCellContext(accessor); if (!context) { return; @@ -856,7 +850,7 @@ registerAction2(class extends Action2 { } async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise { - if (!context) { + if (!isCellActionContext(context)) { context = getActiveCellContext(accessor); if (!context) { return; @@ -895,7 +889,7 @@ registerAction2(class extends Action2 { } async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise { - if (!context) { + if (!isCellActionContext(context)) { context = getActiveCellContext(accessor); if (!context) { return; -- GitLab