Skip to content

Commit 21147b8

Browse files
committed
make MenuId#id a string and a strict identifier
1 parent 9457eb4 commit 21147b8

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

src/vs/platform/actions/browser/menuEntryActionViewItem.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ export class MenuEntryActionViewItem extends ActionViewItem {
141141
@IKeybindingService protected readonly _keybindingService: IKeybindingService,
142142
@INotificationService protected _notificationService: INotificationService,
143143
@IContextKeyService protected _contextKeyService: IContextKeyService,
144-
@IThemeService protected _themeService: IThemeService
144+
@IThemeService protected _themeService: IThemeService,
145+
@IContextMenuService protected _contextMenuService: IContextMenuService
145146
) {
146147
super(undefined, action, { icon: !!(action.class || action.item.icon), label: !action.class && !action.item.icon, draggable: options?.draggable, keybinding: options?.keybinding, hoverDelegate: options?.hoverDelegate });
147148
this._altKey = ModifierKeyEmitter.getInstance();
@@ -202,6 +203,17 @@ export class MenuEntryActionViewItem extends ActionViewItem {
202203
mouseOver = true;
203204
updateAltState();
204205
}));
206+
207+
208+
this._register(addDisposableListener(container, 'contextmenu', event => {
209+
event.preventDefault();
210+
event.stopPropagation();
211+
212+
this._contextMenuService.showContextMenu({
213+
getAnchor: () => container,
214+
getActions: () => this._menuItemAction.hideActions.asList()
215+
});
216+
}, true));
205217
}
206218

207219
override updateLabel(): void {
@@ -356,7 +368,7 @@ export class DropdownWithDefaultActionViewItem extends BaseActionViewItem {
356368
) {
357369
super(null, submenuAction);
358370
this._options = options;
359-
this._storageKey = `${submenuAction.item.submenu._debugName}_lastActionId`;
371+
this._storageKey = `${submenuAction.item.submenu.id}_lastActionId`;
360372

361373
// determine default action
362374
let defaultAction: IAction | undefined;

src/vs/platform/actions/common/actions.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function isISubmenuItem(item: IMenuItem | ISubmenuItem): item is ISubmenu
4545

4646
export class MenuId {
4747

48-
private static _idPool = 0;
48+
private static readonly _idPool = new Set<string>();
4949

5050
static readonly CommandPalette = new MenuId('CommandPalette');
5151
static readonly DebugBreakpointsContext = new MenuId('DebugBreakpointsContext');
@@ -162,12 +162,15 @@ export class MenuId {
162162
static readonly NewFile = new MenuId('NewFile');
163163
static readonly MergeToolbar = new MenuId('MergeToolbar');
164164

165-
readonly id: number;
166-
readonly _debugName: string;
167165

168-
constructor(debugName: string) {
169-
this.id = MenuId._idPool++;
170-
this._debugName = debugName;
166+
readonly id: string;
167+
168+
constructor(identifier: string) {
169+
if (MenuId._idPool.has(identifier)) {
170+
throw new Error(`Duplicate menu identifier ${identifier}`);
171+
}
172+
MenuId._idPool.add(identifier);
173+
this.id = identifier;
171174
}
172175
}
173176

src/vs/workbench/browser/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class MenuActions extends Disposable {
4848
this._onDidChange.fire();
4949
}
5050

51-
private updateSubmenus(actions: readonly IAction[], submenus: { [id: number]: IMenu }): IDisposable {
51+
private updateSubmenus(actions: readonly IAction[], submenus: Record<string, IMenu>): IDisposable {
5252
const disposables = new DisposableStore();
5353

5454
for (const action of actions) {

src/vs/workbench/contrib/extensions/browser/extensions.contribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ async function runAction(action: IAction): Promise<void> {
446446
}
447447

448448
interface IExtensionActionOptions extends IAction2Options {
449-
menuTitles?: { [id: number]: string };
449+
menuTitles?: { [id: string]: string };
450450
run(accessor: ServicesAccessor, ...args: any[]): Promise<any>;
451451
}
452452

src/vs/workbench/services/actions/common/menusExtensionPoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ submenusExtensionPoint.setHandler(extensions => {
729729

730730
const _apiMenusByKey = new Map(Iterable.map(Iterable.from(apiMenus), menu => ([menu.key, menu])));
731731
const _menuRegistrations = new DisposableStore();
732-
const _submenuMenuItems = new Map<number /* menu id */, Set<number /* submenu id */>>();
732+
const _submenuMenuItems = new Map<string /* menu id */, Set<string /* submenu id */>>();
733733

734734
const menusExtensionPoint = ExtensionsRegistry.registerExtensionPoint<{ [loc: string]: (schema.IUserFriendlyMenuItem | schema.IUserFriendlySubmenuItem)[] }>({
735735
extensionPoint: 'menus',

0 commit comments

Comments
 (0)