Skip to content

Commit

Permalink
Polish affordance to maximize panel
Browse files Browse the repository at this point in the history
fixes #22135
  • Loading branch information
isidorn committed Mar 14, 2017
1 parent 0f431e3 commit b41f181
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 7 deletions.
16 changes: 13 additions & 3 deletions src/vs/workbench/browser/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
private startPanelHeight: number;
private panelHeight: number;
private panelHeightBeforeMaximized: number;
private panelMaximized: boolean;
private panelWidth: number;
private layoutEditorGroupsVertically: boolean;

Expand Down Expand Up @@ -107,6 +108,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
this.toUnbind = [];
this.partLayoutInfo = this.getPartLayoutInfo();
this.panelHeightBeforeMaximized = 0;
this.panelMaximized = false;

this.sashX = new Sash(this.workbenchContainer.getHTMLElement(), this, {
baseSize: 5
Expand Down Expand Up @@ -342,9 +344,13 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
panelHeight = sidebarSize.height * DEFAULT_PANEL_HEIGHT_COEFFICIENT;
}
if (options && options.toggleMaximizedPanel) {
const heightToSwap = panelHeight;
panelHeight = panelHeight === maxPanelHeight ? Math.max(this.partLayoutInfo.panel.minHeight, Math.min(this.panelHeightBeforeMaximized, maxPanelHeight)) : maxPanelHeight;
this.panelHeightBeforeMaximized = heightToSwap;
panelHeight = this.panelMaximized ? Math.max(this.partLayoutInfo.panel.minHeight, Math.min(this.panelHeightBeforeMaximized, maxPanelHeight)) : maxPanelHeight;
}
this.panelMaximized = panelHeight === maxPanelHeight;
if (panelHeight / maxPanelHeight < 0.7) {
// Remember the previous height only if the panel size is not too large.
// To get a nice minimize effect even if a user dragged the panel sash to maximum.
this.panelHeightBeforeMaximized = panelHeight;
}
const panelDimension = new Dimension(this.workbenchSize.width - sidebarSize.width - activityBarSize.width, panelHeight);
this.panelWidth = panelDimension.width;
Expand Down Expand Up @@ -529,6 +535,10 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
return this.panelWidth;
}

public isPanelMaximized(): boolean {
return this.panelMaximized;
}

public dispose(): void {
if (this.toUnbind) {
dispose(this.toUnbind);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/vs/workbench/browser/parts/panel/media/down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/vs/workbench/browser/parts/panel/media/panelpart.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@
background: url('close.svg') center center no-repeat;
}

.monaco-workbench .maximize-panel-action {
background: url('up.svg') center center no-repeat;
}

.vs-dark .monaco-workbench .maximize-panel-action,
.hc-black .monaco-workbench .maximize-panel-action {
background: url('up-inverse.svg') center center no-repeat;
}

.monaco-workbench .minimize-panel-action {
background: url('down.svg') center center no-repeat;
}

.vs-dark .monaco-workbench .minimize-panel-action,
.hc-black .monaco-workbench .minimize-panel-action {
background: url('down-inverse.svg') center center no-repeat;
}

.vs-dark .monaco-workbench .hide-panel-action,
.hc-black .monaco-workbench .hide-panel-action {
background: url('close-inverse.svg') center center no-repeat;
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/browser/parts/panel/media/up-inverse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/vs/workbench/browser/parts/panel/media/up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions src/vs/workbench/browser/parts/panel/panelActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import 'vs/css!./media/panelpart';
import nls = require('vs/nls');
import { TPromise } from 'vs/base/common/winjs.base';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { Action } from 'vs/base/common/actions';
import { Registry } from 'vs/platform/platform';
Expand Down Expand Up @@ -113,24 +114,34 @@ class FocusPanelAction extends Action {
}
}

class ToggleMaximizedPanelAction extends Action {
export class ToggleMaximizedPanelAction extends Action {

public static ID = 'workbench.action.toggleMaximizedPanel';
public static LABEL = nls.localize('toggleMaximizedPanel', "Toggle Maximized Panel");
private toDispose: IDisposable[];

constructor(
id: string,
label: string,
@IPartService private partService: IPartService
) {
super(id, label);
super(id, label, partService.isPanelMaximized() ? 'minimize-panel-action' : 'maximize-panel-action');
this.toDispose = [];
this.toDispose.push(partService.onEditorLayout(() => {
this.class = this.partService.isPanelMaximized() ? 'minimize-panel-action' : 'maximize-panel-action';
}));
}

public run(): TPromise<any> {
// Show panel
return this.partService.setPanelHidden(false)
.then(() => this.partService.toggleMaximizedPanel());
}

public dispose(): void {
super.dispose();
this.toDispose = dispose(this.toDispose);
}
}

const actionRegistry = Registry.as<IWorkbenchActionRegistry>(WorkbenchExtensions.WorkbenchActions);
Expand Down
7 changes: 5 additions & 2 deletions src/vs/workbench/browser/parts/panel/panelPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ActionsOrientation, ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import { ClosePanelAction, PanelAction } from 'vs/workbench/browser/parts/panel/panelActions';
import { ClosePanelAction, PanelAction, ToggleMaximizedPanelAction } from 'vs/workbench/browser/parts/panel/panelActions';

export class PanelPart extends CompositePart<Panel> implements IPanelService {

Expand Down Expand Up @@ -116,7 +116,10 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
}

protected getActions(): IAction[] {
return [this.instantiationService.createInstance(ClosePanelAction, ClosePanelAction.ID, ClosePanelAction.LABEL)];
return [
this.instantiationService.createInstance(ToggleMaximizedPanelAction, ToggleMaximizedPanelAction.ID, ToggleMaximizedPanelAction.LABEL),
this.instantiationService.createInstance(ClosePanelAction, ClosePanelAction.ID, ClosePanelAction.LABEL)
];
}

public getActivePanel(): IPanel {
Expand Down
4 changes: 4 additions & 0 deletions src/vs/workbench/electron-browser/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,10 @@ export class Workbench implements IPartService {
this.workbenchLayout.layout({ toggleMaximizedPanel: true });
}

public isPanelMaximized(): boolean {
return this.workbenchLayout.isPanelMaximized();
}

public getSideBarPosition(): Position {
return this.sideBarPosition;
}
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/services/part/common/partService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ export interface IPartService {
*/
toggleMaximizedPanel(): void;

/**
* Returns true if the panel is maximized.
*/
isPanelMaximized(): boolean;

/**
* Gets the current side bar position. Note that the sidebar can be hidden too.
*/
Expand Down

0 comments on commit b41f181

Please sign in to comment.