Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/browser/contextmenu.ts
3292 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 { StandardMouseEvent } from './mouseEvent.js';
7
import { IActionViewItemOptions } from './ui/actionbar/actionViewItems.js';
8
import { IActionViewItem } from './ui/actionbar/actionbar.js';
9
import { AnchorAlignment, AnchorAxisAlignment, IAnchor } from './ui/contextview/contextview.js';
10
import { IAction, IActionRunner } from '../common/actions.js';
11
import { ResolvedKeybinding } from '../common/keybindings.js';
12
import { OmitOptional } from '../common/types.js';
13
14
export interface IContextMenuEvent {
15
readonly shiftKey?: boolean;
16
readonly ctrlKey?: boolean;
17
readonly altKey?: boolean;
18
readonly metaKey?: boolean;
19
}
20
21
/**
22
* A specific context menu location to position the menu at.
23
* Uses some TypeScript type tricks to prevent allowing to
24
* pass in a `MouseEvent` and force people to use `StandardMouseEvent`.
25
*/
26
type ContextMenuLocation = OmitOptional<IAnchor> & { getModifierState?: never };
27
28
export interface IContextMenuDelegate {
29
/**
30
* The anchor where to position the context view.
31
* Use a `HTMLElement` to position the view at the element,
32
* a `StandardMouseEvent` to position it at the mouse position
33
* or an `ContextMenuLocation` to position it at a specific location.
34
*/
35
getAnchor(): HTMLElement | StandardMouseEvent | ContextMenuLocation;
36
getActions(): readonly IAction[];
37
getCheckedActionsRepresentation?(action: IAction): 'radio' | 'checkbox';
38
getActionViewItem?(action: IAction, options: IActionViewItemOptions): IActionViewItem | undefined;
39
getActionsContext?(event?: IContextMenuEvent): unknown;
40
getKeyBinding?(action: IAction): ResolvedKeybinding | undefined;
41
getMenuClassName?(): string;
42
onHide?(didCancel: boolean): void;
43
actionRunner?: IActionRunner;
44
skipTelemetry?: boolean;
45
autoSelectFirstItem?: boolean;
46
anchorAlignment?: AnchorAlignment;
47
anchorAxisAlignment?: AnchorAxisAlignment;
48
domForShadowRoot?: HTMLElement;
49
/**
50
* custom context menus with higher layers are rendered higher in z-index order
51
*/
52
layer?: number;
53
}
54
55
export interface IContextMenuProvider {
56
showContextMenu(delegate: IContextMenuDelegate): void;
57
}
58
59