提交 0e409ed1 编写于 作者: B Benjamin Pasero

debt - simplify part layout

上级 1924c391
......@@ -631,11 +631,11 @@ export class WorkbenchLegacyLayout extends Disposable implements IVerticalSashLa
}
// Propagate to Part Layouts
this.parts.titlebar.layout(new Dimension(this.workbenchSize.width, this.titlebarHeight));
this.parts.editor.layout(new Dimension(editorSize.width, editorSize.height));
this.parts.sidebar.layout(sidebarSize);
this.parts.panel.layout(panelDimension);
this.parts.activitybar.layout(activityBarSize);
this.parts.titlebar.layout(this.workbenchSize.width, this.titlebarHeight);
this.parts.editor.layout(editorSize.width, editorSize.height);
this.parts.sidebar.layout(sidebarSize.width, sidebarSize.height);
this.parts.panel.layout(panelDimension.width, panelDimension.height);
this.parts.activitybar.layout(activityBarSize.width, activityBarSize.height);
// Propagate to Context View
this.contextViewService.layout();
......
......@@ -8,12 +8,18 @@ import { Component } from 'vs/workbench/common/component';
import { IThemeService, ITheme } from 'vs/platform/theme/common/themeService';
import { Dimension, size } from 'vs/base/browser/dom';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IDimension } from 'vs/platform/layout/browser/layoutService';
export interface IPartOptions {
hasTitle?: boolean;
borderWidth?: () => number;
}
export interface ILayoutContentResult {
titleSize: IDimension;
contentSize: IDimension;
}
/**
* Parts are layed out in the workbench and have their own layout that
* arranges an optional title and mandatory content area to show content.
......@@ -95,22 +101,18 @@ export abstract class Part extends Component {
/**
* Layout title and content area in the given dimension.
*/
layout(dimension: Dimension): Dimension[] {
return this.partLayout.layout(dimension);
protected layoutContents(width: number, height: number): ILayoutContentResult {
return this.partLayout.layout(width, height);
}
}
export class PartLayout {
class PartLayout {
private static readonly TITLE_HEIGHT = 35;
constructor(container: HTMLElement, private options: IPartOptions, titleArea: HTMLElement | null, private contentArea: HTMLElement | null) { }
layout(dimension: Dimension): Dimension[] {
const { width, height } = dimension;
// Return the applied sizes to title and content
const sizes: Dimension[] = [];
layout(width: number, height: number): ILayoutContentResult {
// Title Size: Width (Fill), Height (Variable)
let titleSize: Dimension;
......@@ -127,14 +129,11 @@ export class PartLayout {
contentSize.width -= this.options.borderWidth(); // adjust for border size
}
sizes.push(titleSize);
sizes.push(contentSize);
// Content
if (this.contentArea) {
size(this.contentArea, contentSize.width, contentSize.height);
}
return sizes;
return { titleSize, contentSize };
}
}
\ No newline at end of file
......@@ -60,8 +60,6 @@ export class ActivitybarPart extends Part implements ISerializableView {
private _onDidChange = this._register(new Emitter<{ width: number; height: number; }>());
get onDidChange(): Event<{ width: number, height: number }> { return this._onDidChange.event; }
private dimension: Dimension;
private globalActionBar: ActionBar;
private globalActivityIdToActions: { [globalActivityId: string]: GlobalActivityAction; } = Object.create(null);
......@@ -364,31 +362,20 @@ export class ActivitybarPart extends Part implements ISerializableView {
.map(v => v.id);
}
layout(dimension: Dimension): Dimension[];
layout(width: number, height: number): void;
layout(dim1: Dimension | number, dim2?: number): Dimension[] | void {
layout(width: number, height: number): void {
if (!this.layoutService.isVisible(Parts.ACTIVITYBAR_PART)) {
if (dim1 instanceof Dimension) {
return [dim1];
}
return;
}
// Pass to super
const sizes = super.layout(dim1 instanceof Dimension ? dim1 : new Dimension(dim1, dim2!));
// Layout contents
const contentAreaSize = super.layoutContents(width, height).contentSize;
this.dimension = sizes[1];
let availableHeight = this.dimension.height;
// Layout composite bar
let availableHeight = contentAreaSize.height;
if (this.globalActionBar) {
availableHeight -= (this.globalActionBar.items.length * ActivitybarPart.ACTION_HEIGHT); // adjust height for global actions showing
}
this.compositeBar.layout(new Dimension(dim1 instanceof Dimension ? dim1.width : dim1, availableHeight));
if (dim1 instanceof Dimension) {
return sizes;
}
this.compositeBar.layout(new Dimension(width, availableHeight));
}
private onDidStorageChange(e: IWorkspaceStorageChangeEvent): void {
......
......@@ -466,22 +466,15 @@ export abstract class CompositePart<T extends Composite> extends Part {
return AnchorAlignment.RIGHT;
}
layout(dimension: Dimension): Dimension[];
layout(width: number, height: number): void;
layout(dim1: Dimension | number, dim2?: number): Dimension[] | void {
layout(width: number, height: number): void {
// Pass to super
const sizes = super.layout(dim1 instanceof Dimension ? dim1 : new Dimension(dim1, dim2!));
// Layout contents
this.contentAreaSize = super.layoutContents(width, height).contentSize;
// Pass Contentsize to composite
this.contentAreaSize = sizes[1];
// Layout composite
if (this.activeComposite) {
this.activeComposite.layout(this.contentAreaSize);
}
if (dim1 instanceof Dimension) {
return sizes;
}
}
protected removeComposite(compositeId: string): boolean {
......
......@@ -10,7 +10,7 @@ import { Dimension, isAncestor, toggleClass, addClass, $ } from 'vs/base/browser
import { Event, Emitter, Relay } from 'vs/base/common/event';
import { contrastBorder, editorBackground } from 'vs/platform/theme/common/colorRegistry';
import { GroupDirection, IAddGroupOptions, GroupsArrangement, GroupOrientation, IMergeGroupOptions, MergeGroupMode, ICopyEditorOptions, GroupsOrder, GroupChangeKind, GroupLocation, IFindGroupScope, EditorGroupLayout, GroupLayoutArgument } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { Direction, SerializableGrid, Sizing, ISerializedGrid, Orientation, GridBranchNode, isGridBranchNode, GridNode, createSerializedGrid, Grid, ISerializableView } from 'vs/base/browser/ui/grid/grid';
import { GroupIdentifier, IWorkbenchEditorConfiguration } from 'vs/workbench/common/editor';
import { values } from 'vs/base/common/map';
......@@ -81,7 +81,7 @@ class GridWidgetView<T extends IView> implements IView {
export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditorGroupsAccessor, ISerializableView {
_serviceBrand: any;
_serviceBrand: ServiceIdentifier<any>;
private static readonly EDITOR_PART_UI_STATE_STORAGE_KEY = 'editorpart.state';
private static readonly EDITOR_PART_CENTERED_VIEW_STORAGE_KEY = 'editorpart.centeredview';
......@@ -958,16 +958,13 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
return this.groupViews.size === 1 && this._activeGroup.isEmpty();
}
layout(dimension: Dimension): Dimension[];
layout(width: number, height: number): void;
layout(dim1: Dimension | number, dim2?: number): Dimension[] | void {
const sizes = super.layout(dim1 instanceof Dimension ? dim1 : new Dimension(dim1, dim2));
layout(width: number, height: number): void {
this.doLayout(sizes[1]);
// Layout contents
const contentAreaSize = super.layoutContents(width, height).contentSize;
if (dim1 instanceof Dimension) {
return sizes;
}
// Layout editor container
this.doLayout(contentAreaSize);
}
private doLayout(dimension: Dimension): void {
......
......@@ -17,7 +17,7 @@ import { IStorageService, StorageScope, IWorkspaceStorageChangeEvent } from 'vs/
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
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 { IInstantiationService, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { ClosePanelAction, TogglePanelPositionAction, PanelActivityAction, ToggleMaximizedPanelAction, TogglePanelAction } 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';
......@@ -49,7 +49,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService, IS
private static readonly PINNED_PANELS = 'workbench.panel.pinnedPanels';
private static readonly MIN_COMPOSITE_BAR_WIDTH = 50;
_serviceBrand: any;
_serviceBrand: ServiceIdentifier<any>;
element: HTMLElement;
......@@ -282,31 +282,22 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService, IS
};
}
layout(dimension: Dimension): Dimension[];
layout(width: number, height: number): void;
layout(dim1: Dimension | number, dim2?: number): Dimension[] | void {
layout(width: number, height: number): void {
if (!this.layoutService.isVisible(Parts.PANEL_PART)) {
if (dim1 instanceof Dimension) {
return [dim1];
}
return;
}
const { width, height } = dim1 instanceof Dimension ? dim1 : { width: dim1, height: dim2 };
if (this.layoutService.getPanelPosition() === Position.RIGHT) {
this.dimension = new Dimension(width - 1, height!); // Take into account the 1px border when layouting
} else {
this.dimension = new Dimension(width, height!);
}
const sizes = super.layout(this.dimension.width, this.dimension.height);
this.layoutCompositeBar();
// Layout contents
super.layout(this.dimension.width, this.dimension.height);
if (dim1 instanceof Dimension) {
return sizes;
}
// Layout composite bar
this.layoutCompositeBar();
}
private layoutCompositeBar(): void {
......
......@@ -19,13 +19,13 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { Event, Emitter } from 'vs/base/common/event';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { contrastBorder } from 'vs/platform/theme/common/colorRegistry';
import { SIDE_BAR_TITLE_FOREGROUND, SIDE_BAR_BACKGROUND, SIDE_BAR_FOREGROUND, SIDE_BAR_BORDER } from 'vs/workbench/common/theme';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { EventType, addDisposableListener, trackFocus, Dimension } from 'vs/base/browser/dom';
import { EventType, addDisposableListener, trackFocus } from 'vs/base/browser/dom';
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview';
......@@ -34,7 +34,8 @@ import { ISerializableView } from 'vs/base/browser/ui/grid/grid';
import { LayoutPriority } from 'vs/base/browser/ui/grid/gridview';
export class SidebarPart extends CompositePart<Viewlet> implements ISerializableView, IViewletService {
_serviceBrand: any;
_serviceBrand: ServiceIdentifier<any>;
static readonly activeViewletSettingsKey = 'workbench.sidebar.activeviewletid';
......@@ -167,22 +168,12 @@ export class SidebarPart extends CompositePart<Viewlet> implements ISerializable
container.style.borderLeftColor = !isPositionLeft ? borderColor : null;
}
layout(dimension: Dimension): Dimension[];
layout(width: number, height: number): void;
layout(dim1: Dimension | number, dim2?: number): Dimension[] | void {
layout(width: number, height: number): void {
if (!this.layoutService.isVisible(Parts.SIDEBAR_PART)) {
if (dim1 instanceof Dimension) {
return [dim1];
}
return;
}
if (dim1 instanceof Dimension) {
return super.layout(dim1);
}
super.layout(dim1, dim2!);
super.layout(width, height);
}
// Viewlet service
......
......@@ -13,7 +13,7 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { Part } from 'vs/workbench/browser/part';
import { IStatusbarRegistry, Extensions, IStatusbarItem } from 'vs/workbench/browser/parts/statusbar/statusbar';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { StatusbarAlignment, IStatusbarService, IStatusbarEntry } from 'vs/platform/statusbar/common/statusbar';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
......@@ -24,7 +24,7 @@ import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/
import { contrastBorder } from 'vs/platform/theme/common/colorRegistry';
import { isThemeColor } from 'vs/editor/common/editorCommon';
import { Color } from 'vs/base/common/color';
import { addClass, EventHelper, createStyleSheet, addDisposableListener, Dimension } from 'vs/base/browser/dom';
import { addClass, EventHelper, createStyleSheet, addDisposableListener } from 'vs/base/browser/dom';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { Event, Emitter } from 'vs/base/common/event';
......@@ -32,7 +32,8 @@ import { ISerializableView } from 'vs/base/browser/ui/grid/grid';
import { Parts } from 'vs/workbench/services/layout/browser/layoutService';
export class StatusbarPart extends Part implements IStatusbarService, ISerializableView {
_serviceBrand: any;
_serviceBrand: ServiceIdentifier<any>;
private static readonly PRIORITY_PROP = 'statusbar-entry-priority';
private static readonly ALIGNMENT_PROP = 'statusbar-entry-alignment';
......@@ -231,14 +232,8 @@ export class StatusbarPart extends Part implements IStatusbarService, ISerializa
return dispose;
}
layout(dimension: Dimension): Dimension[];
layout(width: number, height: number): void;
layout(dim1: Dimension | number, dim2?: number): Dimension[] | void {
if (dim1 instanceof Dimension) {
return super.layout(dim1);
} else {
super.layout(new Dimension(dim1, dim2!));
}
layout(width: number, height: number): void {
super.layoutContents(width, height);
}
toJSON(): object {
......
......@@ -28,7 +28,7 @@ import { Color } from 'vs/base/common/color';
import { trim } from 'vs/base/common/strings';
import { EventType, EventHelper, Dimension, isAncestor, hide, show, removeClass, addClass, append, $, addDisposableListener, runAtThisOrScheduleAtNextAnimationFrame } from 'vs/base/browser/dom';
import { MenubarControl } from 'vs/workbench/browser/parts/titlebar/menubarControl';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { template, getBaseLabel } from 'vs/base/common/labels';
import { ILabelService } from 'vs/platform/label/common/label';
import { Event, Emitter } from 'vs/base/common/event';
......@@ -58,7 +58,7 @@ export class TitlebarPart extends Part implements ITitleService, ISerializableVi
private _onMenubarVisibilityChange = this._register(new Emitter<boolean>());
get onMenubarVisibilityChange(): Event<boolean> { return this._onMenubarVisibilityChange.event; }
_serviceBrand: any;
_serviceBrand: ServiceIdentifier<any>;
private title: HTMLElement;
private dragRegion: HTMLElement;
......@@ -588,19 +588,10 @@ export class TitlebarPart extends Part implements ITitleService, ISerializableVi
}
}
layout(dimension: Dimension): Dimension[];
layout(width: number, height: number): void;
layout(dim1: Dimension | number, dim2?: number): Dimension[] | void {
if (dim1 instanceof Dimension) {
this.updateLayout(dim1);
layout(width: number, height: number): void {
this.updateLayout(new Dimension(width, height));
return super.layout(dim1);
}
const dimensions = new Dimension(dim1, dim2!);
this.updateLayout(dimensions);
super.layout(dimensions);
super.layoutContents(width, height);
}
toJSON(): object {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册