提交 eecfb293 编写于 作者: I isidor

workbench: setPanelHidden returns a promise

上级 de712b90
...@@ -53,7 +53,7 @@ export class MainThreadOutputService extends MainThreadOutputServiceShape { ...@@ -53,7 +53,7 @@ export class MainThreadOutputService extends MainThreadOutputServiceShape {
public $close(channelId: string): TPromise<void> { public $close(channelId: string): TPromise<void> {
const panel = this._panelService.getActivePanel(); const panel = this._panelService.getActivePanel();
if (panel && panel.getId() === OUTPUT_PANEL_ID && channelId === this._outputService.getActiveChannel().id) { if (panel && panel.getId() === OUTPUT_PANEL_ID && channelId === this._outputService.getActiveChannel().id) {
this._partService.setPanelHidden(true); return this._partService.setPanelHidden(true);
} }
return undefined; return undefined;
......
...@@ -185,6 +185,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal ...@@ -185,6 +185,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
let doLayout = false; let doLayout = false;
let isPanelVisible = this.partService.isVisible(Parts.PANEL_PART); let isPanelVisible = this.partService.isVisible(Parts.PANEL_PART);
let newSashHeight = this.startPanelHeight - (e.currentY - startY); let newSashHeight = this.startPanelHeight - (e.currentY - startY);
let promise = TPromise.as(null);
// Panel visible // Panel visible
if (isPanelVisible) { if (isPanelVisible) {
...@@ -192,7 +193,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal ...@@ -192,7 +193,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
// Automatically hide panel when a certain threshold is met // Automatically hide panel when a certain threshold is met
if (newSashHeight + HIDE_PANEL_HEIGHT_THRESHOLD < this.computedStyles.panel.minHeight) { if (newSashHeight + HIDE_PANEL_HEIGHT_THRESHOLD < this.computedStyles.panel.minHeight) {
let dragCompensation = DEFAULT_MIN_PANEL_PART_HEIGHT - HIDE_PANEL_HEIGHT_THRESHOLD; 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); 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 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 ...@@ -209,12 +210,12 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
if (startY - e.currentY >= this.computedStyles.panel.minHeight) { if (startY - e.currentY >= this.computedStyles.panel.minHeight) {
this.startPanelHeight = 0; this.startPanelHeight = 0;
this.panelHeight = this.computedStyles.panel.minHeight; this.panelHeight = this.computedStyles.panel.minHeight;
this.partService.setPanelHidden(false); promise = this.partService.setPanelHidden(false);
} }
} }
if (doLayout) { if (doLayout) {
this.layout(); promise.done(() => this.layout(), errors.onUnexpectedError);
} }
}); });
...@@ -229,8 +230,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal ...@@ -229,8 +230,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
this.sashY.addListener2('reset', () => { this.sashY.addListener2('reset', () => {
this.panelHeight = this.sidebarHeight * DEFAULT_PANEL_HEIGHT_COEFFICIENT; this.panelHeight = this.sidebarHeight * DEFAULT_PANEL_HEIGHT_COEFFICIENT;
this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL); this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
this.partService.setPanelHidden(false); this.partService.setPanelHidden(false).done(() => this.layout(), errors.onUnexpectedError);
this.layout();
}); });
this.sashX.addListener2('reset', () => { this.sashX.addListener2('reset', () => {
......
...@@ -84,8 +84,7 @@ export abstract class TogglePanelAction extends Action { ...@@ -84,8 +84,7 @@ export abstract class TogglePanelAction extends Action {
public run(): TPromise<any> { public run(): TPromise<any> {
if (this.isPanelShowing()) { if (this.isPanelShowing()) {
this.partService.setPanelHidden(true); return this.partService.setPanelHidden(true);
return TPromise.as(true);
} }
return this.panelService.openPanel(this.panelId, true); return this.panelService.openPanel(this.panelId, true);
......
...@@ -80,16 +80,17 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService { ...@@ -80,16 +80,17 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
} }
// First check if panel is hidden and show if so // First check if panel is hidden and show if so
let promise = TPromise.as(null);
if (!this.partService.isVisible(Parts.PANEL_PART)) { if (!this.partService.isVisible(Parts.PANEL_PART)) {
try { try {
this.blockOpeningPanel = true; this.blockOpeningPanel = true;
this.partService.setPanelHidden(false); promise = this.partService.setPanelHidden(false);
} finally { } finally {
this.blockOpeningPanel = false; this.blockOpeningPanel = false;
} }
} }
return this.openComposite(id, focus); return promise.then(() => this.openComposite(id, focus));
} }
protected getActions(): IAction[] { protected getActions(): IAction[] {
...@@ -122,9 +123,8 @@ class ClosePanelAction extends Action { ...@@ -122,9 +123,8 @@ class ClosePanelAction extends Action {
super(id, name, 'hide-panel-action'); super(id, name, 'hide-panel-action');
} }
public run(): TPromise<boolean> { public run(): TPromise<any> {
this.partService.setPanelHidden(true); return this.partService.setPanelHidden(true);
return TPromise.as(true);
} }
} }
...@@ -140,9 +140,8 @@ export class TogglePanelAction extends ActivityAction { ...@@ -140,9 +140,8 @@ export class TogglePanelAction extends ActivityAction {
super(id, name, partService.isVisible(Parts.PANEL_PART) ? 'panel expanded' : 'panel'); super(id, name, partService.isVisible(Parts.PANEL_PART) ? 'panel expanded' : 'panel');
} }
public run(): TPromise<boolean> { public run(): TPromise<any> {
this.partService.setPanelHidden(this.partService.isVisible(Parts.PANEL_PART)); return this.partService.setPanelHidden(this.partService.isVisible(Parts.PANEL_PART));
return TPromise.as(true);
} }
} }
...@@ -160,21 +159,18 @@ class FocusPanelAction extends Action { ...@@ -160,21 +159,18 @@ class FocusPanelAction extends Action {
super(id, label); super(id, label);
} }
public run(): TPromise<boolean> { public run(): TPromise<any> {
// Show panel // Show panel
if (!this.partService.isVisible(Parts.PANEL_PART)) { if (!this.partService.isVisible(Parts.PANEL_PART)) {
this.partService.setPanelHidden(false); return this.partService.setPanelHidden(false);
} }
// Focus into active panel // Focus into active panel
else { let panel = this.panelService.getActivePanel();
let panel = this.panelService.getActivePanel(); if (panel) {
if (panel) { panel.focus();
panel.focus();
}
} }
return TPromise.as(true); return TPromise.as(true);
} }
} }
...@@ -192,12 +188,10 @@ class ToggleMaximizedPanelAction extends Action { ...@@ -192,12 +188,10 @@ class ToggleMaximizedPanelAction extends Action {
super(id, label); super(id, label);
} }
public run(): TPromise<boolean> { public run(): TPromise<any> {
// Show panel // Show panel
this.partService.setPanelHidden(false); return this.partService.setPanelHidden(false)
this.partService.toggleMaximizedPanel(); .then(() => this.partService.toggleMaximizedPanel());
return TPromise.as(true);
} }
} }
......
...@@ -690,7 +690,6 @@ export class Workbench implements IPartService { ...@@ -690,7 +690,6 @@ export class Workbench implements IPartService {
// If sidebar becomes hidden, also hide the current active Viewlet if any // If sidebar becomes hidden, also hide the current active Viewlet if any
if (hidden && this.sidebarPart.getActiveViewlet()) { if (hidden && this.sidebarPart.getActiveViewlet()) {
promise = this.sidebarPart.hideActiveViewlet().then(() => { promise = this.sidebarPart.hideActiveViewlet().then(() => {
const activeEditor = this.editorPart.getActiveEditor(); const activeEditor = this.editorPart.getActiveEditor();
const activePanel = this.panelPart.getActivePanel(); const activePanel = this.panelPart.getActivePanel();
...@@ -722,7 +721,7 @@ export class Workbench implements IPartService { ...@@ -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; this.panelHidden = hidden;
// Adjust CSS // Adjust CSS
...@@ -732,20 +731,16 @@ export class Workbench implements IPartService { ...@@ -732,20 +731,16 @@ export class Workbench implements IPartService {
this.workbench.removeClass('nopanel'); this.workbench.removeClass('nopanel');
} }
// Layout let promise = TPromise.as(null);
if (!skipLayout) {
this.workbenchLayout.layout({ forceStyleRecompute: true });
}
// If panel part becomes hidden, also hide the current active panel if any // If panel part becomes hidden, also hide the current active panel if any
if (hidden && this.panelPart.getActivePanel()) { if (hidden && this.panelPart.getActivePanel()) {
this.panelPart.hideActivePanel(); promise = this.panelPart.hideActivePanel().then(() => {
// Pass Focus to Editor if Panel part is now hidden
// Pass Focus to Editor if Panel part is now hidden const editor = this.editorPart.getActiveEditor();
const editor = this.editorPart.getActiveEditor(); if (editor) {
if (editor) { editor.focus();
editor.focus(); }
} });
} }
// If panel part becomes visible, show last active panel or default panel // If panel part becomes visible, show last active panel or default panel
...@@ -753,12 +748,19 @@ export class Workbench implements IPartService { ...@@ -753,12 +748,19 @@ export class Workbench implements IPartService {
const registry = Registry.as<PanelRegistry>(PanelExtensions.Panels); const registry = Registry.as<PanelRegistry>(PanelExtensions.Panels);
const panelToOpen = this.panelPart.getLastActivePanelId() || registry.getDefaultPanelId(); const panelToOpen = this.panelPart.getLastActivePanelId() || registry.getDefaultPanelId();
if (panelToOpen) { if (panelToOpen) {
this.panelPart.openPanel(panelToOpen, true).done(null, errors.onUnexpectedError); promise = this.panelPart.openPanel(panelToOpen, true);
} }
} }
// Remember in settings return promise.then(() => {
this.storageService.store(Workbench.panelHiddenSettingKey, hidden ? 'true' : 'false', StorageScope.WORKSPACE); // Remember in settings
this.storageService.store(Workbench.panelHiddenSettingKey, hidden ? 'true' : 'false', StorageScope.WORKSPACE);
// Layout
if (!skipLayout) {
this.workbenchLayout.layout({ forceStyleRecompute: true });
}
});
} }
public toggleMaximizedPanel(): void { public toggleMaximizedPanel(): void {
...@@ -1076,7 +1078,7 @@ export class Workbench implements IPartService { ...@@ -1076,7 +1078,7 @@ export class Workbench implements IPartService {
this.zenMode.transitionedToFullScreen = toggleFullScreen; this.zenMode.transitionedToFullScreen = toggleFullScreen;
this.zenMode.wasSideBarVisible = this.isVisible(Parts.SIDEBAR_PART); this.zenMode.wasSideBarVisible = this.isVisible(Parts.SIDEBAR_PART);
this.zenMode.wasPanelVisible = this.isVisible(Parts.PANEL_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.setSideBarHidden(true, true).done(undefined, errors.onUnexpectedError);
this.setActivityBarHidden(true, true); this.setActivityBarHidden(true, true);
...@@ -1088,7 +1090,7 @@ export class Workbench implements IPartService { ...@@ -1088,7 +1090,7 @@ export class Workbench implements IPartService {
} }
} else { } else {
if (this.zenMode.wasPanelVisible) { if (this.zenMode.wasPanelVisible) {
this.setPanelHidden(false, true); this.setPanelHidden(false, true).done(undefined, errors.onUnexpectedError);
} }
if (this.zenMode.wasSideBarVisible) { if (this.zenMode.wasSideBarVisible) {
this.setSideBarHidden(false, true).done(undefined, errors.onUnexpectedError); this.setSideBarHidden(false, true).done(undefined, errors.onUnexpectedError);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import Event, { Emitter } from 'vs/base/common/event'; import Event, { Emitter } from 'vs/base/common/event';
import * as errors from 'vs/base/common/errors';
import platform = require('vs/base/common/platform'); import platform = require('vs/base/common/platform');
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
...@@ -189,7 +190,7 @@ export class TerminalService implements ITerminalService { ...@@ -189,7 +190,7 @@ export class TerminalService implements ITerminalService {
public hidePanel(): void { public hidePanel(): void {
const panel = this._panelService.getActivePanel(); const panel = this._panelService.getActivePanel();
if (panel && panel.getId() === TERMINAL_PANEL_ID) { 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 { ...@@ -85,7 +85,7 @@ export interface IPartService {
/** /**
* Set panel part hidden or not * 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. * Maximizes the panel height if the panel is not already maximized.
......
...@@ -278,7 +278,7 @@ export class TestPartService implements IPartService { ...@@ -278,7 +278,7 @@ export class TestPartService implements IPartService {
return false; return false;
} }
public setPanelHidden(hidden: boolean): void { } public setPanelHidden(hidden: boolean): TPromise<void> { return TPromise.as(null); }
public toggleMaximizedPanel(): void { } public toggleMaximizedPanel(): void { }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册