diff --git a/src/vs/platform/actions/browser/actionViewItemService.ts b/src/vs/platform/actions/browser/actionViewItemService.ts index fa5739eec65..851b6c9117e 100644 --- a/src/vs/platform/actions/browser/actionViewItemService.ts +++ b/src/vs/platform/actions/browser/actionViewItemService.ts @@ -5,7 +5,7 @@ import { IActionViewItemProvider } from '../../../base/browser/ui/actionbar/actionbar.js'; import { Emitter, Event } from '../../../base/common/event.js'; -import { IDisposable, toDisposable } from '../../../base/common/lifecycle.js'; +import { Disposable, IDisposable, toDisposable } from '../../../base/common/lifecycle.js'; import { InstantiationType, registerSingleton } from '../../instantiation/common/extensions.js'; import { createDecorator } from '../../instantiation/common/instantiation.js'; import { MenuId } from '../common/actions.js'; @@ -19,8 +19,10 @@ export interface IActionViewItemService { onDidChange: Event; + register(menu: MenuId, submenu: MenuId, provider: IActionViewItemProvider, event?: Event): IDisposable; register(menu: MenuId, commandId: string, provider: IActionViewItemProvider, event?: Event): IDisposable; + lookUp(menu: MenuId, submenu: MenuId): IActionViewItemProvider | undefined; lookUp(menu: MenuId, commandId: string): IActionViewItemProvider | undefined; } @@ -29,11 +31,11 @@ export class NullActionViewItemService implements IActionViewItemService { onDidChange: Event = Event.None; - register(menu: MenuId, commandId: string, provider: IActionViewItemProvider, event?: Event): IDisposable { - return toDisposable(() => { }); + register(menu: MenuId, commandId: string | MenuId, provider: IActionViewItemProvider, event?: Event): IDisposable { + return Disposable.None; } - lookUp(menu: MenuId, commandId: string): IActionViewItemProvider | undefined { + lookUp(menu: MenuId, commandId: string | MenuId): IActionViewItemProvider | undefined { return undefined; } } @@ -51,10 +53,10 @@ class ActionViewItemService implements IActionViewItemService { this._onDidChange.dispose(); } - register(menu: MenuId, commandId: string, provider: IActionViewItemProvider, event?: Event): IDisposable { - const id = this._makeKey(menu, commandId); + register(menu: MenuId, commandOrSubmenuId: string | MenuId, provider: IActionViewItemProvider, event?: Event): IDisposable { + const id = this._makeKey(menu, commandOrSubmenuId); if (this._providers.has(id)) { - throw new Error(`A provider for the command ${commandId} and menu ${menu} is already registered.`); + throw new Error(`A provider for the command ${commandOrSubmenuId} and menu ${menu} is already registered.`); } this._providers.set(id, provider); @@ -68,12 +70,12 @@ class ActionViewItemService implements IActionViewItemService { }); } - lookUp(menu: MenuId, commandId: string): IActionViewItemProvider | undefined { - return this._providers.get(this._makeKey(menu, commandId)); + lookUp(menu: MenuId, commandOrMenuId: string | MenuId): IActionViewItemProvider | undefined { + return this._providers.get(this._makeKey(menu, commandOrMenuId)); } - private _makeKey(menu: MenuId, commandId: string) { - return menu.id + commandId; + private _makeKey(menu: MenuId, commandOrMenuId: string | MenuId) { + return `${menu.id}/${(commandOrMenuId instanceof MenuId ? commandOrMenuId.id : commandOrMenuId)}`; } } diff --git a/src/vs/platform/actions/browser/toolbar.ts b/src/vs/platform/actions/browser/toolbar.ts index b0a033af8eb..741f946c6f8 100644 --- a/src/vs/platform/actions/browser/toolbar.ts +++ b/src/vs/platform/actions/browser/toolbar.ts @@ -349,7 +349,7 @@ export class MenuWorkbenchToolBar extends WorkbenchToolBar { resetMenu: menuId, ...options, actionViewItemProvider: (action, opts) => { - let provider = actionViewService.lookUp(menuId, action.id); + let provider = actionViewService.lookUp(menuId, action instanceof SubmenuItemAction ? action.item.submenu.id : action.id); if (!provider) { provider = options?.actionViewItemProvider; } diff --git a/src/vs/workbench/contrib/chat/browser/actions/chatActions.ts b/src/vs/workbench/contrib/chat/browser/actions/chatActions.ts index 5ed8892df37..65fd15c1f00 100644 --- a/src/vs/workbench/contrib/chat/browser/actions/chatActions.ts +++ b/src/vs/workbench/contrib/chat/browser/actions/chatActions.ts @@ -447,10 +447,7 @@ export class ChatCommandCenterRendering implements IWorkbenchContribution { @IInstantiationService instantiationService: IInstantiationService, ) { - // TODO@jrieken this isn't proper - const key = `submenuitem.${MenuId.ChatCommandCenter.id}`; - - this._store.add(actionViewItemService.register(MenuId.CommandCenter, key, (action, options) => { + this._store.add(actionViewItemService.register(MenuId.CommandCenter, MenuId.ChatCommandCenter, (action, options) => { const agent = agentService.getDefaultAgent(ChatAgentLocation.Panel); if (!agent?.metadata.themeIcon) {