提交 42265cd2 编写于 作者: B Benjamin Pasero

fix enablement of menu

上级 765e466a
......@@ -303,8 +303,8 @@ export class CodeApplication {
this.windowsMainService = accessor.get(IWindowsMainService);
// TODO@Joao: so ugly...
this.windowsMainService.onWindowClose(() => {
if (!platform.isMacintosh && this.windowsMainService.getWindowCount() === 0) {
this.windowsMainService.onWindowsCountChanged(e => {
if (!platform.isMacintosh && e.newCount === 0) {
this.sharedProcess.dispose();
}
});
......
......@@ -20,7 +20,7 @@ import { RunOnceScheduler } from 'vs/base/common/async';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { tildify } from 'vs/base/common/labels';
import { KeybindingsResolver } from "vs/code/electron-main/keyboard";
import { IWindowsMainService } from "vs/platform/windows/electron-main/windows";
import { IWindowsMainService, IWindowsCountChangedEvent } from "vs/platform/windows/electron-main/windows";
import { IHistoryMainService } from "vs/platform/history/common/history";
import { IWorkspaceIdentifier, IWorkspacesMainService, getWorkspaceLabel, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
......@@ -102,7 +102,7 @@ export class CodeMenu {
// Listen to some events from window service
this.historyService.onRecentlyOpenedChange(() => this.updateMenu());
this.windowsService.onWindowClose(_ => this.onClose(this.windowsService.getWindowCount()));
this.windowsService.onWindowsCountChanged(e => this.onWindowsCountChanged(e));
// Listen to extension viewlets
ipc.on('vscode:extensionViewlets', (event, rawExtensionViewlets) => {
......@@ -201,8 +201,13 @@ export class CodeMenu {
}
}
private onClose(remainingWindowCount: number): void {
if (remainingWindowCount === 0 && isMacintosh) {
private onWindowsCountChanged(e: IWindowsCountChangedEvent): void {
if (!isMacintosh) {
return;
}
// Update menu if window count goes from N > 0 or 0 > N to update menu item enablement
if ((e.oldCount === 0 && e.newCount > 0) || (e.oldCount > 0 && e.newCount === 0)) {
this.updateMenu();
}
}
......
......@@ -25,7 +25,7 @@ import CommonEvent, { Emitter } from 'vs/base/common/event';
import product from 'vs/platform/node/product';
import { ITelemetryService, ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
import { isEqual } from 'vs/base/common/paths';
import { IWindowsMainService, IOpenConfiguration } from "vs/platform/windows/electron-main/windows";
import { IWindowsMainService, IOpenConfiguration, IWindowsCountChangedEvent } from "vs/platform/windows/electron-main/windows";
import { IHistoryMainService } from "vs/platform/history/common/history";
import { IProcessEnvironment, isLinux, isMacintosh, isWindows } from 'vs/base/common/platform';
import { TPromise } from "vs/base/common/winjs.base";
......@@ -122,6 +122,9 @@ export class WindowsManager implements IWindowsMainService {
private _onWindowReload = new Emitter<number>();
onWindowReload: CommonEvent<number> = this._onWindowReload.event;
private _onWindowsCountChanged = new Emitter<IWindowsCountChangedEvent>();
onWindowsCountChanged: CommonEvent<IWindowsCountChangedEvent> = this._onWindowsCountChanged.event;
constructor(
@ILogService private logService: ILogService,
@IStorageService private storageService: IStorageService,
......@@ -970,8 +973,12 @@ export class WindowsManager implements IWindowsMainService {
isExtensionTestHost: !!configuration.extensionTestsPath
});
// Add to our list of windows
WindowsManager.WINDOWS.push(codeWindow);
// Indicate number change via event
this._onWindowsCountChanged.fire({ oldCount: WindowsManager.WINDOWS.length - 1, newCount: WindowsManager.WINDOWS.length });
// Window Events
codeWindow.win.webContents.removeAllListeners('devtools-reload-page'); // remove built in listener so we can handle this on our own
codeWindow.win.webContents.on('devtools-reload-page', () => this.reload(codeWindow));
......@@ -1293,6 +1300,7 @@ export class WindowsManager implements IWindowsMainService {
WindowsManager.WINDOWS.splice(index, 1);
// Emit
this._onWindowsCountChanged.fire({ oldCount: WindowsManager.WINDOWS.length + 1, newCount: WindowsManager.WINDOWS.length });
this._onWindowClose.fire(win.id);
}
......
......@@ -40,11 +40,17 @@ export interface ICodeWindow {
export const IWindowsMainService = createDecorator<IWindowsMainService>('windowsMainService');
export interface IWindowsCountChangedEvent {
oldCount: number;
newCount: number;
}
export interface IWindowsMainService {
_serviceBrand: any;
// events
onWindowReady: Event<ICodeWindow>;
onWindowsCountChanged: Event<IWindowsCountChangedEvent>;
onWindowClose: Event<number>;
onWindowReload: Event<number>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册