Skip to content

Commit 42265cd

Browse files
author
Benjamin Pasero
committed
fix enablement of menu
1 parent 765e466 commit 42265cd

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

src/vs/code/electron-main/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ export class CodeApplication {
303303
this.windowsMainService = accessor.get(IWindowsMainService);
304304

305305
// TODO@Joao: so ugly...
306-
this.windowsMainService.onWindowClose(() => {
307-
if (!platform.isMacintosh && this.windowsMainService.getWindowCount() === 0) {
306+
this.windowsMainService.onWindowsCountChanged(e => {
307+
if (!platform.isMacintosh && e.newCount === 0) {
308308
this.sharedProcess.dispose();
309309
}
310310
});

src/vs/code/electron-main/menus.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { RunOnceScheduler } from 'vs/base/common/async';
2020
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2121
import { tildify } from 'vs/base/common/labels';
2222
import { KeybindingsResolver } from "vs/code/electron-main/keyboard";
23-
import { IWindowsMainService } from "vs/platform/windows/electron-main/windows";
23+
import { IWindowsMainService, IWindowsCountChangedEvent } from "vs/platform/windows/electron-main/windows";
2424
import { IHistoryMainService } from "vs/platform/history/common/history";
2525
import { IWorkspaceIdentifier, IWorkspacesMainService, getWorkspaceLabel, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
2626

@@ -102,7 +102,7 @@ export class CodeMenu {
102102

103103
// Listen to some events from window service
104104
this.historyService.onRecentlyOpenedChange(() => this.updateMenu());
105-
this.windowsService.onWindowClose(_ => this.onClose(this.windowsService.getWindowCount()));
105+
this.windowsService.onWindowsCountChanged(e => this.onWindowsCountChanged(e));
106106

107107
// Listen to extension viewlets
108108
ipc.on('vscode:extensionViewlets', (event, rawExtensionViewlets) => {
@@ -201,8 +201,13 @@ export class CodeMenu {
201201
}
202202
}
203203

204-
private onClose(remainingWindowCount: number): void {
205-
if (remainingWindowCount === 0 && isMacintosh) {
204+
private onWindowsCountChanged(e: IWindowsCountChangedEvent): void {
205+
if (!isMacintosh) {
206+
return;
207+
}
208+
209+
// Update menu if window count goes from N > 0 or 0 > N to update menu item enablement
210+
if ((e.oldCount === 0 && e.newCount > 0) || (e.oldCount > 0 && e.newCount === 0)) {
206211
this.updateMenu();
207212
}
208213
}

src/vs/code/electron-main/windows.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import CommonEvent, { Emitter } from 'vs/base/common/event';
2525
import product from 'vs/platform/node/product';
2626
import { ITelemetryService, ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
2727
import { isEqual } from 'vs/base/common/paths';
28-
import { IWindowsMainService, IOpenConfiguration } from "vs/platform/windows/electron-main/windows";
28+
import { IWindowsMainService, IOpenConfiguration, IWindowsCountChangedEvent } from "vs/platform/windows/electron-main/windows";
2929
import { IHistoryMainService } from "vs/platform/history/common/history";
3030
import { IProcessEnvironment, isLinux, isMacintosh, isWindows } from 'vs/base/common/platform';
3131
import { TPromise } from "vs/base/common/winjs.base";
@@ -122,6 +122,9 @@ export class WindowsManager implements IWindowsMainService {
122122
private _onWindowReload = new Emitter<number>();
123123
onWindowReload: CommonEvent<number> = this._onWindowReload.event;
124124

125+
private _onWindowsCountChanged = new Emitter<IWindowsCountChangedEvent>();
126+
onWindowsCountChanged: CommonEvent<IWindowsCountChangedEvent> = this._onWindowsCountChanged.event;
127+
125128
constructor(
126129
@ILogService private logService: ILogService,
127130
@IStorageService private storageService: IStorageService,
@@ -970,8 +973,12 @@ export class WindowsManager implements IWindowsMainService {
970973
isExtensionTestHost: !!configuration.extensionTestsPath
971974
});
972975

976+
// Add to our list of windows
973977
WindowsManager.WINDOWS.push(codeWindow);
974978

979+
// Indicate number change via event
980+
this._onWindowsCountChanged.fire({ oldCount: WindowsManager.WINDOWS.length - 1, newCount: WindowsManager.WINDOWS.length });
981+
975982
// Window Events
976983
codeWindow.win.webContents.removeAllListeners('devtools-reload-page'); // remove built in listener so we can handle this on our own
977984
codeWindow.win.webContents.on('devtools-reload-page', () => this.reload(codeWindow));
@@ -1293,6 +1300,7 @@ export class WindowsManager implements IWindowsMainService {
12931300
WindowsManager.WINDOWS.splice(index, 1);
12941301

12951302
// Emit
1303+
this._onWindowsCountChanged.fire({ oldCount: WindowsManager.WINDOWS.length + 1, newCount: WindowsManager.WINDOWS.length });
12961304
this._onWindowClose.fire(win.id);
12971305
}
12981306

src/vs/platform/windows/electron-main/windows.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,17 @@ export interface ICodeWindow {
4040

4141
export const IWindowsMainService = createDecorator<IWindowsMainService>('windowsMainService');
4242

43+
export interface IWindowsCountChangedEvent {
44+
oldCount: number;
45+
newCount: number;
46+
}
47+
4348
export interface IWindowsMainService {
4449
_serviceBrand: any;
4550

4651
// events
4752
onWindowReady: Event<ICodeWindow>;
53+
onWindowsCountChanged: Event<IWindowsCountChangedEvent>;
4854
onWindowClose: Event<number>;
4955
onWindowReload: Event<number>;
5056

0 commit comments

Comments
 (0)