Skip to content

Commit 88c6e02

Browse files
committed
adopt showContextMenu-users that have been using createAndFillInContextMenuActions
1 parent cfd3a08 commit 88c6e02

File tree

17 files changed

+72
-164
lines changed

17 files changed

+72
-164
lines changed

src/vs/editor/standalone/browser/standaloneServices.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,9 +948,11 @@ class StandaloneContextMenuService extends ContextMenuService {
948948
@INotificationService notificationService: INotificationService,
949949
@IContextViewService contextViewService: IContextViewService,
950950
@IKeybindingService keybindingService: IKeybindingService,
951-
@IThemeService themeService: IThemeService
951+
@IThemeService themeService: IThemeService,
952+
@IMenuService menuService: IMenuService,
953+
@IContextKeyService contextKeyService: IContextKeyService,
952954
) {
953-
super(telemetryService, notificationService, contextViewService, keybindingService, themeService);
955+
super(telemetryService, notificationService, contextViewService, keybindingService, themeService, menuService, contextKeyService);
954956
this.configure({ blockMouse: false }); // we do not want that in the standalone editor
955957
}
956958
}

src/vs/platform/actions/browser/toolbar.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { coalesceInPlace } from 'vs/base/common/arrays';
1010
import { BugIndicatingError } from 'vs/base/common/errors';
1111
import { DisposableStore } from 'vs/base/common/lifecycle';
1212
import { localize } from 'vs/nls';
13-
import { createAndFillInActionBarActions, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
13+
import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
1414
import { IMenuActionOptions, IMenuService, MenuId, MenuItemAction, SubmenuItemAction } from 'vs/platform/actions/common/actions';
1515
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1616
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
@@ -182,23 +182,15 @@ export class WorkbenchToolBar extends ToolBar {
182182
}));
183183
}
184184

185-
// add context menu actions (iff appicable)
186-
if (this._options?.contextMenu) {
187-
const menu = this._menuService.createMenu(this._options.contextMenu, this._contextKeyService);
188-
const contextMenuActions: IAction[] = [];
189-
createAndFillInContextMenuActions(menu, { ...this._options?.menuOptions, renderShortTitle: true, }, contextMenuActions);
190-
menu.dispose();
191-
192-
if (contextMenuActions.length > 0) {
193-
actions = [...actions, new Separator(), ...contextMenuActions];
194-
}
195-
}
196-
197185
// this.getElement().classList.toggle('config', true);
198186

199187
this._contextMenuService.showContextMenu({
200188
getAnchor: () => e,
201189
getActions: () => actions,
190+
// add context menu actions (iff appicable)
191+
menuId: this._options?.contextMenu,
192+
menuActionOptions: { renderShortTitle: true, ...this._options?.menuOptions },
193+
contextKeyService: this._contextKeyService,
202194
onHide: () => this.getElement().classList.toggle('config', false),
203195
});
204196
}));

src/vs/workbench/browser/parts/editor/editorGroupView.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
3636
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
3737
import { IAction } from 'vs/base/common/actions';
3838
import { NoTabsTitleControl } from 'vs/workbench/browser/parts/editor/noTabsTitleControl';
39-
import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions';
39+
import { IMenuService, MenuId } from 'vs/platform/actions/common/actions';
4040
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
41-
import { createAndFillInActionBarActions, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
41+
import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
4242
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
4343
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
4444
import { hash } from 'vs/base/common/hash';
@@ -364,13 +364,11 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
364364
}
365365

366366
private createContainerContextMenu(): void {
367-
const menu = this._register(this.menuService.createMenu(MenuId.EmptyEditorGroupContext, this.contextKeyService));
368-
369-
this._register(addDisposableListener(this.element, EventType.CONTEXT_MENU, e => this.onShowContainerContextMenu(menu, e)));
370-
this._register(addDisposableListener(this.element, TouchEventType.Contextmenu, () => this.onShowContainerContextMenu(menu)));
367+
this._register(addDisposableListener(this.element, EventType.CONTEXT_MENU, e => this.onShowContainerContextMenu(e)));
368+
this._register(addDisposableListener(this.element, TouchEventType.Contextmenu, () => this.onShowContainerContextMenu()));
371369
}
372370

373-
private onShowContainerContextMenu(menu: IMenu, e?: MouseEvent): void {
371+
private onShowContainerContextMenu(e?: MouseEvent): void {
374372
if (!this.isEmpty) {
375373
return; // only for empty editor groups
376374
}
@@ -382,14 +380,11 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
382380
anchor = { x: event.posx, y: event.posy };
383381
}
384382

385-
// Fill in contributed actions
386-
const actions: IAction[] = [];
387-
createAndFillInContextMenuActions(menu, undefined, actions);
388-
389383
// Show it
390384
this.contextMenuService.showContextMenu({
385+
menuId: MenuId.EmptyEditorGroupContext,
386+
contextKeyService: this.contextKeyService,
391387
getAnchor: () => anchor,
392-
getActions: () => actions,
393388
onHide: () => {
394389
this.focus();
395390
}

src/vs/workbench/browser/parts/editor/titleControl.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { ActionsOrientation, IActionViewItem, prepareActions } from 'vs/base/bro
1212
import { IAction, SubmenuAction, ActionRunner } from 'vs/base/common/actions';
1313
import { ResolvedKeybinding } from 'vs/base/common/keybindings';
1414
import { dispose, DisposableStore } from 'vs/base/common/lifecycle';
15-
import { createActionViewItem, createAndFillInActionBarActions, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
16-
import { IMenu, IMenuService, MenuId } from 'vs/platform/actions/common/actions';
15+
import { createActionViewItem, createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
16+
import { IMenuService, MenuId } from 'vs/platform/actions/common/actions';
1717
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1818
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
1919
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
@@ -108,7 +108,6 @@ export abstract class TitleControl extends Themable {
108108

109109
private readonly editorToolBarMenuDisposables = this._register(new DisposableStore());
110110

111-
private contextMenu: IMenu;
112111
private renderDropdownAsChildElement: boolean;
113112

114113
constructor(
@@ -140,7 +139,6 @@ export abstract class TitleControl extends Themable {
140139

141140
this.groupLockedContext = ActiveEditorGroupLockedContext.bindTo(contextKeyService);
142141

143-
this.contextMenu = this._register(this.menuService.createMenu(MenuId.EditorTitleContext, this.contextKeyService));
144142
this.renderDropdownAsChildElement = false;
145143

146144
this.create(parent);
@@ -374,14 +372,12 @@ export abstract class TitleControl extends Themable {
374372
anchor = { x: event.posx, y: event.posy };
375373
}
376374

377-
// Fill in contributed actions
378-
const actions: IAction[] = [];
379-
createAndFillInContextMenuActions(this.contextMenu, { shouldForwardArgs: true, arg: this.resourceContext.get() }, actions);
380-
381375
// Show it
382376
this.contextMenuService.showContextMenu({
383377
getAnchor: () => anchor,
384-
getActions: () => actions,
378+
menuId: MenuId.EditorTitleContext,
379+
menuActionOptions: { shouldForwardArgs: true, arg: this.resourceContext.get() },
380+
contextKeyService: this.contextKeyService,
385381
getActionsContext: () => ({ groupId: this.group.id, editorIndex: this.group.getIndexOfEditor(editor) }),
386382
getKeyBinding: action => this.getKeybinding(action),
387383
onHide: () => {

src/vs/workbench/browser/parts/titlebar/titlebarPart.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { getZoomFactor } from 'vs/base/browser/browser';
1111
import { MenuBarVisibility, getTitleBarStyle, getMenuBarVisibility } from 'vs/platform/window/common/window';
1212
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
1313
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
14-
import { IAction } from 'vs/base/common/actions';
1514
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
1615
import { DisposableStore } from 'vs/base/common/lifecycle';
1716
import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService';
@@ -25,8 +24,8 @@ import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiati
2524
import { Emitter, Event } from 'vs/base/common/event';
2625
import { IStorageService } from 'vs/platform/storage/common/storage';
2726
import { Parts, IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
28-
import { createActionViewItem, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
29-
import { Action2, IMenuService, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
27+
import { createActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
28+
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
3029
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
3130
import { IHostService } from 'vs/workbench/services/host/browser/host';
3231
import { Codicon } from 'vs/base/common/codicons';
@@ -92,7 +91,6 @@ export class TitlebarPart extends Part implements ITitleService {
9291
@IThemeService themeService: IThemeService,
9392
@IStorageService storageService: IStorageService,
9493
@IWorkbenchLayoutService layoutService: IWorkbenchLayoutService,
95-
@IMenuService private readonly menuService: IMenuService,
9694
@IContextKeyService private readonly contextKeyService: IContextKeyService,
9795
@IHostService private readonly hostService: IHostService,
9896
@IHoverService hoverService: IHoverService,
@@ -382,16 +380,11 @@ export class TitlebarPart extends Part implements ITitleService {
382380
const event = new StandardMouseEvent(e);
383381
const anchor = { x: event.posx, y: event.posy };
384382

385-
// Fill in contributed actions
386-
const menu = this.menuService.createMenu(menuId, this.contextKeyService);
387-
const actions: IAction[] = [];
388-
createAndFillInContextMenuActions(menu, undefined, actions);
389-
menu.dispose();
390-
391383
// Show it
392384
this.contextMenuService.showContextMenu({
393385
getAnchor: () => anchor,
394-
getActions: () => actions,
386+
menuId,
387+
contextKeyService: this.contextKeyService,
395388
domForShadowRoot: isMacintosh && isNative ? event.target : undefined
396389
});
397390
}

src/vs/workbench/contrib/bulkEdit/browser/preview/bulkEditPane.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ import { ResourceLabels, IResourceLabelsContainer } from 'vs/workbench/browser/l
2626
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
2727
import Severity from 'vs/base/common/severity';
2828
import { basename, dirname } from 'vs/base/common/resources';
29-
import { IMenuService, MenuId } from 'vs/platform/actions/common/actions';
30-
import { IAction } from 'vs/base/common/actions';
31-
import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
29+
import { MenuId } from 'vs/platform/actions/common/actions';
3230
import { ITreeContextMenuEvent } from 'vs/base/browser/ui/tree/tree';
3331
import { CancellationToken } from 'vs/base/common/cancellation';
3432
import { ITextEditorOptions } from 'vs/platform/editor/common/editor';
@@ -78,10 +76,9 @@ export class BulkEditPane extends ViewPane {
7876
@ILabelService private readonly _labelService: ILabelService,
7977
@ITextModelService private readonly _textModelService: ITextModelService,
8078
@IDialogService private readonly _dialogService: IDialogService,
81-
@IMenuService private readonly _menuService: IMenuService,
8279
@IContextMenuService private readonly _contextMenuService: IContextMenuService,
83-
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
8480
@IStorageService private readonly _storageService: IStorageService,
81+
@IContextKeyService contextKeyService: IContextKeyService,
8582
@IViewDescriptorService viewDescriptorService: IViewDescriptorService,
8683
@IKeybindingService keybindingService: IKeybindingService,
8784
@IContextMenuService contextMenuService: IContextMenuService,
@@ -92,13 +89,13 @@ export class BulkEditPane extends ViewPane {
9289
) {
9390
super(
9491
{ ...options, titleMenuId: MenuId.BulkEditTitle },
95-
keybindingService, contextMenuService, configurationService, _contextKeyService, viewDescriptorService, _instaService, openerService, themeService, telemetryService
92+
keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, _instaService, openerService, themeService, telemetryService
9693
);
9794

9895
this.element.classList.add('bulk-edit-panel', 'show-file-icons');
99-
this._ctxHasCategories = BulkEditPane.ctxHasCategories.bindTo(_contextKeyService);
100-
this._ctxGroupByFile = BulkEditPane.ctxGroupByFile.bindTo(_contextKeyService);
101-
this._ctxHasCheckedChanges = BulkEditPane.ctxHasCheckedChanges.bindTo(_contextKeyService);
96+
this._ctxHasCategories = BulkEditPane.ctxHasCategories.bindTo(contextKeyService);
97+
this._ctxGroupByFile = BulkEditPane.ctxGroupByFile.bindTo(contextKeyService);
98+
this._ctxHasCheckedChanges = BulkEditPane.ctxHasCheckedChanges.bindTo(contextKeyService);
10299
}
103100

104101
override dispose(): void {
@@ -380,16 +377,11 @@ export class BulkEditPane extends ViewPane {
380377
}
381378

382379
private _onContextMenu(e: ITreeContextMenuEvent<any>): void {
383-
const menu = this._menuService.createMenu(MenuId.BulkEditContext, this._contextKeyService);
384-
const actions: IAction[] = [];
385-
createAndFillInContextMenuActions(menu, undefined, actions);
386380

387381
this._contextMenuService.showContextMenu({
388-
getActions: () => actions,
389-
getAnchor: () => e.anchor,
390-
onHide: () => {
391-
menu.dispose();
392-
}
382+
menuId: MenuId.BulkEditContext,
383+
contextKeyService: this.contextKeyService,
384+
getAnchor: () => e.anchor
393385
});
394386
}
395387
}

src/vs/workbench/contrib/comments/browser/commentMenus.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ export class CommentMenus implements IDisposable {
3535
return this.getMenu(MenuId.CommentThreadTitleContext, contextKeyService);
3636
}
3737

38-
getCommentThreadCommentContextActions(contextKeyService: IContextKeyService): IMenu {
39-
return this.getMenu(MenuId.CommentThreadCommentContext, contextKeyService);
40-
}
41-
4238
private getMenu(menuId: MenuId, contextKeyService: IContextKeyService): IMenu {
4339
const menu = this.menuService.createMenu(menuId, contextKeyService);
4440

src/vs/workbench/contrib/comments/browser/commentNode.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
2626
import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview';
2727
import { ToggleReactionsAction, ReactionAction, ReactionActionViewItem } from './reactionsAction';
2828
import { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/commentThreadWidget';
29-
import { MenuItemAction, SubmenuItemAction, IMenu } from 'vs/platform/actions/common/actions';
29+
import { MenuItemAction, SubmenuItemAction, IMenu, MenuId } from 'vs/platform/actions/common/actions';
3030
import { MenuEntryActionViewItem, SubmenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
3131
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
3232
import { CommentFormActions } from 'vs/workbench/contrib/comments/browser/commentFormActions';
@@ -574,13 +574,11 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
574574

575575

576576
private onContextMenu(e: MouseEvent) {
577-
const actions = this._commentMenus.getCommentThreadCommentContextActions(this._contextKeyService).getActions({ shouldForwardArgs: true }).map((value) => value[1]).flat();
578-
if (!actions.length) {
579-
return;
580-
}
581577
this.contextMenuService.showContextMenu({
582578
getAnchor: () => e,
583-
getActions: () => actions,
579+
menuId: MenuId.CommentThreadCommentContext,
580+
menuActionOptions: { shouldForwardArgs: true },
581+
contextKeyService: this._contextKeyService,
584582
actionRunner: new ActionRunner(),
585583
getActionsContext: () => {
586584
return this.commentNodeContext;

src/vs/workbench/contrib/files/browser/views/explorerView.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as nls from 'vs/nls';
77
import { URI } from 'vs/base/common/uri';
88
import * as perf from 'vs/base/common/performance';
9-
import { IAction, WorkbenchActionExecutedEvent, WorkbenchActionExecutedClassification } from 'vs/base/common/actions';
9+
import { WorkbenchActionExecutedEvent, WorkbenchActionExecutedClassification } from 'vs/base/common/actions';
1010
import { memoize } from 'vs/base/common/decorators';
1111
import { IFilesConfiguration, ExplorerFolderContext, FilesExplorerFocusedContext, ExplorerFocusedContext, ExplorerRootContext, ExplorerResourceReadonlyContext, ExplorerResourceCut, ExplorerResourceMoveableToTrash, ExplorerCompressedFocusContext, ExplorerCompressedFirstFocusContext, ExplorerCompressedLastFocusContext, ExplorerResourceAvailableEditorIdsContext, VIEW_ID, VIEWLET_ID, ExplorerResourceNotReadonlyContext, ViewHasSomeCollapsibleRootItemContext } from 'vs/workbench/contrib/files/common/files';
1212
import { FileCopiedContext, NEW_FILE_COMMAND_ID, NEW_FOLDER_COMMAND_ID } from 'vs/workbench/contrib/files/browser/fileActions';
@@ -31,8 +31,7 @@ import { ExplorerDelegate, ExplorerDataSource, FilesRenderer, ICompressedNavigat
3131
import { IThemeService, IFileIconTheme } from 'vs/platform/theme/common/themeService';
3232
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
3333
import { ITreeContextMenuEvent, TreeVisibility } from 'vs/base/browser/ui/tree/tree';
34-
import { IMenuService, MenuId, IMenu, Action2, registerAction2 } from 'vs/platform/actions/common/actions';
35-
import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
34+
import { MenuId, Action2, registerAction2 } from 'vs/platform/actions/common/actions';
3635
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
3736
import { ExplorerItem, NewExplorerItem } from 'vs/workbench/contrib/files/common/explorerModel';
3837
import { ResourceLabels } from 'vs/workbench/browser/labels';
@@ -202,7 +201,6 @@ export class ExplorerView extends ViewPane implements IExplorerView {
202201
@IDecorationsService private readonly decorationService: IDecorationsService,
203202
@ILabelService private readonly labelService: ILabelService,
204203
@IThemeService themeService: IWorkbenchThemeService,
205-
@IMenuService private readonly menuService: IMenuService,
206204
@ITelemetryService telemetryService: ITelemetryService,
207205
@IExplorerService private readonly explorerService: IExplorerService,
208206
@IStorageService private readonly storageService: IStorageService,
@@ -242,13 +240,6 @@ export class ExplorerView extends ViewPane implements IExplorerView {
242240
// noop
243241
}
244242

245-
// Memoized locals
246-
@memoize private get contributedContextMenu(): IMenu {
247-
const contributedContextMenu = this.menuService.createMenu(MenuId.ExplorerContext, this.tree.contextKeyService);
248-
this._register(contributedContextMenu);
249-
return contributedContextMenu;
250-
}
251-
252243
@memoize private get fileCopiedContextKey(): IContextKey<boolean> {
253244
return FileCopiedContext.bindTo(this.contextKeyService);
254245
}
@@ -582,7 +573,6 @@ export class ExplorerView extends ViewPane implements IExplorerView {
582573

583574
const selection = this.tree.getSelection();
584575

585-
const actions: IAction[] = [];
586576
const roots = this.explorerService.roots; // If the click is outside of the elements pass the root resource if there is only one root. If there are multiple roots pass empty object.
587577
let arg: URI | {};
588578
if (stat instanceof ExplorerItem) {
@@ -591,11 +581,12 @@ export class ExplorerView extends ViewPane implements IExplorerView {
591581
} else {
592582
arg = roots.length === 1 ? roots[0].resource : {};
593583
}
594-
createAndFillInContextMenuActions(this.contributedContextMenu, { arg, shouldForwardArgs: true }, actions);
595584

596585
this.contextMenuService.showContextMenu({
586+
menuId: MenuId.ExplorerContext,
587+
menuActionOptions: { arg, shouldForwardArgs: true },
588+
contextKeyService: this.tree.contextKeyService,
597589
getAnchor: () => anchor,
598-
getActions: () => actions,
599590
onHide: (wasCancelled?: boolean) => {
600591
if (wasCancelled) {
601592
this.tree.domFocus();

0 commit comments

Comments
 (0)