Skip to content

Commit 14928af

Browse files
committed
make the internals fit for microsoft#9827
1 parent 8da81e5 commit 14928af

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/brows
1515
import { EditorAction, ServicesAccessor, registerEditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
1616
import { IEditorContribution, ScrollType } from 'vs/editor/common/editorCommon';
1717
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
18-
import { IMenuService, MenuId } from 'vs/platform/actions/common/actions';
18+
import { IMenuService, MenuId, SubmenuItemAction } from 'vs/platform/actions/common/actions';
1919
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
2020
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
2121
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
2222
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
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';
2627

2728
export class ContextMenuController implements IEditorContribution {
2829

@@ -128,24 +129,35 @@ export class ContextMenuController implements IEditorContribution {
128129
}
129130

130131
// Find actions available for menu
131-
const menuActions = this._getMenuActions(this._editor.getModel());
132+
const menuActions = this._getMenuActions(this._editor.getModel(), MenuId.EditorContext);
132133

133134
// Show menu if we have actions to show
134135
if (menuActions.length > 0) {
135136
this._doShowContextMenu(menuActions, anchor);
136137
}
137138
}
138139

139-
private _getMenuActions(model: ITextModel): ReadonlyArray<IAction> {
140+
private _getMenuActions(model: ITextModel, menuId: MenuId): IAction[] {
140141
const result: IAction[] = [];
141142

142-
let contextMenu = this._menuService.createMenu(MenuId.EditorContext, this._contextKeyService);
143-
const groups = contextMenu.getActions({ arg: model.uri });
144-
contextMenu.dispose();
143+
// get menu groups
144+
const menu = this._menuService.createMenu(menuId, this._contextKeyService);
145+
const groups = menu.getActions({ arg: model.uri });
146+
menu.dispose();
145147

148+
// translate them into other actions
146149
for (let group of groups) {
147150
const [, actions] = group;
148-
result.push(...actions);
151+
for (const action of actions) {
152+
if (action instanceof SubmenuItemAction) {
153+
const subActions = this._getMenuActions(model, action.item.submenu);
154+
if (subActions.length > 0) {
155+
result.push(new ContextSubMenu(action.label, subActions));
156+
}
157+
} else {
158+
result.push(action);
159+
}
160+
}
149161
result.push(new Separator());
150162
}
151163
result.pop(); // remove last separator

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ class Menu implements IMenu {
111111
const activeActions: Array<MenuItemAction | SubmenuItemAction> = [];
112112
for (const item of items) {
113113
if (this._contextKeyService.contextMatchesRules(item.when)) {
114-
const action = isIMenuItem(item) ? new MenuItemAction(item.command, item.alt, options, this._contextKeyService, this._commandService) : new SubmenuItemAction(item);
114+
const action = isIMenuItem(item)
115+
? new MenuItemAction(item.command, item.alt, options, this._contextKeyService, this._commandService)
116+
: new SubmenuItemAction(item);
117+
115118
activeActions.push(action);
116119
}
117120
}

0 commit comments

Comments
 (0)