1 | import { Disposable } from '../disposable';
|
2 | export declare type MenuPath = string[];
|
3 | export declare const MAIN_MENU_BAR: MenuPath;
|
4 | export declare const SETTINGS_MENU: MenuPath;
|
5 | export declare const ACCOUNTS_MENU: MenuPath;
|
6 | export declare const ACCOUNTS_SUBMENU: string[];
|
7 | /**
|
8 | * @internal For most use cases, refer to {@link MenuAction} or {@link MenuNode}
|
9 | */
|
10 | export interface MenuNodeMetadata {
|
11 | /**
|
12 | * technical identifier.
|
13 | */
|
14 | readonly id: string;
|
15 | /**
|
16 | * Menu nodes are sorted in ascending order based on their `sortString`.
|
17 | */
|
18 | readonly sortString: string;
|
19 | /**
|
20 | * Condition under which the menu node should be rendered.
|
21 | * See https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts
|
22 | */
|
23 | readonly when?: string;
|
24 | /**
|
25 | * A reference to the parent node - useful for determining the menu path by which the node can be accessed.
|
26 | */
|
27 | readonly parent?: MenuNode;
|
28 | }
|
29 | /**
|
30 | * Metadata for the visual presentation of a node.
|
31 | * @internal For most uses cases, refer to {@link MenuNode}, {@link CommandMenuNode}, or {@link CompoundMenuNode}
|
32 | */
|
33 | export interface MenuNodeRenderingData {
|
34 | /**
|
35 | * Optional label. Will be rendered as text of the menu item.
|
36 | */
|
37 | readonly label?: string;
|
38 | /**
|
39 | * Icon classes for the menu node. If present, these will produce an icon to the left of the label in browser-style menus.
|
40 | */
|
41 | readonly icon?: string;
|
42 | }
|
43 | /** @internal For most use cases refer to {@link MenuNode}, {@link CommandMenuNode}, or {@link CompoundMenuNode} */
|
44 | export interface MenuNodeBase extends MenuNodeMetadata, MenuNodeRenderingData {
|
45 | }
|
46 | /**
|
47 | * A menu entry representing an action, e.g. "New File".
|
48 | */
|
49 | export interface MenuAction extends MenuNodeRenderingData, Pick<MenuNodeMetadata, 'when'> {
|
50 | /**
|
51 | * The command to execute.
|
52 | */
|
53 | commandId: string;
|
54 | /**
|
55 | * In addition to the mandatory command property, an alternative command can be defined.
|
56 | * It will be shown and invoked when pressing Alt while opening a menu.
|
57 | */
|
58 | alt?: string;
|
59 | /**
|
60 | * Menu entries are sorted in ascending order based on their `order` strings. If omitted the determined
|
61 | * label will be used instead.
|
62 | */
|
63 | order?: string;
|
64 | }
|
65 | export declare namespace MenuAction {
|
66 | function is(arg: unknown): arg is MenuAction;
|
67 | }
|
68 | /**
|
69 | * Additional options when creating a new submenu.
|
70 | */
|
71 | export interface SubMenuOptions extends Pick<MenuAction, 'order'>, Pick<MenuNodeMetadata, 'when'>, Partial<Pick<CompoundMenuNode, 'role' | 'label' | 'icon'>> {
|
72 | /**
|
73 | * The class to use for the submenu icon.
|
74 | * @deprecated use `icon` instead;
|
75 | */
|
76 | iconClass?: string;
|
77 | }
|
78 | export declare const enum CompoundMenuNodeRole {
|
79 | /** Indicates that the node should be rendered as submenu that opens a new menu on hover */
|
80 | Submenu = 0,
|
81 | /** Indicates that the node's children should be rendered as group separated from other items by a separator */
|
82 | Group = 1,
|
83 | /** Indicates that the node's children should be treated as though they were direct children of the node's parent */
|
84 | Flat = 2
|
85 | }
|
86 | export interface CompoundMenuNode extends MenuNodeBase {
|
87 | /**
|
88 | * Items that are grouped under this menu.
|
89 | */
|
90 | readonly children: ReadonlyArray<MenuNode>;
|
91 | /**
|
92 | * @deprecated @since 1.28 use `role` instead.
|
93 | * Whether the item should be rendered as a submenu.
|
94 | */
|
95 | readonly isSubmenu: boolean;
|
96 | /**
|
97 | * How the node and its children should be rendered. See {@link CompoundMenuNodeRole}.
|
98 | */
|
99 | readonly role: CompoundMenuNodeRole;
|
100 | }
|
101 | export interface MutableCompoundMenuNode extends CompoundMenuNode {
|
102 | /**
|
103 | * Inserts the given node at the position indicated by `sortString`.
|
104 | *
|
105 | * @returns a disposable which, when called, will remove the given node again.
|
106 | */
|
107 | addNode(node: MenuNode): Disposable;
|
108 | /**
|
109 | * Removes the first node with the given id.
|
110 | *
|
111 | * @param id node id.
|
112 | */
|
113 | removeNode(id: string): void;
|
114 | /**
|
115 | * Fills any `undefined` fields with the values from the {@link options}.
|
116 | */
|
117 | updateOptions(options: SubMenuOptions): void;
|
118 | }
|
119 | export declare namespace CompoundMenuNode {
|
120 | function is(node?: MenuNode): node is CompoundMenuNode;
|
121 | function getRole(node: MenuNode): CompoundMenuNodeRole | undefined;
|
122 | function sortChildren(m1: MenuNode, m2: MenuNode): number;
|
123 | /** Collapses the children of any subemenus with role {@link CompoundMenuNodeRole Flat} and sorts */
|
124 | function getFlatChildren(children: ReadonlyArray<MenuNode>): MenuNode[];
|
125 | /**
|
126 | * Indicates whether the given node is the special `navigation` menu.
|
127 | *
|
128 | * @param node the menu node to check.
|
129 | * @returns `true` when the given node is a {@link CompoundMenuNode} with id `navigation`,
|
130 | * `false` otherwise.
|
131 | */
|
132 | function isNavigationGroup(node: MenuNode): node is CompoundMenuNode;
|
133 | function isMutable(node?: MenuNode): node is MutableCompoundMenuNode;
|
134 | }
|
135 | export interface CommandMenuNode extends MenuNodeBase {
|
136 | command: string;
|
137 | }
|
138 | export declare namespace CommandMenuNode {
|
139 | function is(candidate?: MenuNode): candidate is CommandMenuNode;
|
140 | function hasAltHandler(candidate?: MenuNode): candidate is AlternativeHandlerMenuNode;
|
141 | }
|
142 | export interface AlternativeHandlerMenuNode extends CommandMenuNode {
|
143 | altNode: CommandMenuNode;
|
144 | }
|
145 | /**
|
146 | * Base interface of the nodes used in the menu tree structure.
|
147 | */
|
148 | export declare type MenuNode = MenuNodeMetadata & MenuNodeRenderingData & Partial<CompoundMenuNode> & Partial<CommandMenuNode> & Partial<AlternativeHandlerMenuNode>;
|
149 | //# sourceMappingURL=menu-types.d.ts.map |
\ | No newline at end of file |