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);