menuService.ts ×32

Frontier kind: Code frontier

unlabeled · c_708c42a358f2

6 tests · 16030 LOC · 70 files · introduces 0 tests · 156 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
35 ranges156 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2012 ranges16030 lines · 70 files · Browse complete extent
All tests (intent)
6 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

3 files ranked by introduced lines: 156 introduced LOC across 35 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/actions/common/menuService.ts 139 introduced LOC · 32 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- menuService.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { RunOnceScheduler } from '../../../base/common/async.js';
7 > import { DebounceEmitter, Emitter, Event } from '../../../base/common/event.js';
8 > import { DisposableStore, Disposable, IDisposable } from '../../../base/common/lifecycle.js';
9 > import { IMenu, IMenuActionOptions, IMenuChangeEvent, IMenuCreateOptions, IMenuItem, IMenuItemHide, IMenuService, isIMenuItem, isISubmenuItem, ISubmenuItem, MenuId, MenuItemAction, MenuRegistry, SubmenuItemAction } from './actions.js';
10 > import { ICommandAction, ILocalizedString } from '../../action/common/action.js';
11 > import { ICommandService } from '../../commands/common/commands.js';
12 > import { ContextKeyExpression, IContextKeyService } from '../../contextkey/common/contextkey.js';
13 > import { IAction, Separator, toAction } from '../../../base/common/actions.js';
14 > import { IStorageService, StorageScope, StorageTarget } from '../../storage/common/storage.js';
15 > import { removeFastWithoutKeepingOrder } from '../../../base/common/arrays.js';
16 > import { localize } from '../../../nls.js';
17 > import { IKeybindingService } from '../../keybinding/common/keybinding.js';
18 >
19 > export class MenuService extends Disposable implements IMenuService {
20 >
21 > declare readonly _serviceBrand: undefined;
22 >
23 > private readonly _hiddenStates: PersistedMenuHideState;
24 >
25 > constructor(
26 > @ICommandService private readonly _commandService: ICommandService,
27 > @IKeybindingService private readonly _keybindingService: IKeybindingService,
28 > @IStorageService storageService: IStorageService,
29 > ) {
30 > super();
31 > this._hiddenStates = this._register(new PersistedMenuHideState(storageService));
32 > }
33 >
34 > createMenu(id: MenuId, contextKeyService: IContextKeyService, options?: IMenuCreateOptions): IMenu {
35 return new MenuImpl(id, this._hiddenStates, { emitEventsForSubmenuChanges: false, eventDebounceDelay: 50, ...options }, this._commandService, this._keybindingService, contextKeyService);
36 }
38 > getMenuActions(id: MenuId, contextKeyService: IContextKeyService, options?: IMenuActionOptions): [string, Array<MenuItemAction | SubmenuItemAction>][] {
39 const menu = new MenuImpl(id, this._hiddenStates, { emitEventsForSubmenuChanges: false, eventDebounceDelay: 50, ...options }, this._commandService, this._keybindingService, contextKeyService);
40 const actions = menu.getActions(options);
42 return actions;
43 }
45 > getMenuContexts(id: MenuId): ReadonlySet<string> {
46 const menuInfo = new MenuInfoSnapshot(id, false);
47 return new Set<string>([...menuInfo.structureContextKeys, ...menuInfo.preconditionContextKeys, ...menuInfo.toggledContextKeys]);
48 }
50 > resetHiddenStates(ids?: MenuId[]): void {
51 this._hiddenStates.reset(ids);
52 }
54 >
55 > class PersistedMenuHideState implements IDisposable {
56 >
57 > private static readonly _key = 'menu.hiddenCommands';
58 >
59 > private readonly _disposables = new DisposableStore();
60 > private readonly _onDidChange = new Emitter<void>();
61 > readonly onDidChange: Event<void> = this._onDidChange.event;
62 >
63 > private _ignoreChangeEvent: boolean = false;
64 > private _data: Record<string, string[] | undefined>;
65 >
66 > private _hiddenByDefaultCache = new Map<string, boolean>();
67 >
68 > constructor(@IStorageService private readonly _storageService: IStorageService) {
69 > try {
70 > const raw = _storageService.get(PersistedMenuHideState._key, StorageScope.PROFILE, '{}');
71 > this._data = JSON.parse(raw);
72 > } catch (err) {
73 this._data = Object.create(null);
74 }
76 > this._disposables.add(_storageService.onDidChangeValue(StorageScope.PROFILE, PersistedMenuHideState._key, this._disposables)(() => {
77 if (!this._ignoreChangeEvent) {
78 try {
84 }
85 this._onDidChange.fire();
86 > })); menuService.ts
87 > }
88 >
89 > dispose() {
90 this._onDidChange.dispose();
91 this._disposables.dispose();
92 }
94 > private _isHiddenByDefault(menu: MenuId, commandId: string) {
95 return this._hiddenByDefaultCache.get(`${menu.id}/${commandId}`) ?? false;
96 }
98 > setDefaultState(menu: MenuId, commandId: string, hidden: boolean): void {
99 this._hiddenByDefaultCache.set(`${menu.id}/${commandId}`, hidden);
100 }
102 > isHidden(menu: MenuId, commandId: string): boolean {
103 const hiddenByDefault = this._isHiddenByDefault(menu, commandId);
104 const state = this._data[menu.id]?.includes(commandId) ?? false;
105 return hiddenByDefault ? !state : state;
106 }
108 > updateHidden(menu: MenuId, commandId: string, hidden: boolean): void {
109 const hiddenByDefault = this._isHiddenByDefault(menu, commandId);
110 if (hiddenByDefault) {
136 this._persist();
137 }
139 > reset(menus?: MenuId[]): void {
140 if (menus === undefined) {
141 // reset all
152 }
153 }
155 > private _persist(): void {
156 try {
157 this._ignoreChangeEvent = true;
162 }
163 }
164 > } menuService.ts
165 >
166 > type MenuItemGroup = [string, Array<IMenuItem | ISubmenuItem>];
167 >
168 > class MenuInfoSnapshot {
169 > protected _menuGroups: MenuItemGroup[] = [];
170 > private _allMenuIds: Set<MenuId> = new Set();
171 > private _structureContextKeys: Set<string> = new Set();
172 > private _preconditionContextKeys: Set<string> = new Set();
173 > private _toggledContextKeys: Set<string> = new Set();
174 >
175 > constructor(
176 protected readonly _id: MenuId,
177 protected readonly _collectContextKeysForSubmenus: boolean,
179 this.refresh();
180 }
182 > get allMenuIds(): ReadonlySet<MenuId> {
183 return this._allMenuIds;
184 }
186 > get structureContextKeys(): ReadonlySet<string> {
187 return this._structureContextKeys;
188 }
190 > get preconditionContextKeys(): ReadonlySet<string> {
191 return this._preconditionContextKeys;
192 }
194 > get toggledContextKeys(): ReadonlySet<string> {
195 return this._toggledContextKeys;
196 }
198 > refresh(): void {
199
200 // reset
222 this._allMenuIds.add(this._id);
223 }
225 > protected _sort(menuItems: (IMenuItem | ISubmenuItem)[]) {
226 // no sorting needed in snapshot
227 return menuItems;
228 }
230 > private _collectContextKeysAndSubmenuIds(item: IMenuItem | ISubmenuItem): void {
231
232 MenuInfoSnapshot._fillInKbExprKeys(item.when, this._structureContextKeys);
251 }
252 }
254 > private static _fillInKbExprKeys(exp: ContextKeyExpression | undefined, set: Set<string>): void {
255 if (exp) {
256 for (const key of exp.keys()) {
259 }
260 }
262 > }
263 >
264 > class MenuInfo extends MenuInfoSnapshot {
265 >
266 > constructor(
267 _id: MenuId,
268 private readonly _hiddenStates: PersistedMenuHideState,
275 this.refresh();
276 }
278 > createActionGroups(options: IMenuActionOptions | undefined): [string, Array<MenuItemAction | SubmenuItemAction>][] {
279 const result: [string, Array<MenuItemAction | SubmenuItemAction>][] = [];
280
311 return result;
312 }
314 > protected override _sort(menuItems: (IMenuItem | ISubmenuItem)[]): (IMenuItem | ISubmenuItem)[] {
315 return menuItems.sort(MenuInfo._compareMenuItems);
316 }
318 > private static _compareMenuItems(a: IMenuItem | ISubmenuItem, b: IMenuItem | ISubmenuItem): number {
319
320 const aGroup = a.group;
359 );
360 }
362 > private static _compareTitles(a: string | ILocalizedString, b: string | ILocalizedString) {
363 const aStr = typeof a === 'string' ? a : a.original;
364 const bStr = typeof b === 'string' ? b : b.original;
365 return aStr.localeCompare(bStr);
366 }
367 > } menuService.ts
368 >
369 > class MenuImpl implements IMenu {
370 >
371 > private readonly _menuInfo: MenuInfo;
372 > private readonly _disposables = new DisposableStore();
373 >
374 > private readonly _onDidChange: Emitter<IMenuChangeEvent>;
375 > readonly onDidChange: Event<IMenuChangeEvent>;
376 >
377 > constructor(
378 id: MenuId,
379 hiddenStates: PersistedMenuHideState,
450 this.onDidChange = this._onDidChange.event;
451 }
453 > getActions(options?: IMenuActionOptions | undefined): [string, (MenuItemAction | SubmenuItemAction)[]][] {
454 return this._menuInfo.createActionGroups(options);
455 }
457 > dispose(): void {
458 this._disposables.dispose();
459 this._onDidChange.dispose();
460 }
461 > } menuService.ts
462 >
463 function createMenuHide(menu: MenuId, command: ICommandAction | ISubmenuItem, states: PersistedMenuHideState): IMenuItemHide {
464
485 };
486 }
488 > export function createConfigureKeybindingAction(commandService: ICommandService, keybindingService: IKeybindingService, commandId: string, when: ContextKeyExpression | undefined = undefined, enabled = true): IAction {
489 return toAction({
490 id: `configureKeybinding/${commandId}`,
src/vs/platform/commands/test/common/nullCommandService.ts 14 introduced LOC · 2 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- nullCommandService.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { Disposable } from '../../../../base/common/lifecycle.js';
7 > import { ICommandService } from '../../common/commands.js';
8 >
9 > export const NullCommandService: ICommandService = {
10 > _serviceBrand: undefined,
11 > onWillExecuteCommand: () => Disposable.None,
12 > onDidExecuteCommand: () => Disposable.None,
13 > executeCommand() {
14 return Promise.resolve(undefined);
15 }
src/vs/platform/keybinding/test/common/mockKeybindingService.ts 3 introduced LOC · 1 range

Open complete file

86
87 export class MockKeybindingService implements IKeybindingService {
88 > public _serviceBrand: undefined; mockKeybindingService.ts
89 >
90 > public readonly inChordMode: boolean = false;
91
92 public get onDidUpdateKeybindings(): Event<void> {