src/vs/platform/actions/common/actions.ts

774 LOC · 669 covered · 105 uncovered · 38 ranges · 200 concepts · 6 introducers · 184 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

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 related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- actions.ts ×20
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; actions.ts ×7
59 > }
61 > export function isISubmenuItem(item: unknown): item is ISubmenuItem {
62 > return (item as ISubmenuItem).submenu !== undefined; menuService.ts ×29
63 > }
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); actions.ts ×2
335 > }
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`); actions.ts ×2
347 > }
348 > MenuId._instances.set(identifier, this); actions.ts ×20
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); actions.ts ×7
431 > if (!value) {
432 > value = new MenuRegistryChangeEvent(id);
433 > this._all.set(id, value);
434 > }
435 > return value;
436 > }
438 > static merge(events: IMenuRegistryChangeEvent[]): IMenuRegistryChangeEvent {
439 > const ids = new Set<MenuId>(); menuService.ts ×29
440 > for (const item of events) {
441 > if (item instanceof MenuRegistryChangeEvent) {
442 > ids.add(item.id);
443 > }
444 > }
445 > return ids;
446 > }
448 > readonly has: (id: MenuId) => boolean;
449 >
450 > private constructor(private readonly id: MenuId) {
451 > this.has = candidate => candidate === id; actions.ts ×7
452 > }
453 > } actions.ts ×20
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); actions.ts ×4
482 > this._onDidChangeMenu.fire(MenuRegistryChangeEvent.for(MenuId.CommandPalette));
483 >
484 > return markAsSingleton(toDisposable(() => {
485 > if (this._commands.delete(command.id)) {
486 > this._onDidChangeMenu.fire(MenuRegistryChangeEvent.for(MenuId.CommandPalette));
487 > }
488 > }));
489 > }
491 > getCommand(id: string): ICommandAction | undefined {
492 return this._commands.get(id);
493 }
495 > getCommands(): ICommandsMap {
496 const map = new Map<string, ICommandAction>();
497 this._commands.forEach((value, key) => map.set(key, value));
498 return map;
499 }
501 > appendMenuItem(id: MenuId, item: IMenuItem | ISubmenuItem): IDisposable {
502 > let list = this._menuItems.get(id); actions.ts ×7
503 > if (!list) {
504 > list = new LinkedList();
505 > this._menuItems.set(id, list);
506 > }
507 > const rm = list.push(item);
508 > this._onDidChangeMenu.fire(MenuRegistryChangeEvent.for(id));
509 > return markAsSingleton(toDisposable(() => {
510 > rm();
511 > this._onDidChangeMenu.fire(MenuRegistryChangeEvent.for(id));
512 > }));
513 > }
515 > appendMenuItems(items: Iterable<{ id: MenuId; item: IMenuItem | ISubmenuItem }>): IDisposable {
516 const result = new DisposableStore();
517 for (const { id, item } of items) {
518 result.add(this.appendMenuItem(id, item));
519 }
520 return result;
521 }
523 > getMenuItems(id: MenuId): Array<IMenuItem | ISubmenuItem> {
524 > let result: Array<IMenuItem | ISubmenuItem>; actions.ts ×7
525 > if (this._menuItems.has(id)) {
526 > result = [...this._menuItems.get(id)!];
527 > } else {
528 result = [];
529 }
530 > if (id === MenuId.CommandPalette) { actions.ts ×7
531 > // CommandPalette is special because it shows actions.ts ×4
532 > // all commands by default
533 > this._appendImplicitItems(result);
534 > }
535 > return result; actions.ts ×7
536 > }
538 > private _appendImplicitItems(result: Array<IMenuItem | ISubmenuItem>) {
539 > const set = new Set<string>(); actions.ts ×4
540 >
541 > for (const item of result) {
542 > if (isIMenuItem(item)) {
543 > set.add(item.command.id);
544 > if (item.alt) {
545 set.add(item.alt.id);
546 }
547 > } actions.ts ×4
548 > }
549 > this._commands.forEach((command, id) => {
550 > if (!set.has(id)) {
551 > result.push({ command });
552 > }
553 > });
554 > }
555 > }; actions.ts ×20
556 >
557 > export class SubmenuItemAction extends SubmenuAction {
558 >
559 > constructor(
560 readonly item: ISubmenuItem,
561 readonly hideActions: IMenuItemHide | undefined,
562 actions: readonly IAction[],
563 ) {
564 super(`submenuitem.${item.submenu.id}`, typeof item.title === 'string' ? item.title : item.title.value, actions, 'submenu');
565 }
566 > } actions.ts ×20
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) actions.ts ×1
581 > : (typeof action.title === 'string' ? action.title : action.title.value); actions.ts ×20
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, menuService.ts ×29
598 > alt: ICommandAction | undefined,
599 > options: IMenuActionOptions | undefined,
600 > readonly hideActions: IMenuItemHide | undefined,
601 > readonly menuKeybinding: IAction | undefined,
602 > @IContextKeyService contextKeyService: IContextKeyService,
603 > @ICommandService private _commandService: ICommandService
604 > ) {
605 > this.id = item.id;
606 > this.label = MenuItemAction.label(item, options);
607 > this.tooltip = (typeof item.tooltip === 'string' ? item.tooltip : item.tooltip?.value) ?? '';
608 > this.enabled = !item.precondition || contextKeyService.contextMatchesRules(item.precondition);
609 > this.checked = undefined;
610 >
611 > let icon: ThemeIcon | undefined;
612 >
613 > if (item.toggled) {
614 const toggled = ((item.toggled as { condition: ContextKeyExpression }).condition ? item.toggled : { condition: item.toggled }) as {
615 condition: ContextKeyExpression; icon?: Icon; tooltip?: string | ILocalizedString; title?: string | ILocalizedString;
616 };
617 this.checked = contextKeyService.contextMatchesRules(toggled.condition);
618 if (this.checked && toggled.tooltip) {
619 this.tooltip = typeof toggled.tooltip === 'string' ? toggled.tooltip : toggled.tooltip.value;
620 }
621
622 if (this.checked && ThemeIcon.isThemeIcon(toggled.icon)) {
623 icon = toggled.icon;
624 }
625
626 if (this.checked && toggled.title) {
627 this.label = typeof toggled.title === 'string' ? toggled.title : toggled.title.value;
628 }
629 }
631 > if (!icon) {
632 > icon = ThemeIcon.isThemeIcon(item.icon) ? item.icon : undefined;
633 > }
634 >
635 > this.item = item;
636 > this.alt = alt ? new MenuItemAction(alt, undefined, options, hideActions, undefined, contextKeyService, _commandService) : undefined;
637 > this._options = options;
638 > this.class = icon && ThemeIcon.asClassName(icon);
639 >
640 > }
642 > run(...args: unknown[]): Promise<void> {
643 let runArgs: unknown[] = [];
644
645 if (this._options?.args) {
646 runArgs = [...runArgs, ...this._options.args];
647 } else if (this._options?.arg) {
648 runArgs = [...runArgs, this._options.arg];
649 }
650
651 if (this._options?.shouldForwardArgs) {
652 runArgs = [...runArgs, ...args];
653 }
654
655 return this._commandService.executeCommand(this.id, ...runArgs);
656 }
657 > } actions.ts ×20
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();
723
724 const { f1, menu, keybinding, ...command } = action.desc;
725
726 if (CommandsRegistry.getCommand(command.id)) {
727 throw new Error(`Cannot register two commands with the same id: ${command.id}`);
728 }
729
730 // command
731 disposables.push(CommandsRegistry.registerCommand({
732 id: command.id,
733 handler: (accessor, ...args) => action.run(accessor, ...args),
734 metadata: command.metadata ?? { description: action.desc.title }
735 }));
736
737 // menu
738 if (Array.isArray(menu)) {
739 for (const item of menu) {
740 disposables.push(MenuRegistry.appendMenuItem(item.id, { command: { ...command, precondition: item.precondition === null ? undefined : command.precondition }, ...item }));
741 }
742
743 } else if (menu) {
744 disposables.push(MenuRegistry.appendMenuItem(menu.id, { command: { ...command, precondition: menu.precondition === null ? undefined : command.precondition }, ...menu }));
745 }
746 if (f1) {
747 disposables.push(MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command, when: command.precondition }));
748 disposables.push(MenuRegistry.addCommand(command));
749 }
750
751 // keybinding
752 if (Array.isArray(keybinding)) {
753 for (const item of keybinding) {
754 disposables.push(KeybindingsRegistry.registerKeybindingRule({
755 ...item,
756 id: command.id,
757 when: command.precondition ? ContextKeyExpr.and(command.precondition, item.when) : item.when
758 }));
759 }
760 } else if (keybinding) {
761 disposables.push(KeybindingsRegistry.registerKeybindingRule({
762 ...keybinding,
763 id: command.id,
764 when: command.precondition ? ContextKeyExpr.and(command.precondition, keybinding.when) : keybinding.when
765 }));
766 }
767
768 return {
769 dispose() {
770 dispose(disposables);
771 }
772 };
773 }
774 > //#endregion actions.ts ×20