diff --git a/src/vs/platform/actions/common/actions.ts b/src/vs/platform/actions/common/actions.ts index f0e548fea19..2233e37ebf9 100644 --- a/src/vs/platform/actions/common/actions.ts +++ b/src/vs/platform/actions/common/actions.ts @@ -46,7 +46,7 @@ export interface ICommandAction { tooltip?: string; icon?: Icon; precondition?: ContextKeyExpression; - toggled?: ContextKeyExpression | { condition: ContextKeyExpression, icon?: Icon, tooltip?: string, title?: string | ILocalizedString }; + toggled?: ContextKeyExpression | { condition: ContextKeyExpression, icon?: Icon, tooltip?: string, title?: string | ILocalizedString; }; } export type ISerializableCommandAction = UriDto; @@ -147,8 +147,10 @@ export class MenuId { static readonly CommentThreadActions = new MenuId('CommentThreadActions'); static readonly CommentTitle = new MenuId('CommentTitle'); static readonly CommentActions = new MenuId('CommentActions'); + static readonly InteractiveToolbar = new MenuId('InteractiveToolbar'); + static readonly InteractiveCellTitle = new MenuId('InteractiveCellTitle'); + static readonly InteractiveCellExecute = new MenuId('InteractiveCellExecute'); static readonly NotebookToolbar = new MenuId('NotebookToolbar'); - static readonly NotebookRightToolbar = new MenuId('NotebookRightToolbar'); static readonly NotebookCellTitle = new MenuId('NotebookCellTitle'); static readonly NotebookCellInsert = new MenuId('NotebookCellInsert'); static readonly NotebookCellBetween = new MenuId('NotebookCellBetween'); @@ -214,7 +216,7 @@ export interface IMenuRegistry { addCommand(userCommand: ICommandAction): IDisposable; getCommand(id: string): ICommandAction | undefined; getCommands(): ICommandsMap; - appendMenuItems(items: Iterable<{ id: MenuId, item: IMenuItem | ISubmenuItem }>): IDisposable; + appendMenuItems(items: Iterable<{ id: MenuId, item: IMenuItem | ISubmenuItem; }>): IDisposable; appendMenuItem(menu: MenuId, item: IMenuItem | ISubmenuItem): IDisposable; getMenuItems(loc: MenuId): Array; } @@ -265,7 +267,7 @@ export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry { return this.appendMenuItems(Iterable.single({ id, item })); } - appendMenuItems(items: Iterable<{ id: MenuId, item: IMenuItem | ISubmenuItem }>): IDisposable { + appendMenuItems(items: Iterable<{ id: MenuId, item: IMenuItem | ISubmenuItem; }>): IDisposable { const changedIds = new Set(); const toRemove = new LinkedList(); @@ -403,8 +405,8 @@ export class MenuItemAction implements IAction { this.checked = false; if (item.toggled) { - const toggled = ((item.toggled as { condition: ContextKeyExpression }).condition ? item.toggled : { condition: item.toggled }) as { - condition: ContextKeyExpression, icon?: Icon, tooltip?: string | ILocalizedString, title?: string | ILocalizedString + const toggled = ((item.toggled as { condition: ContextKeyExpression; }).condition ? item.toggled : { condition: item.toggled }) as { + condition: ContextKeyExpression, icon?: Icon, tooltip?: string | ILocalizedString, title?: string | ILocalizedString; }; this.checked = contextKeyService.contextMatchesRules(toggled.condition); if (this.checked && toggled.tooltip) { @@ -455,7 +457,7 @@ export class SyncActionDescriptor { private readonly _keybindingContext: ContextKeyExpression | undefined; private readonly _keybindingWeight: number | undefined; - public static create(ctor: { new(id: string, label: string, ...services: Services): Action }, + public static create(ctor: { new(id: string, label: string, ...services: Services): Action; }, id: string, label: string | undefined, keybindings?: IKeybindings, keybindingContext?: ContextKeyExpression, keybindingWeight?: number ): SyncActionDescriptor { return new SyncActionDescriptor(ctor as IConstructorSignature2, id, label, keybindings, keybindingContext, keybindingWeight); @@ -522,7 +524,7 @@ export interface IAction2Options extends ICommandAction { /** * One or many menu items. */ - menu?: OneOrN<{ id: MenuId } & Omit>; + menu?: OneOrN<{ id: MenuId; } & Omit>; /** * One keybinding. @@ -541,7 +543,7 @@ export abstract class Action2 { abstract run(accessor: ServicesAccessor, ...args: any[]): void; } -export function registerAction2(ctor: { new(): Action2 }): IDisposable { +export function registerAction2(ctor: { new(): Action2; }): IDisposable { const disposables = new DisposableStore(); const action = new ctor(); diff --git a/src/vs/workbench/api/common/menusExtensionPoint.ts b/src/vs/workbench/api/common/menusExtensionPoint.ts index 513eb79d485..fac4741dc91 100644 --- a/src/vs/workbench/api/common/menusExtensionPoint.ts +++ b/src/vs/workbench/api/common/menusExtensionPoint.ts @@ -184,12 +184,6 @@ const apiMenus: IAPIMenu[] = [ description: localize('notebook.toolbar', "The contributed notebook toolbar menu"), proposed: true }, - { - key: 'notebook/toolbar/right', - id: MenuId.NotebookRightToolbar, - description: localize('notebook.toolbar.right', "The contributed notebook right toolbar menu"), - proposed: true - }, { key: 'notebook/cell/title', id: MenuId.NotebookCellTitle, diff --git a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts index 0e29f058aab..ca391ce7cff 100644 --- a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts +++ b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts @@ -31,6 +31,7 @@ import { NotebookStatusBarController } from 'vs/workbench/contrib/notebook/brows import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService'; import { PLAINTEXT_LANGUAGE_IDENTIFIER } from 'vs/editor/common/modes/modesRegistry'; import { IModeService } from 'vs/editor/common/services/modeService'; +import { MenuId } from 'vs/platform/actions/common/actions'; const DECORATION_KEY = 'interactiveInputDecoration'; @@ -111,7 +112,14 @@ export class InteractiveEditor extends EditorPane { isReadOnly: true, contributions: NotebookEditorExtensionsRegistry.getSomeEditorContributions([ NotebookStatusBarController.id - ]) + ]), + menuIds: { + notebookToolbar: MenuId.InteractiveToolbar, + cellTitleToolbar: MenuId.InteractiveCellTitle, + cellInsertToolbar: MenuId.NotebookCellBetween, + cellTopInsertToolbar: MenuId.NotebookCellListTop, + cellExecuteToolbar: MenuId.InteractiveCellExecute + } }); this.#codeEditorWidget = this.#instantiationService.createInstance(CodeEditorWidget, this.#inputEditorContainer, getSimpleEditorOptions(), getSimpleCodeEditorWidgetOptions()); diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts b/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts index 18ad72a4070..6b9d68c79e3 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts @@ -13,7 +13,7 @@ import { IModeService } from 'vs/editor/common/services/modeService'; import { localize } from 'vs/nls'; import { Action2, IAction2Options, MenuId, MenuItemAction, MenuRegistry, registerAction2 } from 'vs/platform/actions/common/actions'; import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands'; -import { ContextKeyExpr, ContextKeyNotExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; +import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { InputFocusedContext, InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar.ts b/src/vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar.ts index 5d58380dccc..5da5d505506 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar.ts @@ -54,6 +54,11 @@ registerAction2(class extends Action2 { ), group: 'status', order: -10 + }, { + id: MenuId.InteractiveToolbar, + when: NOTEBOOK_KERNEL_COUNT.notEqualsTo(0), + group: 'status', + order: -10 }], description: { description: nls.localize('notebookActions.selectKernel.args', "Notebook Kernel Args"), diff --git a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts index 7d587b28bf2..d5c4fabaa82 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts @@ -25,7 +25,7 @@ import { CellKind, NotebookCellMetadata, IOrderedMimeType, INotebookRendererInfo import { ICellRange, cellRangesToIndexes, reduceRanges } from 'vs/workbench/contrib/notebook/common/notebookRange'; import { Webview } from 'vs/workbench/contrib/webview/browser/webview'; import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel'; -import { IMenu } from 'vs/platform/actions/common/actions'; +import { IMenu, MenuId } from 'vs/platform/actions/common/actions'; import { IEditorPane } from 'vs/workbench/common/editor'; import { ITextEditorOptions, ITextResourceEditorInput } from 'vs/platform/editor/common/editor'; import { IConstructorSignature1 } from 'vs/platform/instantiation/common/instantiation'; @@ -345,6 +345,13 @@ export interface INotebookEditorCreationOptions { readonly isEmbedded?: boolean; readonly isReadOnly?: boolean; readonly contributions?: INotebookEditorContributionDescription[]; + readonly menuIds: { + notebookToolbar: MenuId; + cellTitleToolbar: MenuId; + cellInsertToolbar: MenuId; + cellTopInsertToolbar: MenuId; + cellExecuteToolbar: MenuId; + }; } export interface IActiveNotebookEditor extends INotebookEditor { @@ -366,6 +373,7 @@ export interface INotebookEditor extends ICommonNotebookEditor { textModel?: NotebookTextModel; getId(): string; hasEditorFocus(): boolean; + readonly creationOptions: INotebookEditorCreationOptions; isEmbedded: boolean; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorServiceImpl.ts index 9cd25389253..88c1bc11cfd 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorServiceImpl.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorServiceImpl.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { ResourceMap } from 'vs/base/common/map'; -import { NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget'; +import { getDefaultNotebookCreationOptions, NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget'; import { DisposableStore, IDisposable } from 'vs/base/common/lifecycle'; import { IEditorGroupsService, IEditorGroup, GroupChangeKind } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; @@ -136,7 +136,7 @@ export class NotebookEditorWidgetService implements INotebookEditorService { if (!value) { // NEW widget const instantiationService = accessor.get(IInstantiationService); - const widget = instantiationService.createInstance(NotebookEditorWidget, creationOptions ?? { isEmbedded: false }); + const widget = instantiationService.createInstance(NotebookEditorWidget, creationOptions ?? getDefaultNotebookCreationOptions()); const token = this._tokenPool++; value = { widget, token }; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorToolbar.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorToolbar.ts index 424eecf4304..58e2fdedd38 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorToolbar.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorToolbar.ts @@ -95,7 +95,7 @@ export class NotebookEditorToolbar extends Disposable { private _reigsterNotebookActionsToolbar() { const cellMenu = this.instantiationService.createInstance(CellMenus); - this._notebookGlobalActionsMenu = this._register(cellMenu.getNotebookToolbar(this.contextKeyService)); + this._notebookGlobalActionsMenu = this._register(cellMenu.getMenu(this.notebookEditor.creationOptions.menuIds.notebookToolbar, this.contextKeyService)); this._register(this._notebookGlobalActionsMenu); this._useGlobalToolbar = this.configurationService.getValue(GlobalToolbar) ?? false; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index 1d9b424f786..1fc16a4a44a 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -196,6 +196,18 @@ export class ListViewInfoAccessor extends Disposable { } } +export function getDefaultNotebookCreationOptions() { + return { + menuIds: { + notebookToolbar: MenuId.NotebookToolbar, + cellTitleToolbar: MenuId.NotebookCellTitle, + cellInsertToolbar: MenuId.NotebookCellBetween, + cellTopInsertToolbar: MenuId.NotebookCellListTop, + cellExecuteToolbar: MenuId.NotebookCellExecute + } + }; +} + export class NotebookEditorWidget extends Disposable implements INotebookEditor { private static readonly EDITOR_MEMENTOS = new Map>(); private _overlayContainer!: HTMLElement; diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/cellMenus.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/cellMenus.ts index 54febbfebe3..e8ec56a0f26 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/cellMenus.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/cellMenus.ts @@ -12,31 +12,7 @@ export class CellMenus { @IMenuService private readonly menuService: IMenuService, ) { } - getNotebookToolbar(contextKeyService: IContextKeyService): IMenu { - return this.getMenu(MenuId.NotebookToolbar, contextKeyService); - } - - getNotebookRightToolbar(contextKeyService: IContextKeyService): IMenu { - return this.getMenu(MenuId.NotebookRightToolbar, contextKeyService); - } - - getCellTitleMenu(contextKeyService: IContextKeyService): IMenu { - return this.getMenu(MenuId.NotebookCellTitle, contextKeyService); - } - - getCellInsertionMenu(contextKeyService: IContextKeyService): IMenu { - return this.getMenu(MenuId.NotebookCellBetween, contextKeyService); - } - - getCellTopInsertionMenu(contextKeyService: IContextKeyService): IMenu { - return this.getMenu(MenuId.NotebookCellListTop, contextKeyService); - } - - getCellExecuteMenu(contextKeyService: IContextKeyService): IMenu { - return this.getMenu(MenuId.NotebookCellExecute, contextKeyService); - } - - private getMenu(menuId: MenuId, contextKeyService: IContextKeyService): IMenu { + getMenu(menuId: MenuId, contextKeyService: IContextKeyService): IMenu { const menu = this.menuService.createMenu(menuId, contextKeyService); return menu; } 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 6efea4253fb..4313f2232e0 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts @@ -127,7 +127,7 @@ abstract class AbstractCellRenderer { disposables.add(toolbar); const cellMenu = this.instantiationService.createInstance(CellMenus); - const menu = disposables.add(cellMenu.getCellInsertionMenu(contextKeyService)); + const menu = disposables.add(cellMenu.getMenu(this.notebookEditor.creationOptions.menuIds.cellInsertToolbar, contextKeyService)); const updateActions = () => { const actions = this.getCellToolbarActions(menu); toolbar.setActions(actions.primary, actions.secondary); @@ -357,7 +357,7 @@ export class MarkupCellRenderer extends AbstractCellRenderer implements IListRen const statusBar = disposables.add(this.instantiationService.createInstance(CellEditorStatusBar, editorPart)); - const titleMenu = disposables.add(this.cellMenus.getCellTitleMenu(contextKeyService)); + const titleMenu = disposables.add(this.cellMenus.getMenu(this.notebookEditor.creationOptions.menuIds.cellTitleToolbar, contextKeyService)); const templateData: MarkdownCellRenderTemplate = { useRenderer: this.useRenderer, @@ -741,7 +741,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende const focusIndicatorBottom = DOM.append(container, $('.cell-focus-indicator.cell-focus-indicator-bottom')); const betweenCellToolbar = this.createBetweenCellToolbar(bottomCellContainer, disposables, contextKeyService, this.notebookEditor.notebookOptions); - const titleMenu = disposables.add(this.cellMenus.getCellTitleMenu(contextKeyService)); + const titleMenu = disposables.add(this.cellMenus.getMenu(this.notebookEditor.creationOptions.menuIds.cellTitleToolbar, contextKeyService)); const templateData: CodeCellRenderTemplate = { rootContainer, @@ -842,7 +842,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende actionViewItemProvider: _action => { actionViewItemDisposables.clear(); - const actions = this.getCellToolbarActions(this.cellMenus.getCellExecuteMenu(contextKeyService)); + const actions = this.getCellToolbarActions(this.cellMenus.getMenu(this.notebookEditor.creationOptions.menuIds.cellExecuteToolbar, contextKeyService)); const primary = actions.primary[0]; if (!(primary instanceof MenuItemAction)) { return undefined; @@ -877,10 +877,10 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende } private setupRunToolbar(runButtonContainer: HTMLElement, cellContainer: HTMLElement, contextKeyService: IContextKeyService, disposables: DisposableStore): ToolBar { - const menu = this.cellMenus.getCellExecuteMenu(contextKeyService); + const menu = this.cellMenus.getMenu(this.notebookEditor.creationOptions.menuIds.cellExecuteToolbar, contextKeyService); const runToolbar = this.createRunCellToolbar(runButtonContainer, cellContainer, contextKeyService, disposables); const updateActions = () => { - const actions = this.getCellToolbarActions(this.cellMenus.getCellExecuteMenu(contextKeyService)); + const actions = this.getCellToolbarActions(this.cellMenus.getMenu(this.notebookEditor.creationOptions.menuIds.cellExecuteToolbar, contextKeyService)); runToolbar.setActions(actions.primary); }; updateActions(); @@ -1228,7 +1228,7 @@ export class ListTopCellToolbar extends Disposable { }; const cellMenu = this.instantiationService.createInstance(CellMenus); - this.menu = this._register(cellMenu.getCellTopInsertionMenu(contextKeyService)); + this.menu = this._register(cellMenu.getMenu(this.notebookEditor.creationOptions.menuIds.cellTopInsertToolbar, contextKeyService)); this._register(this.menu.onDidChange(() => { this.updateActions(); }));