Skip to content

Commit eed2e95

Browse files
committed
fix native submenus, delete ContextSubMenu
1 parent d3cd7bc commit eed2e95

10 files changed

Lines changed: 33 additions & 46 deletions

File tree

src/vs/base/browser/contextmenu.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { IAction, IActionRunner, SubmenuAction, SubmenuActions } from 'vs/base/common/actions';
6+
import { IAction, IActionRunner } from 'vs/base/common/actions';
77
import { IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
88
import { ResolvedKeybinding } from 'vs/base/common/keyCodes';
99
import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview';
@@ -15,15 +15,9 @@ export interface IContextMenuEvent {
1515
readonly metaKey?: boolean;
1616
}
1717

18-
export class ContextSubMenu extends SubmenuAction {
19-
constructor(label: string, public actions: SubmenuActions) {
20-
super(label, actions, 'contextsubmenu');
21-
}
22-
}
23-
2418
export interface IContextMenuDelegate {
2519
getAnchor(): HTMLElement | { x: number; y: number; width?: number; height?: number; };
26-
getActions(): ReadonlyArray<IAction | ContextSubMenu>;
20+
getActions(): IAction[];
2721
getCheckedActionsRepresentation?(action: IAction): 'radio' | 'checkbox';
2822
getActionViewItem?(action: IAction): IActionViewItem | undefined;
2923
getActionsContext?(event?: IContextMenuEvent): any;

src/vs/base/browser/ui/dropdown/dropdown.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ export interface IContextMenuProvider {
206206
}
207207

208208
export interface IActionProvider {
209-
getActions(): ReadonlyArray<IAction>;
209+
getActions(): IAction[];
210210
}
211211

212212
export interface IDropdownMenuOptions extends IBaseDropdownOptions {
213213
contextMenuProvider: IContextMenuProvider;
214-
actions?: ReadonlyArray<IAction>;
214+
actions?: IAction[];
215215
actionProvider?: IActionProvider;
216216
menuClassName?: string;
217217
menuAsChild?: boolean; // scope down for #99448
@@ -220,7 +220,7 @@ export interface IDropdownMenuOptions extends IBaseDropdownOptions {
220220
export class DropdownMenu extends BaseDropdown {
221221
private _contextMenuProvider: IContextMenuProvider;
222222
private _menuOptions: IMenuOptions | undefined;
223-
private _actions: ReadonlyArray<IAction> = [];
223+
private _actions: IAction[] = [];
224224
private actionProvider?: IActionProvider;
225225
private menuClassName: string;
226226
private menuAsChild?: boolean;
@@ -243,15 +243,15 @@ export class DropdownMenu extends BaseDropdown {
243243
return this._menuOptions;
244244
}
245245

246-
private get actions(): ReadonlyArray<IAction> {
246+
private get actions(): IAction[] {
247247
if (this.actionProvider) {
248248
return this.actionProvider.getActions();
249249
}
250250

251251
return this._actions;
252252
}
253253

254-
private set actions(actions: ReadonlyArray<IAction>) {
254+
private set actions(actions: IAction[]) {
255255
this._actions = actions;
256256
}
257257

src/vs/editor/contrib/contextmenu/contextmenu.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as dom from 'vs/base/browser/dom';
88
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
99
import { ActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
1010
import { IAnchor } from 'vs/base/browser/ui/contextview/contextview';
11-
import { IAction, Separator } from 'vs/base/common/actions';
11+
import { IAction, Separator, SubmenuAction } from 'vs/base/common/actions';
1212
import { KeyCode, KeyMod, ResolvedKeybinding } from 'vs/base/common/keyCodes';
1313
import { DisposableStore } from 'vs/base/common/lifecycle';
1414
import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser';
@@ -23,7 +23,6 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis
2323
import { ITextModel } from 'vs/editor/common/model';
2424
import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
2525
import { EditorOption } from 'vs/editor/common/config/editorOptions';
26-
import { ContextSubMenu } from 'vs/base/browser/contextmenu';
2726

2827
export class ContextMenuController implements IEditorContribution {
2928

@@ -153,7 +152,7 @@ export class ContextMenuController implements IEditorContribution {
153152
if (action instanceof SubmenuItemAction) {
154153
const subActions = this._getMenuActions(model, action.item.submenu);
155154
if (subActions.length > 0) {
156-
result.push(new ContextSubMenu(action.label, subActions));
155+
result.push(new SubmenuAction(action.label, subActions));
157156
addedItems++;
158157
}
159158
} else {
@@ -174,7 +173,7 @@ export class ContextMenuController implements IEditorContribution {
174173
return result;
175174
}
176175

177-
private _doShowContextMenu(actions: ReadonlyArray<IAction>, anchor: IAnchor | null = null): void {
176+
private _doShowContextMenu(actions: IAction[], anchor: IAnchor | null = null): void {
178177
if (!this._editor.hasModel()) {
179178
return;
180179
}

src/vs/workbench/browser/parts/activitybar/activitybarActions.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as nls from 'vs/nls';
88
import * as DOM from 'vs/base/browser/dom';
99
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
1010
import { EventType as TouchEventType, GestureEvent } from 'vs/base/browser/touch';
11-
import { Action, IAction, Separator } from 'vs/base/common/actions';
11+
import { Action, IAction, Separator, SubmenuAction } from 'vs/base/common/actions';
1212
import { KeyCode } from 'vs/base/common/keyCodes';
1313
import { dispose } from 'vs/base/common/lifecycle';
1414
import { SyncActionDescriptor, IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions';
@@ -29,7 +29,6 @@ import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/men
2929
import { Codicon } from 'vs/base/common/codicons';
3030
import { ActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
3131
import { isMacintosh } from 'vs/base/common/platform';
32-
import { ContextSubMenu } from 'vs/base/browser/contextmenu';
3332
import { IAuthenticationService } from 'vs/workbench/services/authentication/browser/authenticationService';
3433
import { AuthenticationSession } from 'vs/editor/common/modes';
3534
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
@@ -159,7 +158,7 @@ export class AccountsActionViewItem extends ActivityActionViewItem {
159158
});
160159

161160
const result = await Promise.all(allSessions);
162-
let menus: (IAction | ContextSubMenu)[] = [];
161+
let menus: IAction[] = [];
163162
result.forEach(sessionInfo => {
164163
const providerDisplayName = this.authenticationService.getLabel(sessionInfo.providerId);
165164
Object.keys(sessionInfo.sessions).forEach(accountName => {
@@ -173,7 +172,7 @@ export class AccountsActionViewItem extends ActivityActionViewItem {
173172

174173
const actions = hasEmbedderAccountSession ? [manageExtensionsAction] : [manageExtensionsAction, signOutAction];
175174

176-
const menu = new ContextSubMenu(`${accountName} (${providerDisplayName})`, actions);
175+
const menu = new SubmenuAction(`${accountName} (${providerDisplayName})`, actions);
177176
menus.push(menu);
178177
});
179178
});

src/vs/workbench/browser/viewlet.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as nls from 'vs/nls';
77
import * as DOM from 'vs/base/browser/dom';
88
import { Registry } from 'vs/platform/registry/common/platform';
9-
import { Action, IAction, Separator } from 'vs/base/common/actions';
9+
import { Action, IAction, Separator, SubmenuAction } from 'vs/base/common/actions';
1010
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
1111
import { IViewlet } from 'vs/workbench/common/viewlet';
1212
import { CompositeDescriptor, CompositeRegistry } from 'vs/workbench/browser/composite';
@@ -26,7 +26,6 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten
2626
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
2727
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2828
import { PaneComposite } from 'vs/workbench/browser/panecomposite';
29-
import { ContextSubMenu } from 'vs/base/browser/contextmenu';
3029
import { Event } from 'vs/base/common/event';
3130

3231
export abstract class Viewlet extends PaneComposite implements IViewlet {
@@ -78,7 +77,7 @@ export abstract class Viewlet extends PaneComposite implements IViewlet {
7877
}
7978

8079
return [
81-
new ContextSubMenu(nls.localize('views', "Views"), viewSecondaryActions),
80+
new SubmenuAction(nls.localize('views', "Views"), viewSecondaryActions),
8281
new Separator(),
8382
...secondaryActions
8483
];

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { ContextSubMenu } from 'vs/base/browser/contextmenu';
76
import { $ } from 'vs/base/browser/dom';
87
import { Action, IAction } from 'vs/base/common/actions';
98
import { coalesce, findFirstInSorted } from 'vs/base/common/arrays';
@@ -547,8 +546,8 @@ export class CommentController implements IEditorContribution {
547546
return picks;
548547
}
549548

550-
private getContextMenuActions(commentInfos: { ownerId: string, extensionId: string | undefined, label: string | undefined, commentingRangesInfo: modes.CommentingRanges }[], lineNumber: number): (IAction | ContextSubMenu)[] {
551-
const actions: (IAction | ContextSubMenu)[] = [];
549+
private getContextMenuActions(commentInfos: { ownerId: string, extensionId: string | undefined, label: string | undefined, commentingRangesInfo: modes.CommentingRanges }[], lineNumber: number): IAction[] {
550+
const actions: IAction[] = [];
552551

553552
commentInfos.forEach(commentInfo => {
554553
const { ownerId, extensionId, label } = commentInfo;

src/vs/workbench/contrib/debug/browser/breakpointEditorContribution.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as env from 'vs/base/common/platform';
88
import * as dom from 'vs/base/browser/dom';
99
import { URI } from 'vs/base/common/uri';
1010
import severity from 'vs/base/common/severity';
11-
import { IAction, Action } from 'vs/base/common/actions';
11+
import { IAction, Action, SubmenuAction } from 'vs/base/common/actions';
1212
import { Range } from 'vs/editor/common/core/range';
1313
import { ICodeEditor, IEditorMouseEvent, MouseTargetType, IContentWidget, IActiveCodeEditor, IContentWidgetPosition, ContentWidgetPositionPreference } from 'vs/editor/browser/editorBrowser';
1414
import { IModelDecorationOptions, IModelDeltaDecoration, TrackedRangeStickiness, ITextModel, OverviewRulerLane, IModelDecorationOverviewRulerOptions } from 'vs/editor/common/model';
@@ -18,7 +18,6 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
1818
import { RemoveBreakpointAction } from 'vs/workbench/contrib/debug/browser/debugActions';
1919
import { IDebugService, IBreakpoint, CONTEXT_BREAKPOINT_WIDGET_VISIBLE, BreakpointWidgetContext, IBreakpointEditorContribution, IBreakpointUpdateData, IDebugConfiguration, State, IDebugSession } from 'vs/workbench/contrib/debug/common/debug';
2020
import { IMarginData } from 'vs/editor/browser/controller/mouseTarget';
21-
import { ContextSubMenu } from 'vs/base/browser/contextmenu';
2221
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
2322
import { BreakpointWidget } from 'vs/workbench/contrib/debug/browser/breakpointWidget';
2423
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
@@ -288,8 +287,8 @@ export class BreakpointEditorContribution implements IBreakpointEditorContributi
288287
}));
289288
}
290289

291-
private getContextMenuActions(breakpoints: ReadonlyArray<IBreakpoint>, uri: URI, lineNumber: number, column?: number): Array<IAction | ContextSubMenu> {
292-
const actions: Array<IAction | ContextSubMenu> = [];
290+
private getContextMenuActions(breakpoints: ReadonlyArray<IBreakpoint>, uri: URI, lineNumber: number, column?: number): IAction[] {
291+
const actions: IAction[] = [];
293292
if (breakpoints.length === 1) {
294293
const breakpointType = breakpoints[0].logMessage ? nls.localize('logPoint', "Logpoint") : nls.localize('breakpoint', "Breakpoint");
295294
actions.push(new RemoveBreakpointAction(RemoveBreakpointAction.ID, nls.localize('removeBreakpoint', "Remove {0}", breakpointType), this.debugService));
@@ -310,15 +309,15 @@ export class BreakpointEditorContribution implements IBreakpointEditorContributi
310309
));
311310
} else if (breakpoints.length > 1) {
312311
const sorted = breakpoints.slice().sort((first, second) => (first.column && second.column) ? first.column - second.column : 1);
313-
actions.push(new ContextSubMenu(nls.localize('removeBreakpoints', "Remove Breakpoints"), sorted.map(bp => new Action(
312+
actions.push(new SubmenuAction(nls.localize('removeBreakpoints', "Remove Breakpoints"), sorted.map(bp => new Action(
314313
'removeInlineBreakpoint',
315314
bp.column ? nls.localize('removeInlineBreakpointOnColumn', "Remove Inline Breakpoint on Column {0}", bp.column) : nls.localize('removeLineBreakpoint', "Remove Line Breakpoint"),
316315
undefined,
317316
true,
318317
() => this.debugService.removeBreakpoints(bp.getId())
319318
))));
320319

321-
actions.push(new ContextSubMenu(nls.localize('editBreakpoints', "Edit Breakpoints"), sorted.map(bp =>
320+
actions.push(new SubmenuAction(nls.localize('editBreakpoints', "Edit Breakpoints"), sorted.map(bp =>
322321
new Action('editBreakpoint',
323322
bp.column ? nls.localize('editInlineBreakpointOnColumn', "Edit Inline Breakpoint on Column {0}", bp.column) : nls.localize('editLineBrekapoint', "Edit Line Breakpoint"),
324323
undefined,
@@ -327,7 +326,7 @@ export class BreakpointEditorContribution implements IBreakpointEditorContributi
327326
)
328327
)));
329328

330-
actions.push(new ContextSubMenu(nls.localize('enableDisableBreakpoints', "Enable/Disable Breakpoints"), sorted.map(bp => new Action(
329+
actions.push(new SubmenuAction(nls.localize('enableDisableBreakpoints', "Enable/Disable Breakpoints"), sorted.map(bp => new Action(
331330
bp.enabled ? 'disableColumnBreakpoint' : 'enableColumnBreakpoint',
332331
bp.enabled ? (bp.column ? nls.localize('disableInlineColumnBreakpoint', "Disable Inline Breakpoint on Column {0}", bp.column) : nls.localize('disableBreakpointOnLine', "Disable Line Breakpoint"))
333332
: (bp.column ? nls.localize('enableBreakpoints', "Enable Inline Breakpoint on Column {0}", bp.column) : nls.localize('enableBreakpointOnLine', "Enable Line Breakpoint")),
@@ -548,7 +547,7 @@ class InlineBreakpointWidget implements IContentWidget, IDisposable {
548547
private readonly breakpoint: IBreakpoint | undefined,
549548
private readonly debugService: IDebugService,
550549
private readonly contextMenuService: IContextMenuService,
551-
private readonly getContextMenuActions: () => ReadonlyArray<IAction | ContextSubMenu>
550+
private readonly getContextMenuActions: () => IAction[]
552551
) {
553552
this.range = this.editor.getModel().getDecorationRange(decorationId);
554553
this.toDispose.push(this.editor.onDidChangeModelDecorations(() => {

src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { ContextSubMenu } from 'vs/base/browser/contextmenu';
76
import { EventHelper, getDomNodePagePosition } from 'vs/base/browser/dom';
8-
import { IAction } from 'vs/base/common/actions';
7+
import { IAction, SubmenuAction } from 'vs/base/common/actions';
98
import { Delayer } from 'vs/base/common/async';
109
import { Emitter, Event } from 'vs/base/common/event';
1110
import { IJSONSchema } from 'vs/base/common/jsonSchema';
@@ -826,7 +825,7 @@ class EditSettingRenderer extends Disposable {
826825

827826
const anchor = { x: e.event.posx, y: e.event.posy + 10 };
828827
const actions = this.getSettings(editPreferenceWidget.getLine()).length === 1 ? this.getActions(editPreferenceWidget.preferences[0], this.getConfigurationsMap()[editPreferenceWidget.preferences[0].key])
829-
: editPreferenceWidget.preferences.map(setting => new ContextSubMenu(setting.key, this.getActions(setting, this.getConfigurationsMap()[setting.key])));
828+
: editPreferenceWidget.preferences.map(setting => new SubmenuAction(setting.key, this.getActions(setting, this.getConfigurationsMap()[setting.key])));
830829
this.contextMenuService.showContextMenu({
831830
getAnchor: () => anchor,
832831
getActions: () => actions

src/vs/workbench/contrib/scm/browser/scmViewPane.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/c
2020
import { ICommandService } from 'vs/platform/commands/common/commands';
2121
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
2222
import { MenuItemAction, IMenuService } from 'vs/platform/actions/common/actions';
23-
import { IAction, IActionViewItem, ActionRunner, Action, RadioGroup, Separator } from 'vs/base/common/actions';
23+
import { IAction, IActionViewItem, ActionRunner, Action, RadioGroup, Separator, SubmenuAction } from 'vs/base/common/actions';
2424
import { ContextAwareMenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
2525
import { SCMMenus } from './menus';
2626
import { ActionBar, IActionViewItemProvider, ActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
@@ -72,7 +72,6 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
7272
import { IListAccessibilityProvider } from 'vs/base/browser/ui/list/listWidget';
7373
import { IModeService } from 'vs/editor/common/services/modeService';
7474
import { ILabelService } from 'vs/platform/label/common/label';
75-
import { ContextSubMenu } from 'vs/base/browser/contextmenu';
7675
import { KeyCode } from 'vs/base/common/keyCodes';
7776
import { DEFAULT_FONT_FAMILY } from 'vs/workbench/browser/style';
7877
import { Command } from 'vs/editor/common/modes';
@@ -1167,7 +1166,7 @@ class ViewModel {
11671166
}
11681167
}
11691168

1170-
class SCMViewSubMenuAction extends ContextSubMenu {
1169+
class SCMViewSubMenuAction extends SubmenuAction {
11711170
constructor(viewModel: ViewModel) {
11721171
super(localize('sortAction', "View & Sort"),
11731172
[

src/vs/workbench/services/contextmenu/electron-sandbox/contextmenuService.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { IAction, IActionRunner, ActionRunner, WorkbenchActionExecutedEvent, WorkbenchActionExecutedClassification, Separator } from 'vs/base/common/actions';
6+
import { IAction, IActionRunner, ActionRunner, WorkbenchActionExecutedEvent, WorkbenchActionExecutedClassification, Separator, SubmenuAction } from 'vs/base/common/actions';
77
import * as dom from 'vs/base/browser/dom';
88
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
99
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
@@ -12,7 +12,7 @@ import { getZoomFactor } from 'vs/base/browser/browser';
1212
import { unmnemonicLabel } from 'vs/base/common/labels';
1313
import { Event, Emitter } from 'vs/base/common/event';
1414
import { INotificationService } from 'vs/platform/notification/common/notification';
15-
import { IContextMenuDelegate, ContextSubMenu, IContextMenuEvent } from 'vs/base/browser/contextmenu';
15+
import { IContextMenuDelegate, IContextMenuEvent } from 'vs/base/browser/contextmenu';
1616
import { once } from 'vs/base/common/functional';
1717
import { Disposable } from 'vs/base/common/lifecycle';
1818
import { IContextMenuItem } from 'vs/base/parts/contextmenu/common/contextmenu';
@@ -123,21 +123,21 @@ class NativeContextMenuService extends Disposable implements IContextMenuService
123123
}
124124
}
125125

126-
private createMenu(delegate: IContextMenuDelegate, entries: ReadonlyArray<IAction | ContextSubMenu>, onHide: () => void): IContextMenuItem[] {
126+
private createMenu(delegate: IContextMenuDelegate, entries: IAction[], onHide: () => void): IContextMenuItem[] {
127127
const actionRunner = delegate.actionRunner || new ActionRunner();
128128

129129
return entries.map(entry => this.createMenuItem(delegate, entry, actionRunner, onHide));
130130
}
131131

132-
private createMenuItem(delegate: IContextMenuDelegate, entry: IAction | ContextSubMenu, actionRunner: IActionRunner, onHide: () => void): IContextMenuItem {
132+
private createMenuItem(delegate: IContextMenuDelegate, entry: IAction, actionRunner: IActionRunner, onHide: () => void): IContextMenuItem {
133133

134134
// Separator
135135
if (entry instanceof Separator) {
136136
return { type: 'separator' };
137137
}
138138

139139
// Submenu
140-
if (entry instanceof ContextSubMenu) {
140+
if (entry instanceof SubmenuAction) {
141141
const actions = Array.isArray(entry.actions) ? entry.actions : entry.actions();
142142
return {
143143
label: unmnemonicLabel(stripCodicons(entry.label)).trim(),

0 commit comments

Comments
 (0)