From 2a322c061566e96718716366aea944fce9316f34 Mon Sep 17 00:00:00 2001 From: isidor Date: Fri, 14 Oct 2016 12:33:32 +0200 Subject: [PATCH] Toggle Maximized Panel fixes #7314 --- src/vs/test/utils/servicesTestUtils.ts | 2 ++ src/vs/workbench/browser/layout.ts | 8 +++++-- .../browser/parts/panel/panelPart.ts | 23 +++++++++++++++++++ .../workbench/electron-browser/workbench.ts | 4 ++++ .../services/part/common/partService.ts | 6 +++++ 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/vs/test/utils/servicesTestUtils.ts b/src/vs/test/utils/servicesTestUtils.ts index 644df848f07b8..65bcd65c28809 100644 --- a/src/vs/test/utils/servicesTestUtils.ts +++ b/src/vs/test/utils/servicesTestUtils.ts @@ -250,6 +250,8 @@ export class TestPartService implements IPartService { public setPanelHidden(hidden: boolean): void { } + public toggleMaximizedPanel(): void { } + public getSideBarPosition() { return 0; } diff --git a/src/vs/workbench/browser/layout.ts b/src/vs/workbench/browser/layout.ts index c04affa7cceff..a478f827bbebc 100644 --- a/src/vs/workbench/browser/layout.ts +++ b/src/vs/workbench/browser/layout.ts @@ -297,7 +297,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal }; } - public layout(forceStyleReCompute?: boolean): void { + public layout(forceStyleReCompute?: boolean, toggleMaximizedPanel?: boolean): void { if (forceStyleReCompute) { this.computeStyle(); this.editor.getLayout().computeStyle(); @@ -338,13 +338,17 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal // Panel part let panelHeight: number; + const maxPanelHeight = sidebarSize.height - DEFAULT_MIN_EDITOR_PART_HEIGHT; if (isPanelHidden) { panelHeight = 0; } else if (this.panelHeight > 0) { - panelHeight = Math.min(sidebarSize.height - DEFAULT_MIN_EDITOR_PART_HEIGHT, Math.max(this.computedStyles.panel.minHeight, this.panelHeight)); + panelHeight = Math.min(maxPanelHeight, Math.max(this.computedStyles.panel.minHeight, this.panelHeight)); } else { panelHeight = sidebarSize.height * 0.4; } + if (toggleMaximizedPanel) { + panelHeight = panelHeight === maxPanelHeight ? sidebarSize.height * 0.4 : maxPanelHeight; + } const panelDimension = new Dimension(this.workbenchSize.width - sidebarSize.width - activityBarSize.width, panelHeight); this.panelWidth = panelDimension.width; diff --git a/src/vs/workbench/browser/parts/panel/panelPart.ts b/src/vs/workbench/browser/parts/panel/panelPart.ts index 16a2d79688971..207a1196226a4 100644 --- a/src/vs/workbench/browser/parts/panel/panelPart.ts +++ b/src/vs/workbench/browser/parts/panel/panelPart.ts @@ -179,6 +179,29 @@ class FocusPanelAction extends Action { } } +class ToggleMaximizedPanelAction extends Action { + + public static ID = 'workbench.action.toggleMaximizedPanel'; + public static LABEL = nls.localize('toggleMaximizedPanel', "Toggle Maximized Panel"); + + constructor( + id: string, + label: string, + @IPartService private partService: IPartService + ) { + super(id, label); + } + + public run(): TPromise { + // Show panel + this.partService.setPanelHidden(false); + this.partService.toggleMaximizedPanel(); + + return TPromise.as(true); + } +} + let actionRegistry = Registry.as(WorkbenchExtensions.WorkbenchActions); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(TogglePanelAction, TogglePanelAction.ID, TogglePanelAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_J }), 'View: Toggle Panel Visibility', nls.localize('view', "View")); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(FocusPanelAction, FocusPanelAction.ID, FocusPanelAction.LABEL), 'View: Focus into Panel', nls.localize('view', "View")); +actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleMaximizedPanelAction, ToggleMaximizedPanelAction.ID, ToggleMaximizedPanelAction.LABEL), 'View: Toggle Maximized Panel', nls.localize('view', "View")); diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts index 2a50aa07d470e..8fc45ce1e2223 100644 --- a/src/vs/workbench/electron-browser/workbench.ts +++ b/src/vs/workbench/electron-browser/workbench.ts @@ -613,6 +613,10 @@ export class Workbench implements IPartService { this.storageService.store(Workbench.panelHiddenSettingKey, hidden ? 'true' : 'false', StorageScope.WORKSPACE); } + public toggleMaximizedPanel(): void { + this.workbenchLayout.layout(true, true); + } + public getSideBarPosition(): Position { return this.sideBarPosition; } diff --git a/src/vs/workbench/services/part/common/partService.ts b/src/vs/workbench/services/part/common/partService.ts index 256781a7224e8..d93012823792b 100644 --- a/src/vs/workbench/services/part/common/partService.ts +++ b/src/vs/workbench/services/part/common/partService.ts @@ -80,6 +80,12 @@ export interface IPartService { */ setPanelHidden(hidden: boolean): void; + /** + * Maximizes the panel height if the panel is not already maximized. + * Shrinks the panel to the default starting size if the panel is maximized. + */ + toggleMaximizedPanel(): void; + /** * Gets the current side bar position. Note that the sidebar can be hidden too. */