diff --git a/src/vs/workbench/api/node/mainThreadOutputService.ts b/src/vs/workbench/api/node/mainThreadOutputService.ts index 313e7c28dd1..bbaacb49b47 100644 --- a/src/vs/workbench/api/node/mainThreadOutputService.ts +++ b/src/vs/workbench/api/node/mainThreadOutputService.ts @@ -53,7 +53,7 @@ export class MainThreadOutputService extends MainThreadOutputServiceShape { public $close(channelId: string): TPromise { const panel = this._panelService.getActivePanel(); if (panel && panel.getId() === OUTPUT_PANEL_ID && channelId === this._outputService.getActiveChannel().id) { - this._partService.setPanelHidden(true); + return this._partService.setPanelHidden(true); } return undefined; diff --git a/src/vs/workbench/browser/layout.ts b/src/vs/workbench/browser/layout.ts index 14e69c320a8..95eafa2d323 100644 --- a/src/vs/workbench/browser/layout.ts +++ b/src/vs/workbench/browser/layout.ts @@ -185,6 +185,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal let doLayout = false; let isPanelVisible = this.partService.isVisible(Parts.PANEL_PART); let newSashHeight = this.startPanelHeight - (e.currentY - startY); + let promise = TPromise.as(null); // Panel visible if (isPanelVisible) { @@ -192,7 +193,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal // Automatically hide panel when a certain threshold is met if (newSashHeight + HIDE_PANEL_HEIGHT_THRESHOLD < this.computedStyles.panel.minHeight) { let dragCompensation = DEFAULT_MIN_PANEL_PART_HEIGHT - HIDE_PANEL_HEIGHT_THRESHOLD; - this.partService.setPanelHidden(true); + promise = this.partService.setPanelHidden(true); startY = Math.min(this.sidebarHeight - this.statusbarHeight - this.titlebarHeight, e.currentY + dragCompensation); this.panelHeight = this.startPanelHeight; // when restoring panel, restore to the panel height we started from } @@ -209,12 +210,12 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal if (startY - e.currentY >= this.computedStyles.panel.minHeight) { this.startPanelHeight = 0; this.panelHeight = this.computedStyles.panel.minHeight; - this.partService.setPanelHidden(false); + promise = this.partService.setPanelHidden(false); } } if (doLayout) { - this.layout(); + promise.done(() => this.layout(), errors.onUnexpectedError); } }); @@ -229,8 +230,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal this.sashY.addListener2('reset', () => { this.panelHeight = this.sidebarHeight * DEFAULT_PANEL_HEIGHT_COEFFICIENT; this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL); - this.partService.setPanelHidden(false); - this.layout(); + this.partService.setPanelHidden(false).done(() => this.layout(), errors.onUnexpectedError); }); this.sashX.addListener2('reset', () => { diff --git a/src/vs/workbench/browser/panel.ts b/src/vs/workbench/browser/panel.ts index 862686efabe..7db1606d256 100644 --- a/src/vs/workbench/browser/panel.ts +++ b/src/vs/workbench/browser/panel.ts @@ -84,8 +84,7 @@ export abstract class TogglePanelAction extends Action { public run(): TPromise { if (this.isPanelShowing()) { - this.partService.setPanelHidden(true); - return TPromise.as(true); + return this.partService.setPanelHidden(true); } return this.panelService.openPanel(this.panelId, true); diff --git a/src/vs/workbench/browser/parts/panel/panelPart.ts b/src/vs/workbench/browser/parts/panel/panelPart.ts index 5d0395fd3f5..203712c6d36 100644 --- a/src/vs/workbench/browser/parts/panel/panelPart.ts +++ b/src/vs/workbench/browser/parts/panel/panelPart.ts @@ -80,16 +80,17 @@ export class PanelPart extends CompositePart implements IPanelService { } // First check if panel is hidden and show if so + let promise = TPromise.as(null); if (!this.partService.isVisible(Parts.PANEL_PART)) { try { this.blockOpeningPanel = true; - this.partService.setPanelHidden(false); + promise = this.partService.setPanelHidden(false); } finally { this.blockOpeningPanel = false; } } - return this.openComposite(id, focus); + return promise.then(() => this.openComposite(id, focus)); } protected getActions(): IAction[] { @@ -122,9 +123,8 @@ class ClosePanelAction extends Action { super(id, name, 'hide-panel-action'); } - public run(): TPromise { - this.partService.setPanelHidden(true); - return TPromise.as(true); + public run(): TPromise { + return this.partService.setPanelHidden(true); } } @@ -140,9 +140,8 @@ export class TogglePanelAction extends ActivityAction { super(id, name, partService.isVisible(Parts.PANEL_PART) ? 'panel expanded' : 'panel'); } - public run(): TPromise { - this.partService.setPanelHidden(this.partService.isVisible(Parts.PANEL_PART)); - return TPromise.as(true); + public run(): TPromise { + return this.partService.setPanelHidden(this.partService.isVisible(Parts.PANEL_PART)); } } @@ -160,21 +159,18 @@ class FocusPanelAction extends Action { super(id, label); } - public run(): TPromise { + public run(): TPromise { // Show panel if (!this.partService.isVisible(Parts.PANEL_PART)) { - this.partService.setPanelHidden(false); + return this.partService.setPanelHidden(false); } // Focus into active panel - else { - let panel = this.panelService.getActivePanel(); - if (panel) { - panel.focus(); - } + let panel = this.panelService.getActivePanel(); + if (panel) { + panel.focus(); } - return TPromise.as(true); } } @@ -192,12 +188,10 @@ class ToggleMaximizedPanelAction extends Action { super(id, label); } - public run(): TPromise { + public run(): TPromise { // Show panel - this.partService.setPanelHidden(false); - this.partService.toggleMaximizedPanel(); - - return TPromise.as(true); + return this.partService.setPanelHidden(false) + .then(() => this.partService.toggleMaximizedPanel()); } } diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts index 387ea257d24..441ba622d0d 100644 --- a/src/vs/workbench/electron-browser/workbench.ts +++ b/src/vs/workbench/electron-browser/workbench.ts @@ -690,7 +690,6 @@ export class Workbench implements IPartService { // If sidebar becomes hidden, also hide the current active Viewlet if any if (hidden && this.sidebarPart.getActiveViewlet()) { promise = this.sidebarPart.hideActiveViewlet().then(() => { - const activeEditor = this.editorPart.getActiveEditor(); const activePanel = this.panelPart.getActivePanel(); @@ -722,7 +721,7 @@ export class Workbench implements IPartService { }); } - public setPanelHidden(hidden: boolean, skipLayout?: boolean): void { + public setPanelHidden(hidden: boolean, skipLayout?: boolean): TPromise { this.panelHidden = hidden; // Adjust CSS @@ -732,20 +731,16 @@ export class Workbench implements IPartService { this.workbench.removeClass('nopanel'); } - // Layout - if (!skipLayout) { - this.workbenchLayout.layout({ forceStyleRecompute: true }); - } - + let promise = TPromise.as(null); // If panel part becomes hidden, also hide the current active panel if any if (hidden && this.panelPart.getActivePanel()) { - this.panelPart.hideActivePanel(); - - // Pass Focus to Editor if Panel part is now hidden - const editor = this.editorPart.getActiveEditor(); - if (editor) { - editor.focus(); - } + promise = this.panelPart.hideActivePanel().then(() => { + // Pass Focus to Editor if Panel part is now hidden + const editor = this.editorPart.getActiveEditor(); + if (editor) { + editor.focus(); + } + }); } // If panel part becomes visible, show last active panel or default panel @@ -753,12 +748,19 @@ export class Workbench implements IPartService { const registry = Registry.as(PanelExtensions.Panels); const panelToOpen = this.panelPart.getLastActivePanelId() || registry.getDefaultPanelId(); if (panelToOpen) { - this.panelPart.openPanel(panelToOpen, true).done(null, errors.onUnexpectedError); + promise = this.panelPart.openPanel(panelToOpen, true); } } - // Remember in settings - this.storageService.store(Workbench.panelHiddenSettingKey, hidden ? 'true' : 'false', StorageScope.WORKSPACE); + return promise.then(() => { + // Remember in settings + this.storageService.store(Workbench.panelHiddenSettingKey, hidden ? 'true' : 'false', StorageScope.WORKSPACE); + + // Layout + if (!skipLayout) { + this.workbenchLayout.layout({ forceStyleRecompute: true }); + } + }); } public toggleMaximizedPanel(): void { @@ -1076,7 +1078,7 @@ export class Workbench implements IPartService { this.zenMode.transitionedToFullScreen = toggleFullScreen; this.zenMode.wasSideBarVisible = this.isVisible(Parts.SIDEBAR_PART); this.zenMode.wasPanelVisible = this.isVisible(Parts.PANEL_PART); - this.setPanelHidden(true, true); + this.setPanelHidden(true, true).done(undefined, errors.onUnexpectedError); this.setSideBarHidden(true, true).done(undefined, errors.onUnexpectedError); this.setActivityBarHidden(true, true); @@ -1088,7 +1090,7 @@ export class Workbench implements IPartService { } } else { if (this.zenMode.wasPanelVisible) { - this.setPanelHidden(false, true); + this.setPanelHidden(false, true).done(undefined, errors.onUnexpectedError); } if (this.zenMode.wasSideBarVisible) { this.setSideBarHidden(false, true).done(undefined, errors.onUnexpectedError); diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts index 23bb2c568b4..0bd64f2bfbd 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import Event, { Emitter } from 'vs/base/common/event'; +import * as errors from 'vs/base/common/errors'; import platform = require('vs/base/common/platform'); import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; @@ -189,7 +190,7 @@ export class TerminalService implements ITerminalService { public hidePanel(): void { const panel = this._panelService.getActivePanel(); if (panel && panel.getId() === TERMINAL_PANEL_ID) { - this._partService.setPanelHidden(true); + this._partService.setPanelHidden(true).done(undefined, errors.onUnexpectedError); } } diff --git a/src/vs/workbench/services/part/common/partService.ts b/src/vs/workbench/services/part/common/partService.ts index 35efde29427..c67e28794e8 100644 --- a/src/vs/workbench/services/part/common/partService.ts +++ b/src/vs/workbench/services/part/common/partService.ts @@ -85,7 +85,7 @@ export interface IPartService { /** * Set panel part hidden or not */ - setPanelHidden(hidden: boolean): void; + setPanelHidden(hidden: boolean): TPromise; /** * Maximizes the panel height if the panel is not already maximized. diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index 1666da5e5ef..a336de3b3e7 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -278,7 +278,7 @@ export class TestPartService implements IPartService { return false; } - public setPanelHidden(hidden: boolean): void { } + public setPanelHidden(hidden: boolean): TPromise { return TPromise.as(null); } public toggleMaximizedPanel(): void { }