From 329d38e6581fe0bd862114ca04bfcf93de50e564 Mon Sep 17 00:00:00 2001
From: SteVen Batten <6561887+sbatten@users.noreply.github.com>
Date: Fri, 15 Jun 2018 13:32:11 -0700
Subject: [PATCH] fallback to old menubar when using macOS or native title
---
src/vs/base/browser/ui/actionbar/actionbar.ts | 4 +++-
src/vs/code/electron-main/app.ts | 10 +++++++++
.../menubar/electron-main/menubarService.ts | 6 ++++-
.../browser/parts/menubar/menubarPart.ts | 22 +++++++++++--------
4 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/src/vs/base/browser/ui/actionbar/actionbar.ts b/src/vs/base/browser/ui/actionbar/actionbar.ts
index 088c16db399..95e634972e2 100644
--- a/src/vs/base/browser/ui/actionbar/actionbar.ts
+++ b/src/vs/base/browser/ui/actionbar/actionbar.ts
@@ -278,7 +278,9 @@ export class ActionItem extends BaseActionItem {
public _updateLabel(): void {
if (this.options.label) {
let label = this.getAction().label;
- label = label.replace(BaseActionItem.MNEMONIC_REGEX, '$1');
+ if (label) {
+ label = label.replace(BaseActionItem.MNEMONIC_REGEX, '$1');
+ }
this.$e.innerHtml(label);
}
}
diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts
index 453a8327648..964e1ed4898 100644
--- a/src/vs/code/electron-main/app.ts
+++ b/src/vs/code/electron-main/app.ts
@@ -63,6 +63,8 @@ import { serve as serveDriver } from 'vs/platform/driver/electron-main/driver';
import { IMenubarService } from 'vs/platform/menubar/common/menubar';
import { MenubarService } from 'vs/platform/menubar/electron-main/menubarService';
import { MenubarChannel } from 'vs/platform/menubar/common/menubarIpc';
+// TODO@sbatten: Remove after conversion to new dynamic menubar
+import { CodeMenu } from 'vs/code/electron-main/menus';
export class CodeApplication {
@@ -493,6 +495,14 @@ export class CodeApplication {
}
}
+ // TODO@sbatten: Remove when menu is converted
+ // Install Menu
+ const instantiationService = accessor.get(IInstantiationService);
+ const configurationService = accessor.get(IConfigurationService);
+ if (platform.isMacintosh || configurationService.getValue('window.titleBarStyle') !== 'custom') {
+ instantiationService.createInstance(CodeMenu);
+ }
+
// Jump List
this.historyMainService.updateWindowsJumpList();
this.historyMainService.onRecentlyOpenedChange(() => this.historyMainService.updateWindowsJumpList());
diff --git a/src/vs/platform/menubar/electron-main/menubarService.ts b/src/vs/platform/menubar/electron-main/menubarService.ts
index a24dd49126b..d4a846baf26 100644
--- a/src/vs/platform/menubar/electron-main/menubarService.ts
+++ b/src/vs/platform/menubar/electron-main/menubarService.ts
@@ -10,6 +10,7 @@ import { Menubar } from 'vs/code/electron-main/menubar';
import { ILogService } from 'vs/platform/log/common/log';
import { TPromise } from 'vs/base/common/winjs.base';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
+import { isMacintosh, isWindows } from 'vs/base/common/platform';
export class MenubarService implements IMenubarService {
_serviceBrand: any;
@@ -21,7 +22,10 @@ export class MenubarService implements IMenubarService {
@ILogService private logService: ILogService
) {
// Install Menu
- this._menubar = this.instantiationService.createInstance(Menubar);
+ // TODO@sbatten: Remove if block
+ if (isMacintosh && isWindows) {
+ this._menubar = this.instantiationService.createInstance(Menubar);
+ }
}
updateMenubar(windowId: number, menus: IMenubarData): TPromise {
diff --git a/src/vs/workbench/browser/parts/menubar/menubarPart.ts b/src/vs/workbench/browser/parts/menubar/menubarPart.ts
index 3d7311a725c..a64265cc5a3 100644
--- a/src/vs/workbench/browser/parts/menubar/menubarPart.ts
+++ b/src/vs/workbench/browser/parts/menubar/menubarPart.ts
@@ -144,13 +144,14 @@ export class MenubarPart extends Part {
}
});
- for (let topLevelMenuName of Object.keys(this.topLevelMenus)) {
- this.topLevelMenus[topLevelMenuName].onDidChange(() => this.setupNativeMenubar());
- }
-
this._onVisibilityChange = new Emitter();
- this.setupNativeMenubar();
+ if (isMacintosh || this.currentTitlebarStyleSetting !== 'custom') {
+ for (let topLevelMenuName of Object.keys(this.topLevelMenus)) {
+ this.topLevelMenus[topLevelMenuName].onDidChange(() => this.setupMenubar());
+ }
+ this.setupMenubar();
+ }
this.isFocused = false;
@@ -247,7 +248,7 @@ export class MenubarPart extends Part {
}
}
- if (this.currentEnableMenuBarMnemonics) {
+ if (this.currentEnableMenuBarMnemonics && this.customMenus) {
this.customMenus.forEach(customMenu => {
let child = customMenu.titleElement.child();
if (child) {
@@ -276,7 +277,7 @@ export class MenubarPart extends Part {
}
private setupMenubar(): void {
- if (this.currentTitlebarStyleSetting === 'custom') {
+ if (!isMacintosh && this.currentTitlebarStyleSetting === 'custom') {
this.setupCustomMenubar();
} else {
this.setupNativeMenubar();
@@ -284,7 +285,10 @@ export class MenubarPart extends Part {
}
private setupNativeMenubar(): void {
- this.menubarService.updateMenubar(this.windowService.getCurrentWindowId(), this.getMenubarMenus());
+ // TODO@sbatten: Remove once native menubar is ready
+ if (isMacintosh && isWindows) {
+ this.menubarService.updateMenubar(this.windowService.getCurrentWindowId(), this.getMenubarMenus());
+ }
}
private registerMnemonic(menuIndex: number, keyCode: KeyCode): void {
@@ -699,7 +703,7 @@ export class MenubarPart extends Part {
// Build the menubar
if (this.container) {
- this.setupCustomMenubar();
+ this.setupMenubar();
}
return this.container.getHTMLElement();
--
GitLab