Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/browser/parts/views/viewMenuActions.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
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 { IAction } from '../../../../base/common/actions.js';
7
import { Emitter, Event } from '../../../../base/common/event.js';
8
import { Disposable } from '../../../../base/common/lifecycle.js';
9
import { getActionBarActions, PrimaryAndSecondaryActions } from '../../../../platform/actions/browser/menuEntryActionViewItem.js';
10
import { MenuId, IMenuActionOptions, IMenuService, IMenu } from '../../../../platform/actions/common/actions.js';
11
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
12
import { IViewDescriptorService, ViewContainer, ViewContainerLocationToString } from '../../../common/views.js';
13
14
export class ViewMenuActions extends Disposable {
15
16
private readonly menu: IMenu;
17
18
private readonly _onDidChange = this._register(new Emitter<void>());
19
readonly onDidChange = this._onDidChange.event;
20
21
constructor(
22
readonly menuId: MenuId,
23
private readonly contextMenuId: MenuId | undefined,
24
private readonly options: IMenuActionOptions | undefined,
25
@IContextKeyService private readonly contextKeyService: IContextKeyService,
26
@IMenuService private readonly menuService: IMenuService,
27
) {
28
super();
29
this.menu = this._register(menuService.createMenu(menuId, contextKeyService, { emitEventsForSubmenuChanges: true }));
30
this._register(this.menu.onDidChange(() => {
31
this.actions = undefined;
32
this._onDidChange.fire();
33
}));
34
}
35
36
private actions: PrimaryAndSecondaryActions | undefined;
37
private getActions(): PrimaryAndSecondaryActions {
38
if (!this.actions) {
39
this.actions = getActionBarActions(this.menu.getActions(this.options));
40
}
41
return this.actions;
42
}
43
44
getPrimaryActions(): IAction[] {
45
return this.getActions().primary;
46
}
47
48
getSecondaryActions(): IAction[] {
49
return this.getActions().secondary;
50
}
51
52
getContextMenuActions(): IAction[] {
53
if (this.contextMenuId) {
54
const menu = this.menuService.getMenuActions(this.contextMenuId, this.contextKeyService, this.options);
55
return getActionBarActions(menu).secondary;
56
}
57
return [];
58
}
59
}
60
61
export class ViewContainerMenuActions extends ViewMenuActions {
62
constructor(
63
element: HTMLElement,
64
viewContainer: ViewContainer,
65
@IViewDescriptorService viewDescriptorService: IViewDescriptorService,
66
@IContextKeyService contextKeyService: IContextKeyService,
67
@IMenuService menuService: IMenuService,
68
) {
69
const scopedContextKeyService = contextKeyService.createScoped(element);
70
scopedContextKeyService.createKey('viewContainer', viewContainer.id);
71
const viewContainerLocationKey = scopedContextKeyService.createKey('viewContainerLocation', ViewContainerLocationToString(viewDescriptorService.getViewContainerLocation(viewContainer)!));
72
super(MenuId.ViewContainerTitle, MenuId.ViewContainerTitleContext, { shouldForwardArgs: true, renderShortTitle: true }, scopedContextKeyService, menuService);
73
this._register(scopedContextKeyService);
74
this._register(Event.filter(viewDescriptorService.onDidChangeContainerLocation, e => e.viewContainer === viewContainer)(() => viewContainerLocationKey.set(ViewContainerLocationToString(viewDescriptorService.getViewContainerLocation(viewContainer)!))));
75
}
76
}
77
78