From c98a21d84abcccacc6122e7c81d7abd748255347 Mon Sep 17 00:00:00 2001 From: SteVen Batten Date: Wed, 25 Mar 2020 19:09:27 -0400 Subject: [PATCH] allow contributing a web menu entry --- src/vs/base/browser/ui/menu/menubar.ts | 8 +++++++- src/vs/platform/actions/common/actions.ts | 1 + .../browser/parts/titlebar/menubarControl.ts | 12 +++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/vs/base/browser/ui/menu/menubar.ts b/src/vs/base/browser/ui/menu/menubar.ts index fa92216ab12..56770df25b3 100644 --- a/src/vs/base/browser/ui/menu/menubar.ts +++ b/src/vs/base/browser/ui/menu/menubar.ts @@ -21,6 +21,7 @@ import { asArray } from 'vs/base/common/arrays'; import { ScanCodeUtils, ScanCode } from 'vs/base/common/scanCode'; import { isMacintosh } from 'vs/base/common/platform'; import { StandardMouseEvent } from 'vs/base/browser/mouseEvent'; +import { Separator } from 'vs/base/browser/ui/actionbar/actionbar'; const $ = DOM.$; @@ -90,7 +91,7 @@ export class MenuBar extends Disposable { private menuStyle: IMenuStyles | undefined; private overflowLayoutScheduled: IDisposable | undefined = undefined; - constructor(private container: HTMLElement, private options: IMenuBarOptions = {}) { + constructor(private container: HTMLElement, private options: IMenuBarOptions = {}, private compactMenuActions?: IAction[]) { super(); this.container.setAttribute('role', 'menubar'); @@ -490,6 +491,11 @@ export class MenuBar extends Disposable { this.container.insertBefore(this.overflowMenu.buttonElement, this.menuCache[this.numMenusShown].buttonElement); this.overflowMenu.buttonElement.style.visibility = 'visible'; } + + if (this.compactMenuActions && this.compactMenuActions.length) { + this.overflowMenu.actions.push(new Separator()); + this.overflowMenu.actions.push(...this.compactMenuActions); + } } else { DOM.removeNode(this.overflowMenu.buttonElement); this.container.appendChild(this.overflowMenu.buttonElement); diff --git a/src/vs/platform/actions/common/actions.ts b/src/vs/platform/actions/common/actions.ts index 20906116e4c..6e3bc1dc84f 100644 --- a/src/vs/platform/actions/common/actions.ts +++ b/src/vs/platform/actions/common/actions.ts @@ -121,6 +121,7 @@ export class MenuId { static readonly TimelineTitle = new MenuId('TimelineTitle'); static readonly TimelineTitleContext = new MenuId('TimelineTitleContext'); static readonly AccountsContext = new MenuId('AccountsContext'); + static readonly WebMenuActions = new MenuId('MenubarWebMenu'); readonly id: number; readonly _debugName: string; diff --git a/src/vs/workbench/browser/parts/titlebar/menubarControl.ts b/src/vs/workbench/browser/parts/titlebar/menubarControl.ts index 0575e3ef666..d5866d1a844 100644 --- a/src/vs/workbench/browser/parts/titlebar/menubarControl.ts +++ b/src/vs/workbench/browser/parts/titlebar/menubarControl.ts @@ -509,6 +509,16 @@ export class CustomMenubarControl extends MenubarControl { } if (firstTime) { + const webActions = []; + const webMenu = this.menuService.createMenu(MenuId.WebMenuActions, this.contextKeyService); + for (const groups of webMenu.getActions()) { + const [, actions] = groups; + for (const action of actions) { + action.label = mnemonicMenuLabel(this.calculateActionLabel(action)); + webActions.push(action); + } + } + this.menubar = this._register(new MenuBar( this.container, { enableMnemonics: this.currentEnableMenuBarMnemonics, @@ -516,7 +526,7 @@ export class CustomMenubarControl extends MenubarControl { visibility: this.currentMenubarVisibility, getKeybinding: (action) => this.keybindingService.lookupKeybinding(action.id), compactMode: this.currentCompactMenuMode - })); + }, webActions.length > 0 ? webActions : undefined)); this.accessibilityService.alwaysUnderlineAccessKeys().then(val => { this.alwaysOnMnemonics = val; -- GitLab