From 21e5f0c8ab47ca251b0f6f210e1a633dbb0fdd9f Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Thu, 21 Oct 2021 17:01:04 -0700 Subject: [PATCH] Add "NotebookCellExecutePrimary" menu, towards #132057 --- src/vs/platform/actions/common/actions.ts | 1 + .../workbench/api/common/menusExtensionPoint.ts | 6 ++++++ .../interactive/browser/interactiveEditor.ts | 3 ++- .../browser/controller/executeActions.ts | 4 ++-- .../contrib/notebook/browser/notebookBrowser.ts | 1 + .../notebook/browser/notebookEditorWidget.ts | 3 ++- .../browser/view/renderers/cellRenderer.ts | 16 +++++++++------- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/vs/platform/actions/common/actions.ts b/src/vs/platform/actions/common/actions.ts index 952e545781c..88c5de0a7ec 100644 --- a/src/vs/platform/actions/common/actions.ts +++ b/src/vs/platform/actions/common/actions.ts @@ -162,6 +162,7 @@ export class MenuId { static readonly NotebookCellBetween = new MenuId('NotebookCellBetween'); static readonly NotebookCellListTop = new MenuId('NotebookCellTop'); static readonly NotebookCellExecute = new MenuId('NotebookCellExecute'); + static readonly NotebookCellExecutePrimary = new MenuId('NotebookCellExecutePrimary'); static readonly NotebookDiffCellInputTitle = new MenuId('NotebookDiffCellInputTitle'); static readonly NotebookDiffCellMetadataTitle = new MenuId('NotebookDiffCellMetadataTitle'); static readonly NotebookDiffCellOutputsTitle = new MenuId('NotebookDiffCellOutputsTitle'); diff --git a/src/vs/workbench/api/common/menusExtensionPoint.ts b/src/vs/workbench/api/common/menusExtensionPoint.ts index fd4aacc6c7d..805f160947f 100644 --- a/src/vs/workbench/api/common/menusExtensionPoint.ts +++ b/src/vs/workbench/api/common/menusExtensionPoint.ts @@ -193,6 +193,12 @@ const apiMenus: IAPIMenu[] = [ id: MenuId.NotebookCellExecute, description: localize('notebook.cell.execute', "The contributed notebook cell execution menu") }, + { + key: 'notebook/cell/executePrimary', + id: MenuId.NotebookCellExecutePrimary, + description: localize('notebook.cell.executePrimary', "The contributed primary notebook cell execution button"), + proposed: true + }, { key: 'interactive/toolbar', id: MenuId.InteractiveToolbar, diff --git a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts index ac5dd17399b..5e46ea2db8a 100644 --- a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts +++ b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts @@ -246,7 +246,8 @@ export class InteractiveEditor extends EditorPane { cellTitleToolbar: MenuId.InteractiveCellTitle, cellInsertToolbar: MenuId.NotebookCellBetween, cellTopInsertToolbar: MenuId.NotebookCellListTop, - cellExecuteToolbar: MenuId.InteractiveCellExecute + cellExecuteToolbar: MenuId.InteractiveCellExecute, + cellExecutePrimary: undefined }, cellEditorContributions: [], options: this.#notebookOptions diff --git a/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts b/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts index f4a3f1c0dc0..83cdd5c305d 100644 --- a/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts @@ -175,7 +175,7 @@ registerAction2(class ExecuteCell extends NotebookMultiCellAction { weight: NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT }, menu: { - id: MenuId.NotebookCellExecute, + id: MenuId.NotebookCellExecutePrimary, when: executeThisCellCondition, group: 'inline' }, @@ -334,7 +334,7 @@ registerAction2(class CancelExecuteCell extends NotebookMultiCellAction { title: localize('notebookActions.cancel', "Stop Cell Execution"), icon: icons.stopIcon, menu: { - id: MenuId.NotebookCellExecute, + id: MenuId.NotebookCellExecutePrimary, when: cellCancelCondition, group: 'inline' }, diff --git a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts index c97c4f52b3d..2fa0421ca7f 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts @@ -345,6 +345,7 @@ export interface INotebookEditorCreationOptions { cellInsertToolbar: MenuId; cellTopInsertToolbar: MenuId; cellExecuteToolbar: MenuId; + cellExecutePrimary?: MenuId; }; readonly options?: NotebookOptions; } diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index 226efa2e737..585b7bc4201 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -216,7 +216,8 @@ export function getDefaultNotebookCreationOptions() { cellTitleToolbar: MenuId.NotebookCellTitle, cellInsertToolbar: MenuId.NotebookCellBetween, cellTopInsertToolbar: MenuId.NotebookCellListTop, - cellExecuteToolbar: MenuId.NotebookCellExecute + cellExecuteToolbar: MenuId.NotebookCellExecute, + cellExecutePrimary: MenuId.NotebookCellExecutePrimary, } }; } diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts index 67a4148e83e..e64c3bc5687 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts @@ -841,21 +841,22 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende actionViewItemProvider: _action => { actionViewItemDisposables.clear(); - const menu = actionViewItemDisposables.add(this.menuService.createMenu(this.notebookEditor.creationOptions.menuIds.cellExecuteToolbar, contextKeyService)); - const actions = this.getCellToolbarActions(menu); - const primary = actions.primary[0]; + const primaryMenu = actionViewItemDisposables.add(this.menuService.createMenu(this.notebookEditor.creationOptions.menuIds.cellExecutePrimary!, contextKeyService)); + const primary = this.getCellToolbarActions(primaryMenu).primary[0]; if (!(primary instanceof MenuItemAction)) { return undefined; } - if (!actions.secondary.length) { + const menu = actionViewItemDisposables.add(this.menuService.createMenu(this.notebookEditor.creationOptions.menuIds.cellExecuteToolbar, contextKeyService)); + const secondary = this.getCellToolbarActions(menu).secondary; + if (!secondary.length) { return undefined; } const item = this.instantiationService.createInstance(DropdownWithPrimaryActionViewItem, primary, dropdownAction, - actions.secondary, + secondary, 'notebook-cell-run-toolbar', this.contextMenuService, { @@ -874,11 +875,12 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende } private setupRunToolbar(runButtonContainer: HTMLElement, cellContainer: HTMLElement, contextKeyService: IContextKeyService, disposables: DisposableStore): ToolBar { - const menu = disposables.add(this.menuService.createMenu(this.notebookEditor.creationOptions.menuIds.cellExecuteToolbar, contextKeyService)); + const menu = disposables.add(this.menuService.createMenu(this.notebookEditor.creationOptions.menuIds.cellExecutePrimary!, contextKeyService)); const runToolbar = this.createRunCellToolbar(runButtonContainer, cellContainer, contextKeyService, disposables); const updateActions = () => { const actions = this.getCellToolbarActions(menu); - runToolbar.setActions(actions.primary); + const primary = actions.primary[0]; // Only allow one primary action + runToolbar.setActions(primary ? [primary] : []); }; updateActions(); disposables.add(menu.onDidChange(updateActions));