Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding context change listener and buffering calls to setup the menu #53622

Merged
merged 2 commits into from
Jul 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 30 additions & 3 deletions src/vs/workbench/browser/parts/menubar/menubarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { IRecentlyOpened } from 'vs/platform/history/common/history';
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, getWorkspaceLabel } from 'vs/platform/workspaces/common/workspaces';
import { getPathLabel } from 'vs/base/common/labels';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { RunOnceScheduler } from 'vs/base/common/async';

interface CustomMenu {
title: string;
Expand Down Expand Up @@ -88,9 +89,11 @@ export class MenubarPart extends Part {

private customMenus: CustomMenu[];

private menuUpdater: RunOnceScheduler;
private actionRunner: IActionRunner;
private container: Builder;
private recentlyOpened: IRecentlyOpened;
private updatePending: boolean;
private _modifierKeyStatus: IModifierKeyStatus;
private _isFocused: boolean;
private _onVisibilityChange: Emitter<Dimension>;
Expand Down Expand Up @@ -135,6 +138,8 @@ export class MenubarPart extends Part {
this.topLevelMenus['Window'] = this._register(this.menuService.createMenu(MenuId.MenubarWindowMenu, this.contextKeyService));
}

this.menuUpdater = this._register(new RunOnceScheduler(() => this.doSetupMenubar(), 0));

this.actionRunner = this._register(new ActionRunner());
this._register(this.actionRunner.onDidBeforeRun(() => {
if (this.focusedMenu && this.focusedMenu.holder) {
Expand All @@ -148,7 +153,7 @@ export class MenubarPart extends Part {
for (let topLevelMenuName of Object.keys(this.topLevelMenus)) {
this._register(this.topLevelMenus[topLevelMenuName].onDidChange(() => this.setupMenubar()));
}
this.setupMenubar();
this.doSetupMenubar();
}

this.isFocused = false;
Expand Down Expand Up @@ -212,6 +217,15 @@ export class MenubarPart extends Part {
}

private set isFocused(value: boolean) {
if (this._isFocused && !value) {
// Losing focus, update the menu if needed

if (this.updatePending) {
this.menuUpdater.schedule();
this.updatePending = false;
}
}

this._isFocused = value;

if (!this._isFocused && this.currentMenubarVisibility === 'toggle') {
Expand Down Expand Up @@ -282,6 +296,9 @@ export class MenubarPart extends Part {
// Listen to update service
// this.updateService.onStateChange(() => this.setupMenubar());

// Listen for context changes
this._register(this.contextKeyService.onDidChangeContext(() => this.setupMenubar()));

// Listen for changes in recently opened menu
this._register(this.windowsService.onRecentlyOpenedChange(() => { this.onRecentlyOpenedChange(); }));

Expand All @@ -291,14 +308,18 @@ export class MenubarPart extends Part {
this._register(ModifierKeyEmitter.getInstance().event(this.onModifierKeyToggled, this));
}

private setupMenubar(): void {
private doSetupMenubar(): void {
if (!isMacintosh && this.currentTitlebarStyleSetting === 'custom') {
this.setupCustomMenubar();
} else {
this.setupNativeMenubar();
}
}

private setupMenubar(): void {
this.menuUpdater.schedule();
}

private setupNativeMenubar(): void {
// TODO@sbatten: Remove once native menubar is ready
if (isMacintosh && isWindows) {
Expand Down Expand Up @@ -428,6 +449,12 @@ export class MenubarPart extends Part {
}

private setupCustomMenubar(): void {
// Don't update while using the menu
if (this.isFocused) {
this.updatePending = true;
return;
}

this.container.empty();
this.container.attr('role', 'menubar');

Expand Down Expand Up @@ -773,7 +800,7 @@ export class MenubarPart extends Part {

// Build the menubar
if (this.container) {
this.setupMenubar();
this.doSetupMenubar();
}

return this.container.getHTMLElement();
Expand Down