This commit is contained in:
SteVen Batten 2018-08-01 13:03:00 -07:00
parent c8f0ee9763
commit 9129656f3d
5 changed files with 25 additions and 11 deletions

View file

@ -112,8 +112,14 @@ export class Menubar {
return enableNativeTabs;
}
updateMenu(menus: IMenubarData, windowId: number) {
updateMenu(menus: IMenubarData, windowId: number, additionalKeybindings?: Array<IMenubarKeybinding>) {
this.menubarMenus = menus;
if (additionalKeybindings) {
additionalKeybindings.forEach(keybinding => {
this.keybindings[keybinding.id] = keybinding;
});
}
this.scheduleUpdateMenu();
}

View file

@ -13,7 +13,7 @@ export const IMenubarService = createDecorator<IMenubarService>('menubarService'
export interface IMenubarService {
_serviceBrand: any;
updateMenubar(windowId: number, menus: IMenubarData): TPromise<void>;
updateMenubar(windowId: number, menus: IMenubarData, additionalKeybindings?: Array<IMenubarKeybinding>): TPromise<void>;
}
export interface IMenubarData {

View file

@ -6,7 +6,7 @@
'use strict';
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
import { TPromise } from 'vs/base/common/winjs.base';
import { IMenubarService, IMenubarData } from 'vs/platform/menubar/common/menubar';
import { IMenubarService, IMenubarData, IMenubarKeybinding } from 'vs/platform/menubar/common/menubar';
import { Event } from 'vs/base/common/event';
export interface IMenubarChannel extends IChannel {
@ -24,7 +24,7 @@ export class MenubarChannel implements IMenubarChannel {
call(command: string, arg?: any): TPromise<any> {
switch (command) {
case 'updateMenubar': return this.service.updateMenubar(arg[0], arg[1]);
case 'updateMenubar': return this.service.updateMenubar(arg[0], arg[1], arg[2]);
}
return undefined;
}
@ -36,7 +36,7 @@ export class MenubarChannelClient implements IMenubarService {
constructor(private channel: IMenubarChannel) { }
updateMenubar(windowId: number, menus: IMenubarData): TPromise<void> {
return this.channel.call('updateMenubar', [windowId, menus]);
updateMenubar(windowId: number, menus: IMenubarData, additionalKeybindings?: Array<IMenubarKeybinding>): TPromise<void> {
return this.channel.call('updateMenubar', [windowId, menus, additionalKeybindings]);
}
}

View file

@ -5,7 +5,7 @@
'use strict';
import { IMenubarService, IMenubarData } from 'vs/platform/menubar/common/menubar';
import { IMenubarService, IMenubarData, IMenubarKeybinding } from 'vs/platform/menubar/common/menubar';
import { Menubar } from 'vs/code/electron-main/menubar';
import { ILogService } from 'vs/platform/log/common/log';
import { TPromise } from 'vs/base/common/winjs.base';
@ -24,11 +24,11 @@ export class MenubarService implements IMenubarService {
this._menubar = this.instantiationService.createInstance(Menubar);
}
updateMenubar(windowId: number, menus: IMenubarData): TPromise<void> {
updateMenubar(windowId: number, menus: IMenubarData, additionalKeybindings?: Array<IMenubarKeybinding>): TPromise<void> {
this.logService.trace('menubarService#updateMenubar', windowId);
if (this._menubar) {
this._menubar.updateMenu(menus, windowId);
this._menubar.updateMenu(menus, windowId, additionalKeybindings);
}
return TPromise.as(null);

View file

@ -430,8 +430,7 @@ export class MenubarPart extends Part {
this.setupCustomMenubar();
} else {
// Send menus to main process to be rendered by Electron
this.menubarService.updateMenubar(this.windowService.getCurrentWindowId(), this.getMenubarMenus());
this.menubarService.updateMenubar(this.windowService.getCurrentWindowId(), this.getMenubarMenus(), this.getAdditionalKeybindings());
}
}
@ -846,6 +845,15 @@ export class MenubarPart extends Part {
}
}
private getAdditionalKeybindings(): Array<IMenubarKeybinding> {
const keybindings = [];
if (isMacintosh) {
keybindings.push(this.getMenubarKeybinding('workbench.action.quit'));
}
return keybindings;
}
private getMenubarMenus(): IMenubarData {
let ret: IMenubarData = {};