Skip to content

Commit 9e5b12a

Browse files
committed
debt - use const enum for MenuId
1 parent f7f121b commit 9e5b12a

3 files changed

Lines changed: 45 additions & 50 deletions

File tree

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

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -58,49 +58,44 @@ export function isISubmenuItem(item: IMenuItem | ISubmenuItem): item is ISubmenu
5858
return (item as ISubmenuItem).submenu !== undefined;
5959
}
6060

61-
export class MenuId {
62-
63-
private static ID = 1;
64-
65-
static readonly EditorTitle = new MenuId();
66-
static readonly EditorTitleContext = new MenuId();
67-
static readonly EditorContext = new MenuId();
68-
static readonly EmptyEditorGroupContext = new MenuId();
69-
static readonly ExplorerContext = new MenuId();
70-
static readonly OpenEditorsContext = new MenuId();
71-
static readonly ProblemsPanelContext = new MenuId();
72-
static readonly DebugVariablesContext = new MenuId();
73-
static readonly DebugWatchContext = new MenuId();
74-
static readonly DebugCallStackContext = new MenuId();
75-
static readonly DebugBreakpointsContext = new MenuId();
76-
static readonly DebugConsoleContext = new MenuId();
77-
static readonly SCMTitle = new MenuId();
78-
static readonly SCMSourceControl = new MenuId();
79-
static readonly SCMResourceGroupContext = new MenuId();
80-
static readonly SCMResourceContext = new MenuId();
81-
static readonly SCMChangeContext = new MenuId();
82-
static readonly CommandPalette = new MenuId();
83-
static readonly ViewTitle = new MenuId();
84-
static readonly ViewItemContext = new MenuId();
85-
static readonly TouchBarContext = new MenuId();
86-
static readonly SearchContext = new MenuId();
87-
static readonly MenubarFileMenu = new MenuId();
88-
static readonly MenubarEditMenu = new MenuId();
89-
static readonly MenubarRecentMenu = new MenuId();
90-
static readonly MenubarSelectionMenu = new MenuId();
91-
static readonly MenubarViewMenu = new MenuId();
92-
static readonly MenubarAppearanceMenu = new MenuId();
93-
static readonly MenubarLayoutMenu = new MenuId();
94-
static readonly MenubarGoMenu = new MenuId();
95-
static readonly MenubarSwitchEditorMenu = new MenuId();
96-
static readonly MenubarSwitchGroupMenu = new MenuId();
97-
static readonly MenubarDebugMenu = new MenuId();
98-
static readonly MenubarNewBreakpointMenu = new MenuId();
99-
static readonly MenubarPreferencesMenu = new MenuId();
100-
static readonly MenubarHelpMenu = new MenuId();
101-
static readonly MenubarTerminalMenu = new MenuId();
102-
103-
readonly id: string = String(MenuId.ID++);
61+
export const enum MenuId {
62+
EditorTitle,
63+
EditorTitleContext,
64+
EditorContext,
65+
EmptyEditorGroupContext,
66+
ExplorerContext,
67+
OpenEditorsContext,
68+
ProblemsPanelContext,
69+
DebugVariablesContext,
70+
DebugWatchContext,
71+
DebugCallStackContext,
72+
DebugBreakpointsContext,
73+
DebugConsoleContext,
74+
SCMTitle,
75+
SCMSourceControl,
76+
SCMResourceGroupContext,
77+
SCMResourceContext,
78+
SCMChangeContext,
79+
CommandPalette,
80+
ViewTitle,
81+
ViewItemContext,
82+
TouchBarContext,
83+
SearchContext,
84+
MenubarFileMenu,
85+
MenubarEditMenu,
86+
MenubarRecentMenu,
87+
MenubarSelectionMenu,
88+
MenubarViewMenu,
89+
MenubarAppearanceMenu,
90+
MenubarLayoutMenu,
91+
MenubarGoMenu,
92+
MenubarSwitchEditorMenu,
93+
MenubarSwitchGroupMenu,
94+
MenubarDebugMenu,
95+
MenubarNewBreakpointMenu,
96+
MenubarPreferencesMenu,
97+
MenubarHelpMenu,
98+
MenubarTerminalMenu,
10499
}
105100

106101
export interface IMenuActionOptions {
@@ -162,9 +157,9 @@ export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry {
162157
}
163158

164159
appendMenuItem(id: MenuId, item: IMenuItem | ISubmenuItem): IDisposable {
165-
let array = this._menuItems[id.id];
160+
let array = this._menuItems[id];
166161
if (!array) {
167-
this._menuItems[id.id] = array = [item];
162+
this._menuItems[id] = array = [item];
168163
} else {
169164
array.push(item);
170165
}
@@ -180,10 +175,10 @@ export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry {
180175
};
181176
}
182177

183-
getMenuItems({ id }: MenuId): (IMenuItem | ISubmenuItem)[] {
178+
getMenuItems(id: MenuId): (IMenuItem | ISubmenuItem)[] {
184179
const result = this._menuItems[id] || [];
185180

186-
if (id === MenuId.CommandPalette.id) {
181+
if (id === MenuId.CommandPalette) {
187182
// CommandPalette is special because it shows
188183
// all commands by default
189184
this._appendImplicitItems(result);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ suite('MenuService', function () {
2828

2929
setup(function () {
3030
menuService = new MenuService(NullCommandService);
31-
testMenuId = new MenuId();
31+
testMenuId = Math.PI;
3232
disposables = [];
3333
});
3434

src/vs/workbench/services/actions/electron-browser/menusExtensionPoint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace schema {
2424
group?: string;
2525
}
2626

27-
export function parseMenuId(value: string): MenuId {
27+
export function parseMenuId(value: string): MenuId | undefined {
2828
switch (value) {
2929
case 'commandPalette': return MenuId.CommandPalette;
3030
case 'touchBar': return MenuId.TouchBarContext;
@@ -326,7 +326,7 @@ ExtensionsRegistry.registerExtensionPoint<{ [loc: string]: schema.IUserFriendlyM
326326
}
327327

328328
const menu = schema.parseMenuId(entry.key);
329-
if (!menu) {
329+
if (typeof menu !== 'number') {
330330
collector.warn(localize('menuId.invalid', "`{0}` is not a valid menu identifier", entry.key));
331331
return;
332332
}

0 commit comments

Comments
 (0)