From 9328275c7f33ac561bf94c00ab474e92368958ca Mon Sep 17 00:00:00 2001 From: Igor Vinokur Date: Tue, 2 Feb 2021 14:16:16 +0200 Subject: [PATCH] fixup! Fix context-keys ScmProvider update, add submenu plugin contribution --- .../src/browser/shell/tab-bar-toolbar.tsx | 13 +++++++----- .../menus/menus-contribution-handler.ts | 21 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/packages/core/src/browser/shell/tab-bar-toolbar.tsx b/packages/core/src/browser/shell/tab-bar-toolbar.tsx index 7fef83070c7cd..eb84fa92ec99f 100644 --- a/packages/core/src/browser/shell/tab-bar-toolbar.tsx +++ b/packages/core/src/browser/shell/tab-bar-toolbar.tsx @@ -153,11 +153,14 @@ export class TabBarToolbar extends ReactWidget { const menuPath = ['TAB_BAR_TOOLBAR_CONTEXT_MENU']; const toDisposeOnHide = new DisposableCollection(); for (const [, item] of this.more) { - // Register a submenu for the item, if the group is in format `//` - if (/.*\/.*\/.*/g.test(item.group!)) { + // Register a submenu for the item, if the group is in format `//.../` + if (item.group!.indexOf('/') !== -1) { const split = item.group!.split('/'); - split.splice(2); - toDisposeOnHide.push(this.menus.registerSubmenu([...menuPath, ...split], split![1])); + const paths: string[] = []; + for (let i = 0; i < split.length - 1; i += 2) { + paths.push(split[i], split[i + 1]); + toDisposeOnHide.push(this.menus.registerSubmenu([...menuPath, ...paths], split[i + 1])); + } } toDisposeOnHide.push(this.menus.registerMenuAction([...menuPath, ...item.group!.split('/')], { label: item.tooltip, @@ -272,7 +275,7 @@ export interface TabBarToolbarItem { /** * Optional group for the item. Default `navigation`. * `navigation` group will be inlined, while all the others will be within the `...` dropdown. - * A group in format `group/submenu/subgroup` means that the item will be located in a submenu of the `...` dropdown. + * A group in format `submenu_group_1/submenu 1/.../submenu_group_n/ submenu n/item_group` means that the item will be located in a submenu(s) of the `...` dropdown. * The submenu's title is named by the submenu section name, e.g. `group//subgroup`. */ readonly group?: string; diff --git a/packages/plugin-ext/src/main/browser/menus/menus-contribution-handler.ts b/packages/plugin-ext/src/main/browser/menus/menus-contribution-handler.ts index af913ff03c866..3abfeae236c81 100644 --- a/packages/plugin-ext/src/main/browser/menus/menus-contribution-handler.ts +++ b/packages/plugin-ext/src/main/browser/menus/menus-contribution-handler.ts @@ -140,17 +140,20 @@ export class MenusContributionPointHandler { toDispose.push(this.registerTreeMenuAction(menuPath, menu)); } } else if (location === 'scm/title') { - for (const action of allMenus[location]) { - if (action.submenu) { - const submenu: Submenu = allSubmenus!.find(s => s.id === action.submenu)!; - for (const submenuAction of allMenus[action.submenu]) { - submenuAction.group = `${action.group!.split('@')[0]}/${submenu.label}/${submenuAction.group ? submenuAction.group.split('@')[0] : '_'}`; - toDispose.push(this.registerScmTitleAction(location, submenuAction)); + const registerActions = (menus: Menu[], group: string | undefined) => { + for (const action of menus) { + if (group) { + action.group = group + (action.group ? '/' + action.group.split('@')[0] : '/_'); + } + if (action.submenu) { + const submenu: Submenu = allSubmenus!.find(s => s.id === action.submenu)!; + registerActions(allMenus[action.submenu], action.group!.split('@')[0] + '/' + submenu.label); + } else { + toDispose.push(this.registerScmTitleAction(location, action)); } - } else if (action.command) { - toDispose.push(this.registerScmTitleAction(location, action)); } - } + }; + registerActions(allMenus[location], undefined); } else if (location === 'scm/resourceGroup/context') { for (const menu of allMenus[location]) { const inline = menu.group && /^inline/.test(menu.group) || false;