mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-15 07:28:05 +00:00
debt - make IActionViewItemService nicer when dealing with sub menus (#230212)
This commit is contained in:
@@ -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<MenuId>;
|
||||
|
||||
register(menu: MenuId, submenu: MenuId, provider: IActionViewItemProvider, event?: Event<unknown>): IDisposable;
|
||||
register(menu: MenuId, commandId: string, provider: IActionViewItemProvider, event?: Event<unknown>): 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<MenuId> = Event.None;
|
||||
|
||||
register(menu: MenuId, commandId: string, provider: IActionViewItemProvider, event?: Event<unknown>): IDisposable {
|
||||
return toDisposable(() => { });
|
||||
register(menu: MenuId, commandId: string | MenuId, provider: IActionViewItemProvider, event?: Event<unknown>): 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<unknown>): IDisposable {
|
||||
const id = this._makeKey(menu, commandId);
|
||||
register(menu: MenuId, commandOrSubmenuId: string | MenuId, provider: IActionViewItemProvider, event?: Event<unknown>): 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)}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user