提交 eecfb293 编写于 作者: I isidor

workbench: setPanelHidden returns a promise

上级 de712b90
......@@ -53,7 +53,7 @@ export class MainThreadOutputService extends MainThreadOutputServiceShape {
public $close(channelId: string): TPromise<void> {
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;
......
......@@ -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', () => {
......
......@@ -84,8 +84,7 @@ export abstract class TogglePanelAction extends Action {
public run(): TPromise<any> {
if (this.isPanelShowing()) {
this.partService.setPanelHidden(true);
return TPromise.as(true);
return this.partService.setPanelHidden(true);
}
return this.panelService.openPanel(this.panelId, true);
......
......@@ -80,16 +80,17 @@ export class PanelPart extends CompositePart<Panel> 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<boolean> {
this.partService.setPanelHidden(true);
return TPromise.as(true);
public run(): TPromise<any> {
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<boolean> {
this.partService.setPanelHidden(this.partService.isVisible(Parts.PANEL_PART));
return TPromise.as(true);
public run(): TPromise<any> {
return this.partService.setPanelHidden(this.partService.isVisible(Parts.PANEL_PART));
}
}
......@@ -160,21 +159,18 @@ class FocusPanelAction extends Action {
super(id, label);
}
public run(): TPromise<boolean> {
public run(): TPromise<any> {
// 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<boolean> {
public run(): TPromise<any> {
// Show panel
this.partService.setPanelHidden(false);
this.partService.toggleMaximizedPanel();
return TPromise.as(true);
return this.partService.setPanelHidden(false)
.then(() => this.partService.toggleMaximizedPanel());
}
}
......
......@@ -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<void> {
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<PanelRegistry>(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);
......
......@@ -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);
}
}
......
......@@ -85,7 +85,7 @@ export interface IPartService {
/**
* Set panel part hidden or not
*/
setPanelHidden(hidden: boolean): void;
setPanelHidden(hidden: boolean): TPromise<void>;
/**
* Maximizes the panel height if the panel is not already maximized.
......
......@@ -278,7 +278,7 @@ export class TestPartService implements IPartService {
return false;
}
public setPanelHidden(hidden: boolean): void { }
public setPanelHidden(hidden: boolean): TPromise<void> { return TPromise.as(null); }
public toggleMaximizedPanel(): void { }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册