提交 d7245d6a 编写于 作者: I isidor

bring back the crowd favorite maximized panel action

上级 47e1c932
......@@ -11,7 +11,7 @@ import { Part } from 'vs/workbench/browser/part';
import { QuickOpenController } from 'vs/workbench/browser/parts/quickopen/quickOpenController';
import { Sash, ISashEvent, IVerticalSashLayoutProvider, IHorizontalSashLayoutProvider, Orientation } from 'vs/base/browser/ui/sash/sash';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IPartService, Position, Parts } from 'vs/workbench/services/part/common/partService';
import { IPartService, Position, ILayoutOptions, Parts } from 'vs/workbench/services/part/common/partService';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
......@@ -26,6 +26,7 @@ const MIN_EDITOR_PART_WIDTH = 220;
const MIN_PANEL_PART_HEIGHT = 77;
const MIN_PANEL_PART_WIDTH = 300;
const DEFAULT_PANEL_SIZE_COEFFICIENT = 0.4;
const PANEL_SIZE_BEFORE_MAXIMIZED_BOUNDARY = 0.7;
const HIDE_SIDEBAR_WIDTH_THRESHOLD = 50;
const HIDE_PANEL_HEIGHT_THRESHOLD = 50;
const HIDE_PANEL_WIDTH_THRESHOLD = 100;
......@@ -70,6 +71,8 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
private sidebarHeight: number;
private titlebarHeight: number;
private statusbarHeight: number;
private panelSizeBeforeMaximized: number;
private panelMaximized: boolean;
private _panelHeight: number;
private _panelWidth: number;
private layoutEditorGroupsVertically: boolean;
......@@ -106,6 +109,8 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
this.quickopen = quickopen;
this.toUnbind = [];
this.partLayoutInfo = this.getPartLayoutInfo();
this.panelSizeBeforeMaximized = 0;
this.panelMaximized = false;
this.sashXOne = new Sash(this.workbenchContainer.getHTMLElement(), this, {
baseSize: 5
......@@ -412,7 +417,7 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
}
}
public layout(): void {
public layout(options?: ILayoutOptions): void {
this.workbenchSize = this.parent.getClientArea();
const isActivityBarHidden = !this.partService.isVisible(Parts.ACTIVITYBAR_PART);
......@@ -442,8 +447,9 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
let panelHeight: number;
let panelWidth: number;
const editorCountForHeight = this.editorGroupService.getGroupOrientation() === 'horizontal' ? this.editorGroupService.getStacksModel().groups.length : 1;
const editorCountForWidth = this.editorGroupService.getGroupOrientation() === 'vertical' ? this.editorGroupService.getStacksModel().groups.length : 1;
const maxPanelHeight = sidebarSize.height - editorCountForHeight * MIN_EDITOR_PART_HEIGHT;
const maxPanelWidth = this.workbenchSize.width - activityBarSize.width - sidebarSize.width - editorCountForHeight * MIN_EDITOR_PART_WIDTH;
const maxPanelWidth = this.workbenchSize.width - activityBarSize.width - sidebarSize.width - editorCountForWidth * MIN_EDITOR_PART_WIDTH;
if (isPanelHidden) {
panelHeight = 0;
......@@ -456,8 +462,16 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
} else {
panelHeight = sidebarSize.height * DEFAULT_PANEL_SIZE_COEFFICIENT;
}
panelWidth = this.workbenchSize.width - sidebarSize.width - activityBarSize.width;
if (options && options.toggleMaximizedPanel) {
panelHeight = this.panelMaximized ? Math.max(this.partLayoutInfo.panel.minHeight, Math.min(this.panelSizeBeforeMaximized, maxPanelHeight)) : maxPanelHeight;
}
this.panelMaximized = panelHeight === maxPanelHeight;
if (panelHeight / maxPanelHeight < PANEL_SIZE_BEFORE_MAXIMIZED_BOUNDARY) {
this.panelSizeBeforeMaximized = panelHeight;
}
} else {
panelHeight = sidebarSize.height;
if (this.panelWidth > 0) {
......@@ -465,6 +479,15 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
} else {
panelWidth = (this.workbenchSize.width - activityBarSize.width - sidebarSize.width) * DEFAULT_PANEL_SIZE_COEFFICIENT;
}
if (options && options.toggleMaximizedPanel) {
panelWidth = this.panelMaximized ? Math.max(this.partLayoutInfo.panel.minWidth, Math.min(this.panelSizeBeforeMaximized, maxPanelWidth)) : maxPanelWidth;
}
this.panelMaximized = panelWidth === maxPanelWidth;
if (panelWidth / maxPanelWidth < PANEL_SIZE_BEFORE_MAXIMIZED_BOUNDARY) {
this.panelSizeBeforeMaximized = panelWidth;
}
}
const panelDimension = new Dimension(panelWidth, panelHeight);
......@@ -663,6 +686,10 @@ export class WorkbenchLayout implements IVerticalSashLayoutProvider, IHorizontal
return this.panelWidth;
}
public isPanelMaximized(): boolean {
return this.panelMaximized;
}
// change part size along the main axis
public resizePart(part: Parts, sizeChange: number): void {
const visibleEditors = this.editorService.getVisibleEditors().length;
......
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#2d2d30}.icon-vs-out{fill:#2d2d30}.icon-vs-bg{fill:#c5c5c5}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M.379 5.652l2.828-2.828 4.76 4.761 4.826-4.826 2.828 2.828-7.654 7.654L.379 5.652z" id="outline" style="display: none;"/><g id="iconBg"><path class="icon-vs-bg" d="M7.967 11.827L1.793 5.652l1.414-1.414 4.76 4.761 4.826-4.826 1.414 1.414-6.24 6.24z"/></g></svg>
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#f6f6f6}.icon-vs-out{fill:#f6f6f6}.icon-vs-bg{fill:#424242}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M.379 5.652l2.828-2.828 4.76 4.761 4.826-4.826 2.828 2.828-7.654 7.654L.379 5.652z" id="outline" style="display: none;"/><g id="iconBg"><path class="icon-vs-bg" d="M7.967 11.827L1.793 5.652l1.414-1.414 4.76 4.761 4.826-4.826 1.414 1.414-6.24 6.24z"/></g></svg>
\ No newline at end of file
......@@ -96,6 +96,32 @@
background: url('close.svg') center center no-repeat;
}
.monaco-workbench .maximize-panel-action {
background: url('up.svg') center center no-repeat;
}
.monaco-workbench .panel.right .maximize-panel-action {
transform: rotate(-90deg);
}
.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;
}
.monaco-workbench .panel.right .minimize-panel-action {
transform: rotate(-90deg);
}
.vs-dark .monaco-workbench .minimize-panel-action,
.hc-black .monaco-workbench .minimize-panel-action {
background: url('down-inverse.svg') center center no-repeat;
}
.monaco-workbench .move-panel-to-right {
background: url('panel-right.svg') center center no-repeat;
}
......
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#2d2d30}.icon-vs-out{fill:#2d2d30}.icon-vs-bg{fill:#c5c5c5}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M7.967 2.759l7.654 7.654-2.828 2.828-4.826-4.826-4.76 4.761-2.828-2.828 7.588-7.589z" id="outline" style="display: none;"/><g id="iconBg"><path class="icon-vs-bg" d="M14.207 10.413l-1.414 1.414-4.826-4.826-4.76 4.761-1.414-1.414 6.174-6.175 6.24 6.24z"/></g></svg>
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#f6f6f6}.icon-vs-out{fill:#f6f6f6}.icon-vs-bg{fill:#424242}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M7.967 2.759l7.654 7.654-2.828 2.828-4.826-4.826-4.76 4.761-2.828-2.828 7.588-7.589z" id="outline" style="display: none;"/><g id="iconBg"><path class="icon-vs-bg" d="M14.207 10.413l-1.414 1.414-4.826-4.826-4.76 4.761-1.414-1.414 6.174-6.175 6.24 6.24z"/></g></svg>
\ No newline at end of file
......@@ -120,8 +120,38 @@ export class TogglePanelPositionAction extends Action {
}
}
class ToggleMaximizedPanelAction extends TogglePanelPositionAction {
export class ToggleMaximizedPanelAction extends Action {
public static ID = 'workbench.action.toggleMaximizedPanel';
public static LABEL = nls.localize('toggleMaximizedPanel', "Toggle Maximized Panel");
private static MAXIMIZE_LABEL = nls.localize('maximizePanel', "Maximize Panel Size");
private static RESTORE_LABEL = nls.localize('minimizePanel', "Restore Panel Size");
private toDispose: IDisposable[];
constructor(
id: string,
label: string,
@IPartService private partService: IPartService
) {
super(id, label, partService.isPanelMaximized() ? 'minimize-panel-action' : 'maximize-panel-action');
this.toDispose = [];
this.toDispose.push(partService.onEditorLayout(() => {
const maximized = this.partService.isPanelMaximized();
this.class = maximized ? 'minimize-panel-action' : 'maximize-panel-action';
this.label = maximized ? ToggleMaximizedPanelAction.RESTORE_LABEL : ToggleMaximizedPanelAction.MAXIMIZE_LABEL;
}));
}
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);
}
}
export class PanelActivityAction extends ActivityAction {
......@@ -141,6 +171,7 @@ export class PanelActivityAction extends ActivityAction {
const actionRegistry = Registry.as<IWorkbenchActionRegistry>(WorkbenchExtensions.WorkbenchActions);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(TogglePanelAction, TogglePanelAction.ID, TogglePanelAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_J }), 'View: Toggle Panel', 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"));
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ClosePanelAction, ClosePanelAction.ID, ClosePanelAction.LABEL), 'View: Close Panel', nls.localize('view', "View"));
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(TogglePanelPositionAction, TogglePanelPositionAction.ID, TogglePanelPositionAction.LABEL), 'View: Toggle Panel Position', nls.localize('view', "View"));
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleMaximizedPanelAction, ToggleMaximizedPanelAction.ID, undefined), 'View: Toggle Panel Position', nls.localize('view', "View"));
......@@ -22,7 +22,7 @@ import { IMessageService } from 'vs/platform/message/common/message';
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 { ClosePanelAction, TogglePanelPositionAction, PanelActivityAction } from 'vs/workbench/browser/parts/panel/panelActions';
import { ClosePanelAction, TogglePanelPositionAction, PanelActivityAction, ToggleMaximizedPanelAction } from 'vs/workbench/browser/parts/panel/panelActions';
import { IThemeService, registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
import { PANEL_BACKGROUND, PANEL_BORDER, PANEL_ACTIVE_TITLE_FOREGROUND, PANEL_INACTIVE_TITLE_FOREGROUND, PANEL_ACTIVE_TITLE_BORDER, PANEL_DRAG_AND_DROP_BACKGROUND } from 'vs/workbench/common/theme';
import { activeContrastBorder, focusBorder, contrastBorder, editorBackground, badgeBackground, badgeForeground } from 'vs/platform/theme/common/colorRegistry';
......@@ -177,6 +177,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
protected getActions(): IAction[] {
return [
this.instantiationService.createInstance(ToggleMaximizedPanelAction, ToggleMaximizedPanelAction.ID, ToggleMaximizedPanelAction.LABEL),
this.instantiationService.createInstance(TogglePanelPositionAction, TogglePanelPositionAction.ID, TogglePanelPositionAction.LABEL),
this.instantiationService.createInstance(ClosePanelAction, ClosePanelAction.ID, ClosePanelAction.LABEL)
];
......
......@@ -38,7 +38,7 @@ import { IActionBarRegistry, Extensions as ActionBarExtensions } from 'vs/workbe
import { PanelRegistry, Extensions as PanelExtensions } from 'vs/workbench/browser/panel';
import { QuickOpenController } from 'vs/workbench/browser/parts/quickopen/quickOpenController';
import { getServices } from 'vs/platform/instantiation/common/extensions';
import { Position, Parts, IPartService } from 'vs/workbench/services/part/common/partService';
import { Position, Parts, IPartService, ILayoutOptions } from 'vs/workbench/services/part/common/partService';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { ContextMenuService } from 'vs/workbench/services/contextview/electron-browser/contextmenuService';
......@@ -892,6 +892,14 @@ export class Workbench implements IPartService {
});
}
public toggleMaximizedPanel(): void {
this.workbenchLayout.layout({ toggleMaximizedPanel: true });
}
public isPanelMaximized(): boolean {
return this.workbenchLayout.isPanelMaximized();
}
public getSideBarPosition(): Position {
return this.sideBarPosition;
}
......@@ -962,9 +970,9 @@ export class Workbench implements IPartService {
* Asks the workbench and all its UI components inside to lay out according to
* the containers dimension the workbench is living in.
*/
public layout(): void {
public layout(options?: ILayoutOptions): void {
if (this.isStarted()) {
this.workbenchLayout.layout();
this.workbenchLayout.layout(options);
}
}
......
......@@ -23,6 +23,10 @@ export enum Position {
BOTTOM
}
export interface ILayoutOptions {
toggleMaximizedPanel?: boolean;
}
export const IPartService = createDecorator<IPartService>('partService');
export interface IPartService {
......@@ -41,7 +45,7 @@ export interface IPartService {
/**
* Asks the part service to layout all parts.
*/
layout(): void;
layout(options?: ILayoutOptions): void;
/**
* Asks the part service to if all parts have been created.
......@@ -88,6 +92,17 @@ export interface IPartService {
*/
setPanelHidden(hidden: boolean): TPromise<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;
/**
* Returns true if the panel is maximized.
*/
isPanelMaximized(): boolean;
/**
* Gets the current side bar position. Note that the sidebar can be hidden too.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册