Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/contextview/browser/contextView.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 { IContextMenuDelegate } from '../../../base/browser/contextmenu.js';
7
import { StandardMouseEvent } from '../../../base/browser/mouseEvent.js';
8
import { AnchorAlignment, AnchorAxisAlignment, IAnchor, IContextViewProvider } from '../../../base/browser/ui/contextview/contextview.js';
9
import { IAction } from '../../../base/common/actions.js';
10
import { Event } from '../../../base/common/event.js';
11
import { IDisposable } from '../../../base/common/lifecycle.js';
12
import { IMenuActionOptions, MenuId } from '../../actions/common/actions.js';
13
import { IContextKeyService } from '../../contextkey/common/contextkey.js';
14
import { createDecorator } from '../../instantiation/common/instantiation.js';
15
16
export const IContextViewService = createDecorator<IContextViewService>('contextViewService');
17
18
export interface IContextViewService extends IContextViewProvider {
19
20
readonly _serviceBrand: undefined;
21
22
showContextView(delegate: IContextViewDelegate, container?: HTMLElement, shadowRoot?: boolean): IOpenContextView;
23
hideContextView(data?: any): void;
24
getContextViewElement(): HTMLElement;
25
layout(): void;
26
anchorAlignment?: AnchorAlignment;
27
}
28
29
export interface IContextViewDelegate {
30
31
canRelayout?: boolean; // Default: true
32
33
/**
34
* The anchor where to position the context view.
35
* Use a `HTMLElement` to position the view at the element,
36
* a `StandardMouseEvent` to position it at the mouse position
37
* or an `IAnchor` to position it at a specific location.
38
*/
39
getAnchor(): HTMLElement | StandardMouseEvent | IAnchor;
40
render(container: HTMLElement): IDisposable;
41
onDOMEvent?(e: any, activeElement: HTMLElement): void;
42
onHide?(data?: any): void;
43
focus?(): void;
44
anchorAlignment?: AnchorAlignment;
45
anchorAxisAlignment?: AnchorAxisAlignment;
46
47
// context views with higher layers are rendered over contet views with lower layers
48
layer?: number; // Default: 0
49
}
50
51
export interface IOpenContextView {
52
close: () => void;
53
}
54
55
export const IContextMenuService = createDecorator<IContextMenuService>('contextMenuService');
56
57
export interface IContextMenuService {
58
59
readonly _serviceBrand: undefined;
60
61
readonly onDidShowContextMenu: Event<void>;
62
readonly onDidHideContextMenu: Event<void>;
63
64
showContextMenu(delegate: IContextMenuDelegate | IContextMenuMenuDelegate): void;
65
}
66
67
export type IContextMenuMenuDelegate = {
68
/**
69
* The MenuId that should be used to populate the context menu.
70
*/
71
menuId?: MenuId;
72
/**
73
* Optional options how menu actions are invoked
74
*/
75
menuActionOptions?: IMenuActionOptions;
76
/**
77
* Optional context key service which drives the given menu
78
*/
79
contextKeyService?: IContextKeyService;
80
81
/**
82
* Optional getter for extra actions. They will be prepended to the menu actions.
83
*/
84
getActions?(): IAction[];
85
} & Omit<IContextMenuDelegate, 'getActions'>;
86
87