make MenuId#id a string and a strict identifier

This commit is contained in:
Johannes 2022-07-11 14:19:15 +02:00
parent 9457eb4f14
commit 21147b8c98
No known key found for this signature in database
GPG key ID: 6DEF802A22264FCA
5 changed files with 26 additions and 11 deletions

View file

@ -141,7 +141,8 @@ export class MenuEntryActionViewItem extends ActionViewItem {
@IKeybindingService protected readonly _keybindingService: IKeybindingService,
@INotificationService protected _notificationService: INotificationService,
@IContextKeyService protected _contextKeyService: IContextKeyService,
@IThemeService protected _themeService: IThemeService
@IThemeService protected _themeService: IThemeService,
@IContextMenuService protected _contextMenuService: IContextMenuService
) {
super(undefined, action, { icon: !!(action.class || action.item.icon), label: !action.class && !action.item.icon, draggable: options?.draggable, keybinding: options?.keybinding, hoverDelegate: options?.hoverDelegate });
this._altKey = ModifierKeyEmitter.getInstance();
@ -202,6 +203,17 @@ export class MenuEntryActionViewItem extends ActionViewItem {
mouseOver = true;
updateAltState();
}));
this._register(addDisposableListener(container, 'contextmenu', event => {
event.preventDefault();
event.stopPropagation();
this._contextMenuService.showContextMenu({
getAnchor: () => container,
getActions: () => this._menuItemAction.hideActions.asList()
});
}, true));
}
override updateLabel(): void {
@ -356,7 +368,7 @@ export class DropdownWithDefaultActionViewItem extends BaseActionViewItem {
) {
super(null, submenuAction);
this._options = options;
this._storageKey = `${submenuAction.item.submenu._debugName}_lastActionId`;
this._storageKey = `${submenuAction.item.submenu.id}_lastActionId`;
// determine default action
let defaultAction: IAction | undefined;

View file

@ -45,7 +45,7 @@ export function isISubmenuItem(item: IMenuItem | ISubmenuItem): item is ISubmenu
export class MenuId {
private static _idPool = 0;
private static readonly _idPool = new Set<string>();
static readonly CommandPalette = new MenuId('CommandPalette');
static readonly DebugBreakpointsContext = new MenuId('DebugBreakpointsContext');
@ -162,12 +162,15 @@ export class MenuId {
static readonly NewFile = new MenuId('NewFile');
static readonly MergeToolbar = new MenuId('MergeToolbar');
readonly id: number;
readonly _debugName: string;
constructor(debugName: string) {
this.id = MenuId._idPool++;
this._debugName = debugName;
readonly id: string;
constructor(identifier: string) {
if (MenuId._idPool.has(identifier)) {
throw new Error(`Duplicate menu identifier ${identifier}`);
}
MenuId._idPool.add(identifier);
this.id = identifier;
}
}

View file

@ -48,7 +48,7 @@ class MenuActions extends Disposable {
this._onDidChange.fire();
}
private updateSubmenus(actions: readonly IAction[], submenus: { [id: number]: IMenu }): IDisposable {
private updateSubmenus(actions: readonly IAction[], submenus: Record<string, IMenu>): IDisposable {
const disposables = new DisposableStore();
for (const action of actions) {

View file

@ -446,7 +446,7 @@ async function runAction(action: IAction): Promise<void> {
}
interface IExtensionActionOptions extends IAction2Options {
menuTitles?: { [id: number]: string };
menuTitles?: { [id: string]: string };
run(accessor: ServicesAccessor, ...args: any[]): Promise<any>;
}

View file

@ -729,7 +729,7 @@ submenusExtensionPoint.setHandler(extensions => {
const _apiMenusByKey = new Map(Iterable.map(Iterable.from(apiMenus), menu => ([menu.key, menu])));
const _menuRegistrations = new DisposableStore();
const _submenuMenuItems = new Map<number /* menu id */, Set<number /* submenu id */>>();
const _submenuMenuItems = new Map<string /* menu id */, Set<string /* submenu id */>>();
const menusExtensionPoint = ExtensionsRegistry.registerExtensionPoint<{ [loc: string]: (schema.IUserFriendlyMenuItem | schema.IUserFriendlySubmenuItem)[] }>({
extensionPoint: 'menus',