|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | | -import { Action } from 'vs/base/common/actions'; |
| 6 | +import { Action, IAction, Separator, SubmenuAction } from 'vs/base/common/actions'; |
7 | 7 | import { SyncDescriptor0, createSyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; |
8 | 8 | import { IConstructorSignature2, createDecorator, BrandedService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; |
9 | 9 | import { IKeybindings, KeybindingsRegistry, IKeybindingRule } from 'vs/platform/keybinding/common/keybindingsRegistry'; |
@@ -295,12 +295,35 @@ export class ExecuteCommandAction extends Action { |
295 | 295 | } |
296 | 296 | } |
297 | 297 |
|
298 | | -export class SubmenuItemAction extends Action { |
| 298 | +export class SubmenuItemAction extends SubmenuAction { |
299 | 299 |
|
300 | | - readonly item: ISubmenuItem; |
301 | | - constructor(item: ISubmenuItem) { |
302 | | - typeof item.title === 'string' ? super('', item.title, 'submenu') : super('', item.title.value, 'submenu'); |
303 | | - this.item = item; |
| 300 | + constructor( |
| 301 | + readonly item: ISubmenuItem, |
| 302 | + menuService: IMenuService, |
| 303 | + contextKeyService: IContextKeyService, |
| 304 | + options?: IMenuActionOptions |
| 305 | + ) { |
| 306 | + super(typeof item.title === 'string' ? item.title : item.title.value, () => { |
| 307 | + const result: IAction[] = []; |
| 308 | + const menu = menuService.createMenu(item.submenu, contextKeyService); |
| 309 | + const groups = menu.getActions(options); |
| 310 | + menu.dispose(); |
| 311 | + |
| 312 | + for (let group of groups) { |
| 313 | + const [, actions] = group; |
| 314 | + |
| 315 | + if (actions.length > 0) { |
| 316 | + result.push(...actions); |
| 317 | + result.push(new Separator()); |
| 318 | + } |
| 319 | + } |
| 320 | + |
| 321 | + if (result.length) { |
| 322 | + result.pop(); // remove last separator |
| 323 | + } |
| 324 | + |
| 325 | + return result; |
| 326 | + }, 'submenu'); |
304 | 327 | } |
305 | 328 | } |
306 | 329 |
|
|
0 commit comments