actions.ts ×20

Frontier kind: Code frontier

unlabeled · c_259a4c6dc75c

184 tests · 15166 LOC · 61 files · introduces 0 tests · 696 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
29 ranges696 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1843 ranges15166 lines · 61 files · Browse complete extent
All tests (intent)
184 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 696 introduced LOC across 29 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/actions/common/actions.ts 569 introduced LOC · 20 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- actions.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 { IAction, SubmenuAction } from '../../../base/common/actions.js';
7 > import { Event, MicrotaskEmitter } from '../../../base/common/event.js';
8 > import { DisposableStore, dispose, IDisposable, markAsSingleton, toDisposable } from '../../../base/common/lifecycle.js';
9 > import { LinkedList } from '../../../base/common/linkedList.js';
10 > import { ThemeIcon } from '../../../base/common/themables.js';
11 > import { ICommandAction, ICommandActionTitle, Icon, ILocalizedString } from '../../action/common/action.js';
12 > import { Categories } from '../../action/common/actionCommonCategories.js';
13 > import { CommandsRegistry, ICommandService } from '../../commands/common/commands.js';
14 > import { ContextKeyExpr, ContextKeyExpression, IContextKeyService } from '../../contextkey/common/contextkey.js';
15 > import { createDecorator, ServicesAccessor } from '../../instantiation/common/instantiation.js';
16 > import { IKeybindingRule, KeybindingsRegistry } from '../../keybinding/common/keybindingsRegistry.js';
17 >
18 > export interface IMenuItem {
19 > command: ICommandAction;
20 > alt?: ICommandAction;
21 > /**
22 > * Menu item is hidden if this expression returns false.
23 > */
24 > when?: ContextKeyExpression;
25 > group?: 'navigation' | string;
26 > order?: number;
27 > isHiddenByDefault?: boolean;
28 > }
29 >
30 > export interface ISubmenuItem {
31 > title: string | ICommandActionTitle;
32 > submenu: MenuId;
33 > icon?: Icon;
34 > when?: ContextKeyExpression;
35 > group?: 'navigation' | string;
36 > order?: number;
37 > isSelection?: boolean;
38 > /**
39 > * A split button shows the first action
40 > * as primary action and the rest of the
41 > * actions in a dropdown.
42 > *
43 > * Use `togglePrimaryAction` to promote
44 > * the action that was last used to be
45 > * the primary action and remember that
46 > * choice.
47 > */
48 > isSplitButton?: boolean | {
49 > /**
50 > * Will update the primary action based
51 > * on the action that was last run.
52 > */
53 > togglePrimaryAction: true;
54 > };
55 > }
56 >
57 > export function isIMenuItem(item: unknown): item is IMenuItem {
58 return (item as IMenuItem).command !== undefined;
59 }
60 > actions.ts
61 > export function isISubmenuItem(item: unknown): item is ISubmenuItem {
62 return (item as ISubmenuItem).submenu !== undefined;
63 }
64 > actions.ts
65 > export class MenuId {
66 >
67 > private static readonly _instances = new Map<string, MenuId>();
68 >
69 > static readonly CommandPalette = new MenuId('CommandPalette');
70 > static readonly DebugBreakpointsContext = new MenuId('DebugBreakpointsContext');
71 > static readonly DebugCallStackContext = new MenuId('DebugCallStackContext');
72 > static readonly DebugConsoleContext = new MenuId('DebugConsoleContext');
73 > static readonly DebugVariablesContext = new MenuId('DebugVariablesContext');
74 > static readonly NotebookVariablesContext = new MenuId('NotebookVariablesContext');
75 > static readonly DebugHoverContext = new MenuId('DebugHoverContext');
76 > static readonly DebugWatchContext = new MenuId('DebugWatchContext');
77 > static readonly DebugToolBar = new MenuId('DebugToolBar');
78 > static readonly DebugToolBarStop = new MenuId('DebugToolBarStop');
79 > static readonly DebugDisassemblyContext = new MenuId('DebugDisassemblyContext');
80 > static readonly DebugCallStackToolbar = new MenuId('DebugCallStackToolbar');
81 > static readonly DebugCreateConfiguration = new MenuId('DebugCreateConfiguration');
82 > static readonly DebugScopesContext = new MenuId('DebugScopesContext');
83 > static readonly EditorContext = new MenuId('EditorContext');
84 > static readonly SimpleEditorContext = new MenuId('SimpleEditorContext');
85 > static readonly EditorContent = new MenuId('EditorContent');
86 > static readonly EditorLineNumberContext = new MenuId('EditorLineNumberContext');
87 > static readonly EditorContextCopy = new MenuId('EditorContextCopy');
88 > static readonly EditorContextPeek = new MenuId('EditorContextPeek');
89 > static readonly EditorContextShare = new MenuId('EditorContextShare');
90 > static readonly EditorTitle = new MenuId('EditorTitle');
91 > static readonly EditorTitleLayout = new MenuId('EditorTitleLayout');
92 > static readonly ModalEditorTitle = new MenuId('ModalEditorTitle');
93 > static readonly ModalEditorTitleContext = new MenuId('ModalEditorTitleContext');
94 > static readonly ModalEditorEditorTitle = new MenuId('ModalEditorEditorTitle');
95 > static readonly CompactWindowEditorTitle = new MenuId('CompactWindowEditorTitle');
96 > static readonly EditorTitleRun = new MenuId('EditorTitleRun');
97 > static readonly EditorTitleContext = new MenuId('EditorTitleContext');
98 > static readonly EditorTitleContextShare = new MenuId('EditorTitleContextShare');
99 > static readonly EmptyEditorGroup = new MenuId('EmptyEditorGroup');
100 > static readonly EmptyEditorGroupContext = new MenuId('EmptyEditorGroupContext');
101 > static readonly EditorGroupWatermarkToolbar = new MenuId('EditorGroupWatermarkToolbar');
102 > static readonly EditorTabsBarContext = new MenuId('EditorTabsBarContext');
103 > static readonly EditorTabsBarShowTabsSubmenu = new MenuId('EditorTabsBarShowTabsSubmenu');
104 > static readonly EditorTabsBarShowTabsZenModeSubmenu = new MenuId('EditorTabsBarShowTabsZenModeSubmenu');
105 > static readonly EditorActionsPositionSubmenu = new MenuId('EditorActionsPositionSubmenu');
106 > static readonly EditorRenderWhitespaceSubmenu = new MenuId('EditorRenderWhitespaceSubmenu');
107 > static readonly EditorSplitMoveSubmenu = new MenuId('EditorSplitMoveSubmenu');
108 > static readonly ExplorerContext = new MenuId('ExplorerContext');
109 > static readonly ExplorerContextShare = new MenuId('ExplorerContextShare');
110 > static readonly ExtensionContext = new MenuId('ExtensionContext');
111 > static readonly ExtensionEditorContextMenu = new MenuId('ExtensionEditorContextMenu');
112 > static readonly GlobalActivity = new MenuId('GlobalActivity');
113 > static readonly CommandCenter = new MenuId('CommandCenter');
114 > static readonly CommandCenterCenter = new MenuId('CommandCenterCenter');
115 > static readonly LayoutControlMenuSubmenu = new MenuId('LayoutControlMenuSubmenu');
116 > static readonly LayoutControlMenu = new MenuId('LayoutControlMenu');
117 > static readonly MenubarMainMenu = new MenuId('MenubarMainMenu');
118 > static readonly MenubarAppearanceMenu = new MenuId('MenubarAppearanceMenu');
119 > static readonly MenubarDebugMenu = new MenuId('MenubarDebugMenu');
120 > static readonly MenubarEditMenu = new MenuId('MenubarEditMenu');
121 > static readonly MenubarCopy = new MenuId('MenubarCopy');
122 > static readonly MenubarFileMenu = new MenuId('MenubarFileMenu');
123 > static readonly MenubarGoMenu = new MenuId('MenubarGoMenu');
124 > static readonly MenubarHelpMenu = new MenuId('MenubarHelpMenu');
125 > static readonly MenubarLayoutMenu = new MenuId('MenubarLayoutMenu');
126 > static readonly MenubarNewBreakpointMenu = new MenuId('MenubarNewBreakpointMenu');
127 > static readonly PanelAlignmentMenu = new MenuId('PanelAlignmentMenu');
128 > static readonly PanelPositionMenu = new MenuId('PanelPositionMenu');
129 > static readonly ActivityBarPositionMenu = new MenuId('ActivityBarPositionMenu');
130 > static readonly NotificationsCenterPositionMenu = new MenuId('NotificationsCenterPositionMenu');
131 > static readonly MenubarPreferencesMenu = new MenuId('MenubarPreferencesMenu');
132 > static readonly MenubarRecentMenu = new MenuId('MenubarRecentMenu');
133 > static readonly MenubarSelectionMenu = new MenuId('MenubarSelectionMenu');
134 > static readonly MenubarShare = new MenuId('MenubarShare');
135 > static readonly MenubarSwitchEditorMenu = new MenuId('MenubarSwitchEditorMenu');
136 > static readonly MenubarSwitchGroupMenu = new MenuId('MenubarSwitchGroupMenu');
137 > static readonly MenubarTerminalMenu = new MenuId('MenubarTerminalMenu');
138 > static readonly MenubarTerminalSuggestStatusMenu = new MenuId('MenubarTerminalSuggestStatusMenu');
139 > static readonly MenubarViewMenu = new MenuId('MenubarViewMenu');
140 > static readonly MenubarHomeMenu = new MenuId('MenubarHomeMenu');
141 > static readonly OpenEditorsContext = new MenuId('OpenEditorsContext');
142 > static readonly OpenEditorsContextShare = new MenuId('OpenEditorsContextShare');
143 > static readonly ProblemsPanelContext = new MenuId('ProblemsPanelContext');
144 > static readonly SCMInputBox = new MenuId('SCMInputBox');
145 > static readonly SCMChangeContext = new MenuId('SCMChangeContext');
146 > static readonly SCMResourceContext = new MenuId('SCMResourceContext');
147 > static readonly SCMResourceContextShare = new MenuId('SCMResourceContextShare');
148 > static readonly SCMResourceFolderContext = new MenuId('SCMResourceFolderContext');
149 > static readonly SCMResourceGroupContext = new MenuId('SCMResourceGroupContext');
150 > static readonly SCMSourceControl = new MenuId('SCMSourceControl');
151 > static readonly SCMSourceControlInline = new MenuId('SCMSourceControlInline');
152 > static readonly SCMSourceControlTitle = new MenuId('SCMSourceControlTitle');
153 > static readonly SCMHistoryTitle = new MenuId('SCMHistoryTitle');
154 > static readonly SCMHistoryItemContext = new MenuId('SCMHistoryItemContext');
155 > static readonly SCMHistoryItemChangeContext = new MenuId('SCMHistoryItemChangeContext');
156 > static readonly SCMHistoryItemRefContext = new MenuId('SCMHistoryItemRefContext');
157 > static readonly SCMArtifactGroupContext = new MenuId('SCMArtifactGroupContext');
158 > static readonly SCMArtifactContext = new MenuId('SCMArtifactContext');
159 > static readonly SCMQuickDiffDecorations = new MenuId('SCMQuickDiffDecorations');
160 > static readonly SCMTitle = new MenuId('SCMTitle');
161 > static readonly SearchContext = new MenuId('SearchContext');
162 > static readonly SearchActionMenu = new MenuId('SearchActionContext');
163 > static readonly StatusBarWindowIndicatorMenu = new MenuId('StatusBarWindowIndicatorMenu');
164 > static readonly StatusBarRemoteIndicatorMenu = new MenuId('StatusBarRemoteIndicatorMenu');
165 > static readonly StickyScrollContext = new MenuId('StickyScrollContext');
166 > static readonly TestItem = new MenuId('TestItem');
167 > static readonly TestItemGutter = new MenuId('TestItemGutter');
168 > static readonly TestProfilesContext = new MenuId('TestProfilesContext');
169 > static readonly TestMessageContext = new MenuId('TestMessageContext');
170 > static readonly TestMessageContent = new MenuId('TestMessageContent');
171 > static readonly TestPeekElement = new MenuId('TestPeekElement');
172 > static readonly TestPeekTitle = new MenuId('TestPeekTitle');
173 > static readonly TestCallStack = new MenuId('TestCallStack');
174 > static readonly TestCoverageFilterItem = new MenuId('TestCoverageFilterItem');
175 > static readonly TouchBarContext = new MenuId('TouchBarContext');
176 > static readonly TitleBar = new MenuId('TitleBar');
177 > static readonly TitleBarAdjacentCenter = new MenuId('TitleBarAdjacentCenter');
178 > static readonly TitleBarContext = new MenuId('TitleBarContext');
179 > static readonly TitleBarTitleContext = new MenuId('TitleBarTitleContext');
180 > static readonly TunnelContext = new MenuId('TunnelContext');
181 > static readonly TunnelPrivacy = new MenuId('TunnelPrivacy');
182 > static readonly TunnelProtocol = new MenuId('TunnelProtocol');
183 > static readonly TunnelPortInline = new MenuId('TunnelInline');
184 > static readonly TunnelTitle = new MenuId('TunnelTitle');
185 > static readonly TunnelLocalAddressInline = new MenuId('TunnelLocalAddressInline');
186 > static readonly TunnelOriginInline = new MenuId('TunnelOriginInline');
187 > static readonly ViewItemContext = new MenuId('ViewItemContext');
188 > static readonly ViewContainerTitle = new MenuId('ViewContainerTitle');
189 > static readonly ViewContainerTitleContext = new MenuId('ViewContainerTitleContext');
190 > static readonly ViewTitle = new MenuId('ViewTitle');
191 > static readonly ViewTitleContext = new MenuId('ViewTitleContext');
192 > static readonly CommentEditorActions = new MenuId('CommentEditorActions');
193 > static readonly CommentThreadTitle = new MenuId('CommentThreadTitle');
194 > static readonly CommentThreadActions = new MenuId('CommentThreadActions');
195 > static readonly CommentThreadAdditionalActions = new MenuId('CommentThreadAdditionalActions');
196 > static readonly CommentThreadTitleContext = new MenuId('CommentThreadTitleContext');
197 > static readonly CommentThreadCommentContext = new MenuId('CommentThreadCommentContext');
198 > static readonly CommentTitle = new MenuId('CommentTitle');
199 > static readonly CommentActions = new MenuId('CommentActions');
200 > static readonly CommentsViewThreadActions = new MenuId('CommentsViewThreadActions');
201 > static readonly InteractiveToolbar = new MenuId('InteractiveToolbar');
202 > static readonly InteractiveCellTitle = new MenuId('InteractiveCellTitle');
203 > static readonly InteractiveCellDelete = new MenuId('InteractiveCellDelete');
204 > static readonly InteractiveCellExecute = new MenuId('InteractiveCellExecute');
205 > static readonly InteractiveInputExecute = new MenuId('InteractiveInputExecute');
206 > static readonly InteractiveInputConfig = new MenuId('InteractiveInputConfig');
207 > static readonly ReplInputExecute = new MenuId('ReplInputExecute');
208 > static readonly IssueReporter = new MenuId('IssueReporter');
209 > static readonly NotebookToolbar = new MenuId('NotebookToolbar');
210 > static readonly NotebookToolbarContext = new MenuId('NotebookToolbarContext');
211 > static readonly NotebookStickyScrollContext = new MenuId('NotebookStickyScrollContext');
212 > static readonly NotebookCellTitle = new MenuId('NotebookCellTitle');
213 > static readonly NotebookCellDelete = new MenuId('NotebookCellDelete');
214 > static readonly NotebookCellInsert = new MenuId('NotebookCellInsert');
215 > static readonly NotebookCellBetween = new MenuId('NotebookCellBetween');
216 > static readonly NotebookCellListTop = new MenuId('NotebookCellTop');
217 > static readonly NotebookCellExecute = new MenuId('NotebookCellExecute');
218 > static readonly NotebookCellExecuteGoTo = new MenuId('NotebookCellExecuteGoTo');
219 > static readonly NotebookCellExecutePrimary = new MenuId('NotebookCellExecutePrimary');
220 > static readonly NotebookDiffCellInputTitle = new MenuId('NotebookDiffCellInputTitle');
221 > static readonly NotebookDiffDocumentMetadata = new MenuId('NotebookDiffDocumentMetadata');
222 > static readonly NotebookDiffCellMetadataTitle = new MenuId('NotebookDiffCellMetadataTitle');
223 > static readonly NotebookDiffCellOutputsTitle = new MenuId('NotebookDiffCellOutputsTitle');
224 > static readonly NotebookOutputToolbar = new MenuId('NotebookOutputToolbar');
225 > static readonly NotebookOutlineFilter = new MenuId('NotebookOutlineFilter');
226 > static readonly NotebookOutlineActionMenu = new MenuId('NotebookOutlineActionMenu');
227 > static readonly NotebookEditorLayoutConfigure = new MenuId('NotebookEditorLayoutConfigure');
228 > static readonly NotebookKernelSource = new MenuId('NotebookKernelSource');
229 > static readonly BulkEditTitle = new MenuId('BulkEditTitle');
230 > static readonly BulkEditContext = new MenuId('BulkEditContext');
231 > static readonly TimelineItemContext = new MenuId('TimelineItemContext');
232 > static readonly TimelineTitle = new MenuId('TimelineTitle');
233 > static readonly TimelineTitleContext = new MenuId('TimelineTitleContext');
234 > static readonly TimelineFilterSubMenu = new MenuId('TimelineFilterSubMenu');
235 > static readonly AccountsContext = new MenuId('AccountsContext');
236 > static readonly SidebarTitle = new MenuId('SidebarTitle');
237 > static readonly PanelTitle = new MenuId('PanelTitle');
238 > static readonly AuxiliaryBarTitle = new MenuId('AuxiliaryBarTitle');
239 > static readonly TerminalInstanceContext = new MenuId('TerminalInstanceContext');
240 > static readonly TerminalEditorInstanceContext = new MenuId('TerminalEditorInstanceContext');
241 > static readonly TerminalNewDropdownContext = new MenuId('TerminalNewDropdownContext');
242 > static readonly TerminalTabContext = new MenuId('TerminalTabContext');
243 > static readonly TerminalTabEmptyAreaContext = new MenuId('TerminalTabEmptyAreaContext');
244 > static readonly TerminalStickyScrollContext = new MenuId('TerminalStickyScrollContext');
245 > static readonly WebviewContext = new MenuId('WebviewContext');
246 > static readonly InlineCompletionsActions = new MenuId('InlineCompletionsActions');
247 > static readonly InlineEditsActions = new MenuId('InlineEditsActions');
248 > static readonly NewFile = new MenuId('NewFile');
249 > static readonly MergeInput1Toolbar = new MenuId('MergeToolbar1Toolbar');
250 > static readonly MergeInput2Toolbar = new MenuId('MergeToolbar2Toolbar');
251 > static readonly MergeBaseToolbar = new MenuId('MergeBaseToolbar');
252 > static readonly MergeInputResultToolbar = new MenuId('MergeToolbarResultToolbar');
253 > static readonly InlineSuggestionToolbar = new MenuId('InlineSuggestionToolbar');
254 > static readonly InlineEditToolbar = new MenuId('InlineEditToolbar');
255 > static readonly ChatContext = new MenuId('ChatContext');
256 > static readonly ChatCodeBlock = new MenuId('ChatCodeblock');
257 > static readonly ChatCompareBlock = new MenuId('ChatCompareBlock');
258 > static readonly ChatMessageTitle = new MenuId('ChatMessageTitle');
259 > static readonly ChatWelcomeContext = new MenuId('ChatWelcomeContext');
260 > static readonly ChatMessageFooter = new MenuId('ChatMessageFooter');
261 > static readonly ChatSubagentContent = new MenuId('ChatSubagentContent');
262 > static readonly ChatExecute = new MenuId('ChatExecute');
263 > static readonly ChatExecuteQueue = new MenuId('ChatExecuteQueue');
264 > static readonly ChatInput = new MenuId('ChatInput');
265 > static readonly ChatInputSecondary = new MenuId('ChatInputSecondary');
266 > static readonly ChatInputStatus = new MenuId('ChatInputStatus');
267 > static readonly ChatInputSide = new MenuId('ChatInputSide');
268 > static readonly AutomationsDialogInput = new MenuId('AutomationsDialogInput');
269 > static readonly ChatModePicker = new MenuId('ChatModePicker');
270 > static readonly ChatEditingWidgetToolbar = new MenuId('ChatEditingWidgetToolbar');
271 > static readonly ChatEditingSessionChangesToolbar = new MenuId('ChatEditingSessionChangesToolbar');
272 > static readonly ChatEditingSessionTitleToolbar = new MenuId('ChatEditingSessionTitleToolbar');
273 > static readonly ChatEditingSessionChangesVersionsSubmenu = new MenuId('ChatEditingSessionChangesVersionsSubmenu');
274 > static readonly ChatEditingSessionChangesFileHeaderToolbar = new MenuId('ChatEditingSessionChangesFileHeaderToolbar');
275 > static readonly ChatEditingSessionChangesFileHeaderRightToolbar = new MenuId('ChatEditingSessionChangesFileHeaderRightToolbar');
276 > static readonly ChatEditingEditorContent = new MenuId('ChatEditingEditorContent');
277 > static readonly ChatEditingEditorHunk = new MenuId('ChatEditingEditorHunk');
278 > static readonly ChatEditingDeletedNotebookCell = new MenuId('ChatEditingDeletedNotebookCell');
279 > static readonly ChatInputAttachmentToolbar = new MenuId('ChatInputAttachmentToolbar');
280 > static readonly ChatEditingWidgetModifiedFilesToolbar = new MenuId('ChatEditingWidgetModifiedFilesToolbar');
281 > static readonly ChatInputResourceAttachmentContext = new MenuId('ChatInputResourceAttachmentContext');
282 > static readonly ChatInputSymbolAttachmentContext = new MenuId('ChatInputSymbolAttachmentContext');
283 > static readonly ChatInlineResourceAnchorContext = new MenuId('ChatInlineResourceAnchorContext');
284 > static readonly ChatInlineSymbolAnchorContext = new MenuId('ChatInlineSymbolAnchorContext');
285 > static readonly ChatMessageCheckpoint: MenuId = new MenuId('ChatMessageCheckpoint');
286 > static readonly ChatMessageRestoreCheckpoint: MenuId = new MenuId('ChatMessageRestoreCheckpoint');
287 > static readonly ChatNewMenu = new MenuId('ChatNewMenu');
288 > static readonly ChatEditingCodeBlockContext = new MenuId('ChatEditingCodeBlockContext');
289 > static readonly ChatTitleBarMenu = new MenuId('ChatTitleBarMenu');
290 > static readonly ChatAttachmentsContext = new MenuId('ChatAttachmentsContext');
291 > static readonly ChatTipContext = new MenuId('ChatTipContext');
292 > static readonly ChatTipToolbar = new MenuId('ChatTipToolbar');
293 > static readonly ChatToolOutputResourceToolbar = new MenuId('ChatToolOutputResourceToolbar');
294 > static readonly ChatTextEditorMenu = new MenuId('ChatTextEditorMenu');
295 > static readonly ChatToolOutputResourceContext = new MenuId('ChatToolOutputResourceContext');
296 > static readonly ChatMultiDiffContext = new MenuId('ChatMultiDiffContext');
297 > static readonly ChatConfirmationMenu = new MenuId('ChatConfirmationMenu');
298 > static readonly ChatEditorInlineMenu = new MenuId('ChatEditorInlineGutter');
299 > static readonly ChatEditorInlineExecute = new MenuId('ChatEditorInputExecute');
300 > static readonly ChatEditorInlineInputSide = new MenuId('ChatEditorInputSide');
301 > static readonly InlineChatEditorAffordance = new MenuId('InlineChatEditorAffordance');
302 >
303 > static readonly AccessibleView = new MenuId('AccessibleView');
304 > static readonly MultiDiffEditorContent = new MenuId('MultiDiffEditorContent');
305 > static readonly MultiDiffEditorFileToolbar = new MenuId('MultiDiffEditorFileToolbar');
306 > static readonly DiffEditorHunkToolbar = new MenuId('DiffEditorHunkToolbar');
307 > static readonly DiffEditorSelectionToolbar = new MenuId('DiffEditorSelectionToolbar');
308 > static readonly BrowserNavigationToolbar = new MenuId('BrowserNavigationToolbar');
309 > static readonly BrowserActionsToolbar = new MenuId('BrowserActionsToolbar');
310 > static readonly BrowserChatActionsMenu = new MenuId('BrowserChatActionsMenu');
311 > static readonly BrowserEmulationToolbar = new MenuId('BrowserEmulationToolbar');
312 > static readonly AgentSessionsViewerFilterSubMenu = new MenuId('AgentSessionsViewerFilterSubMenu');
313 > static readonly AgentSessionsContext = new MenuId('AgentSessionsContext');
314 > static readonly AgentSessionSectionContext = new MenuId('AgentSessionSectionContext');
315 > static readonly AgentSessionsCreateSubMenu = new MenuId('AgentSessionsCreateSubMenu');
316 > static readonly AgentSessionsToolbar = new MenuId('AgentSessionsToolbar');
317 > static readonly AgentSessionItemToolbar = new MenuId('AgentSessionItemToolbar');
318 > static readonly AgentSessionSectionToolbar = new MenuId('AgentSessionSectionToolbar');
319 > static readonly SessionItemContextMenu = new MenuId('SessionItemContextMenu');
320 > static readonly SessionHeaderContext = new MenuId('SessionsSessionHeaderContext');
321 > static readonly AgentsTitleBarControlMenu = new MenuId('AgentsTitleBarControlMenu');
322 > static readonly AgentsChangesToolbar = new MenuId('AgentsChangesToolbar');
323 > static readonly AgentsChangesPrimaryActionSubMenu = new MenuId('AgentsChangesPrimaryActionSubMenu');
324 > static readonly AgentsChangeInlineToolbar = new MenuId('AgentsChangeInlineToolbar');
325 > static readonly ChatViewSessionTitleNavigationToolbar = new MenuId('ChatViewSessionTitleNavigationToolbar');
326 > static readonly ChatViewSessionTitleToolbar = new MenuId('ChatViewSessionTitleToolbar');
327 > static readonly ChatContextUsageActions = new MenuId('ChatContextUsageActions');
328 > static readonly MarkerHoverStatusBar = new MenuId('MarkerHoverParticipant.StatusBar');
329 >
330 > /**
331 > * Create or reuse a `MenuId` with the given identifier
332 > */
333 > static for(identifier: string): MenuId {
334 return MenuId._instances.get(identifier) ?? new MenuId(identifier);
335 }
336 > actions.ts
337 > readonly id: string;
338 >
339 > /**
340 > * Create a new `MenuId` with the unique identifier. Will throw if a menu
341 > * with the identifier already exists, use `MenuId.for(ident)` or a unique
342 > * identifier
343 > */
344 > constructor(identifier: string) {
345 > if (MenuId._instances.has(identifier)) {
346 throw new TypeError(`MenuId with identifier '${identifier}' already exists. Use MenuId.for(ident) or a unique identifier`);
347 }
348 > MenuId._instances.set(identifier, this); actions.ts
349 > this.id = identifier;
350 > }
351 > }
352 >
353 > export interface IMenuActionOptions {
354 > arg?: unknown;
355 > args?: unknown[];
356 > shouldForwardArgs?: boolean;
357 > renderShortTitle?: boolean;
358 > }
359 >
360 > export interface IMenuChangeEvent {
361 > readonly menu: IMenu;
362 > readonly isStructuralChange: boolean;
363 > readonly isToggleChange: boolean;
364 > readonly isEnablementChange: boolean;
365 > }
366 >
367 > export interface IMenu extends IDisposable {
368 > readonly onDidChange: Event<IMenuChangeEvent>;
369 > getActions(options?: IMenuActionOptions): [string, Array<MenuItemAction | SubmenuItemAction>][];
370 > }
371 >
372 > export interface IMenuData {
373 > contexts: ReadonlySet<string>;
374 > actions: [string, Array<MenuItemAction | SubmenuItemAction>][];
375 > }
376 >
377 > export const IMenuService = createDecorator<IMenuService>('menuService');
378 >
379 > export interface IMenuCreateOptions {
380 > emitEventsForSubmenuChanges?: boolean;
381 > eventDebounceDelay?: number;
382 > }
383 >
384 > export interface IMenuService {
385 >
386 > readonly _serviceBrand: undefined;
387 >
388 > /**
389 > * Consider using getMenuActions if you don't need to listen to events.
390 > *
391 > * Create a new menu for the given menu identifier. A menu sends events when it's entries
392 > * have changed (placement, enablement, checked-state). By default it does not send events for
393 > * submenu entries. That is more expensive and must be explicitly enabled with the
394 > * `emitEventsForSubmenuChanges` flag.
395 > */
396 > createMenu(id: MenuId, contextKeyService: IContextKeyService, options?: IMenuCreateOptions): IMenu;
397 >
398 > /**
399 > * Creates a new menu, gets the actions, and then disposes of the menu.
400 > */
401 > getMenuActions(id: MenuId, contextKeyService: IContextKeyService, options?: IMenuActionOptions): [string, Array<MenuItemAction | SubmenuItemAction>][];
402 >
403 > /**
404 > * Gets the names of the contexts that this menu listens on.
405 > */
406 > getMenuContexts(id: MenuId): ReadonlySet<string>;
407 >
408 > /**
409 > * Reset **all** menu item hidden states.
410 > */
411 > resetHiddenStates(): void;
412 >
413 > /**
414 > * Reset the menu's hidden states.
415 > */
416 > resetHiddenStates(menuIds: readonly MenuId[] | undefined): void;
417 > }
418 >
419 > type ICommandsMap = Map<string, ICommandAction>;
420 >
421 > export interface IMenuRegistryChangeEvent {
422 > has(id: MenuId): boolean;
423 > }
424 >
425 > class MenuRegistryChangeEvent {
426 >
427 > private static _all = new Map<MenuId, MenuRegistryChangeEvent>();
428 >
429 > static for(id: MenuId): MenuRegistryChangeEvent {
430 let value = this._all.get(id);
431 if (!value) {
435 return value;
436 }
437 > actions.ts
438 > static merge(events: IMenuRegistryChangeEvent[]): IMenuRegistryChangeEvent {
439 const ids = new Set<MenuId>();
440 for (const item of events) {
445 return ids;
446 }
447 > actions.ts
448 > readonly has: (id: MenuId) => boolean;
449 >
450 > private constructor(private readonly id: MenuId) {
451 this.has = candidate => candidate === id;
452 }
453 > } actions.ts
454 >
455 > export interface IMenuRegistry {
456 > readonly onDidChangeMenu: Event<IMenuRegistryChangeEvent>;
457 > addCommand(userCommand: ICommandAction): IDisposable;
458 > getCommand(id: string): ICommandAction | undefined;
459 > getCommands(): ICommandsMap;
460 >
461 > /**
462 > * @deprecated Use `appendMenuItem` or most likely use `registerAction2` instead. There should be no strong
463 > * reason to use this directly.
464 > */
465 > appendMenuItems(items: Iterable<{ id: MenuId; item: IMenuItem | ISubmenuItem }>): IDisposable;
466 > appendMenuItem(menu: MenuId, item: IMenuItem | ISubmenuItem): IDisposable;
467 > getMenuItems(loc: MenuId): Array<IMenuItem | ISubmenuItem>;
468 > }
469 >
470 > export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry {
471 >
472 > private readonly _commands = new Map<string, ICommandAction>();
473 > private readonly _menuItems = new Map<MenuId, LinkedList<IMenuItem | ISubmenuItem>>();
474 > private readonly _onDidChangeMenu = new MicrotaskEmitter<IMenuRegistryChangeEvent>({
475 > merge: MenuRegistryChangeEvent.merge
476 > });
477 >
478 > readonly onDidChangeMenu: Event<IMenuRegistryChangeEvent> = this._onDidChangeMenu.event;
479 >
480 > addCommand(command: ICommandAction): IDisposable {
481 this._commands.set(command.id, command);
482 this._onDidChangeMenu.fire(MenuRegistryChangeEvent.for(MenuId.CommandPalette));
488 }));
489 }
490 > actions.ts
491 > getCommand(id: string): ICommandAction | undefined {
492 return this._commands.get(id);
493 }
494 > actions.ts
495 > getCommands(): ICommandsMap {
496 const map = new Map<string, ICommandAction>();
497 this._commands.forEach((value, key) => map.set(key, value));
498 return map;
499 }
500 > actions.ts
501 > appendMenuItem(id: MenuId, item: IMenuItem | ISubmenuItem): IDisposable {
502 let list = this._menuItems.get(id);
503 if (!list) {
512 }));
513 }
514 > actions.ts
515 > appendMenuItems(items: Iterable<{ id: MenuId; item: IMenuItem | ISubmenuItem }>): IDisposable {
516 const result = new DisposableStore();
517 for (const { id, item } of items) {
520 return result;
521 }
522 > actions.ts
523 > getMenuItems(id: MenuId): Array<IMenuItem | ISubmenuItem> {
524 let result: Array<IMenuItem | ISubmenuItem>;
525 if (this._menuItems.has(id)) {
535 return result;
536 }
537 > actions.ts
538 > private _appendImplicitItems(result: Array<IMenuItem | ISubmenuItem>) {
539 const set = new Set<string>();
540
553 });
554 }
555 > }; actions.ts
556 >
557 > export class SubmenuItemAction extends SubmenuAction {
558 >
559 > constructor(
560 readonly item: ISubmenuItem,
561 readonly hideActions: IMenuItemHide | undefined,
564 super(`submenuitem.${item.submenu.id}`, typeof item.title === 'string' ? item.title : item.title.value, actions, 'submenu');
565 }
566 > } actions.ts
567 >
568 > export interface IMenuItemHide {
569 > readonly isHidden: boolean;
570 > readonly hide: IAction;
571 > readonly toggle: IAction;
572 > }
573 >
574 > // implements IAction, does NOT extend Action, so that no one
575 > // subscribes to events of Action or modified properties
576 > export class MenuItemAction implements IAction {
577 >
578 > static label(action: ICommandAction, options?: IMenuActionOptions): string {
579 > return options?.renderShortTitle && action.shortTitle
580 ? (typeof action.shortTitle === 'string' ? action.shortTitle : action.shortTitle.value)
581 > : (typeof action.title === 'string' ? action.title : action.title.value); actions.ts
582 > }
583 >
584 > readonly item: ICommandAction;
585 > readonly alt: MenuItemAction | undefined;
586 >
587 > private readonly _options: IMenuActionOptions | undefined;
588 >
589 > readonly id: string;
590 > readonly label: string;
591 > readonly tooltip: string;
592 > readonly class: string | undefined;
593 > readonly enabled: boolean;
594 > readonly checked?: boolean;
595 >
596 > constructor(
597 item: ICommandAction,
598 alt: ICommandAction | undefined,
639
640 }
641 > actions.ts
642 > run(...args: unknown[]): Promise<void> {
643 let runArgs: unknown[] = [];
644
655 return this._commandService.executeCommand(this.id, ...runArgs);
656 }
657 > } actions.ts
658 >
659 > //#region --- IAction2
660 >
661 > type OneOrN<T> = T | T[];
662 >
663 > interface IAction2CommonOptions extends ICommandAction {
664 > /**
665 > * One or many menu items.
666 > */
667 > menu?: OneOrN<{ id: MenuId; precondition?: null } & Omit<IMenuItem, 'command'>>;
668 >
669 > /**
670 > * One keybinding.
671 > */
672 > keybinding?: OneOrN<Omit<IKeybindingRule, 'id'>>;
673 > }
674 >
675 > interface IBaseAction2Options extends IAction2CommonOptions {
676 >
677 > /**
678 > * This type is used when an action is not going to show up in the command palette.
679 > * In that case, it's able to use a string for the `title` and `category` properties.
680 > */
681 > f1?: false;
682 > }
683 >
684 > export interface ICommandPaletteOptions extends IAction2CommonOptions {
685 >
686 > /**
687 > * The title of the command that will be displayed in the command palette after the category.
688 > * This overrides {@link ICommandAction.title} to ensure a string isn't used so that the title
689 > * includes the localized value and the original value for users using language packs.
690 > */
691 > title: ICommandActionTitle;
692 >
693 > /**
694 > * The category of the command that will be displayed in the command palette before the title suffixed.
695 > * with a colon This overrides {@link ICommandAction.title} to ensure a string isn't used so that
696 > * the title includes the localized value and the original value for users using language packs.
697 > */
698 > category?: keyof typeof Categories | ILocalizedString;
699 >
700 > /**
701 > * Shorthand to add this command to the command palette. Note: this is not the only way to declare that
702 > * a command should be in the command palette... however, enforcing ILocalizedString in the other scenarios
703 > * is much more challenging and this gets us most of the way there.
704 > */
705 > f1: true;
706 > }
707 >
708 > export type IAction2Options = ICommandPaletteOptions | IBaseAction2Options;
709 >
710 > export interface IAction2F1RequiredOptions {
711 > title: ICommandActionTitle;
712 > category?: keyof typeof Categories | ILocalizedString;
713 > }
714 >
715 > export abstract class Action2 {
716 > constructor(readonly desc: Readonly<IAction2Options>) { }
717 > abstract run(accessor: ServicesAccessor, ...args: unknown[]): void;
718 > }
719 >
720 > export function registerAction2(ctor: { new(): Action2 }): IDisposable {
721 const disposables: IDisposable[] = []; // not using `DisposableStore` to reduce startup perf cost
722 const action = new ctor();
src/vs/platform/keybinding/common/keybindingsRegistry.ts 127 introduced LOC · 9 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- keybindingsRegistry.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 { decodeKeybinding, Keybinding } from '../../../base/common/keybindings.js';
7 > import { OperatingSystem, OS } from '../../../base/common/platform.js';
8 > import { CommandsRegistry, ICommandHandler, ICommandMetadata } from '../../commands/common/commands.js';
9 > import { ContextKeyExpression } from '../../contextkey/common/contextkey.js';
10 > import { Registry } from '../../registry/common/platform.js';
11 > import { combinedDisposable, DisposableStore, IDisposable, toDisposable } from '../../../base/common/lifecycle.js';
12 > import { LinkedList } from '../../../base/common/linkedList.js';
13 >
14 > export interface IKeybindingItem {
15 > keybinding: Keybinding | null;
16 > command: string | null;
17 > commandArgs?: any;
18 > when: ContextKeyExpression | null | undefined;
19 > weight1: number;
20 > weight2: number;
21 > extensionId: string | null;
22 > isBuiltinExtension: boolean;
23 > }
24 >
25 > export interface IKeybindings {
26 > primary?: number;
27 > secondary?: number[];
28 > win?: {
29 > primary: number;
30 > secondary?: number[];
31 > };
32 > linux?: {
33 > primary: number;
34 > secondary?: number[];
35 > };
36 > mac?: {
37 > primary: number;
38 > secondary?: number[];
39 > };
40 > }
41 >
42 > export interface IKeybindingRule extends IKeybindings {
43 > id: string;
44 > weight: number;
45 > args?: any;
46 > /**
47 > * Keybinding is disabled if expression returns false.
48 > */
49 > when?: ContextKeyExpression | null | undefined;
50 > }
51 >
52 > export interface IExtensionKeybindingRule {
53 > keybinding: Keybinding | null;
54 > id: string;
55 > args?: any;
56 > weight: number;
57 > when: ContextKeyExpression | undefined;
58 > extensionId?: string;
59 > isBuiltinExtension?: boolean;
60 > }
61 >
62 > export const enum KeybindingWeight {
63 > EditorCore = 0,
64 > EditorContrib = 100,
65 > WorkbenchContrib = 200,
66 > SessionsContrib = 250,
67 > BuiltinExtension = 300,
68 > ExternalExtension = 400
69 > }
70 >
71 > export interface ICommandAndKeybindingRule<Args extends unknown[] = unknown[]> extends IKeybindingRule {
72 > handler: ICommandHandler<Args>;
73 > metadata?: ICommandMetadata | null;
74 > }
75 >
76 > export interface IKeybindingsRegistry {
77 > registerKeybindingRule(rule: IKeybindingRule): IDisposable;
78 > setExtensionKeybindings(rules: IExtensionKeybindingRule[]): void;
79 > registerCommandAndKeybindingRule<Args extends unknown[] = unknown[]>(desc: ICommandAndKeybindingRule<Args>): IDisposable;
80 > getDefaultKeybindings(): IKeybindingItem[];
81 > getDefaultKeybindingsForOS(os: OperatingSystem): IKeybindingItem[];
82 > }
83 >
84 > /**
85 > * Stores all built-in and extension-provided keybindings (but not ones that user defines themselves)
86 > */
87 > class KeybindingsRegistryImpl implements IKeybindingsRegistry {
88 >
89 > private _coreKeybindings: LinkedList<IKeybindingItem>;
90 > private _coreKeybindingRules: LinkedList<IKeybindingRule>;
91 > private _extensionKeybindings: IKeybindingItem[];
92 > private _cachedMergedKeybindings: IKeybindingItem[] | null;
93 >
94 > constructor() {
95 > this._coreKeybindings = new LinkedList();
96 > this._coreKeybindingRules = new LinkedList();
97 > this._extensionKeybindings = [];
98 > this._cachedMergedKeybindings = null;
99 > }
100 >
101 > private static bindToPlatform(kb: IKeybindings, os: OperatingSystem): { primary?: number; secondary?: number[] } {
102 if (os === OperatingSystem.Windows) {
103 if (kb && kb.win) {
115 return kb;
116 }
118 > /**
119 > * Take current platform into account and reduce to primary & secondary.
120 > */
121 > private static bindToCurrentPlatform(kb: IKeybindings): { primary?: number; secondary?: number[] } {
122 return KeybindingsRegistryImpl.bindToPlatform(kb, OS);
123 }
125 > public registerKeybindingRule(rule: IKeybindingRule): IDisposable {
126 const actualKb = KeybindingsRegistryImpl.bindToCurrentPlatform(rule);
127 const result = new DisposableStore();
149 return result;
150 }
152 > public setExtensionKeybindings(rules: IExtensionKeybindingRule[]): void {
153 const result: IKeybindingItem[] = [];
154 let keybindingsLen = 0;
171 this._cachedMergedKeybindings = null;
172 }
174 > public registerCommandAndKeybindingRule(desc: ICommandAndKeybindingRule): IDisposable {
175 return combinedDisposable(
176 this.registerKeybindingRule(desc),
178 );
179 }
181 > private _registerDefaultKeybinding(keybinding: Keybinding, commandId: string, commandArgs: any, weight1: number, weight2: number, when: ContextKeyExpression | null | undefined): IDisposable {
182 const remove = this._coreKeybindings.push({
183 keybinding: keybinding,
197 });
198 }
200 > public getDefaultKeybindings(): IKeybindingItem[] {
201 if (!this._cachedMergedKeybindings) {
202 this._cachedMergedKeybindings = Array.from(this._coreKeybindings).concat(this._extensionKeybindings);
205 return this._cachedMergedKeybindings.slice(0);
206 }
208 > public getDefaultKeybindingsForOS(os: OperatingSystem): IKeybindingItem[] {
209 const result: IKeybindingItem[] = [];
210 for (const rule of this._coreKeybindingRules) {
250 return result;
251 }
253 > export const KeybindingsRegistry: IKeybindingsRegistry = new KeybindingsRegistryImpl();
254 >
255 > // Define extension point ids
256 > export const Extensions = {
257 > EditorModes: 'platform.keybindingsRegistry'
258 > };
259 > Registry.add(Extensions.EditorModes, KeybindingsRegistry);
260 >
261 function sorter(a: IKeybindingItem, b: IKeybindingItem): number {
262 if (a.weight1 !== b.weight1) {