Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 (#6381)

* Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973

* disable strict null check
This commit is contained in:
Anthony Dresser
2019-07-15 22:35:46 -07:00
committed by GitHub
parent f720ec642f
commit 0b7e7ddbf9
2406 changed files with 59140 additions and 35464 deletions

View File

@@ -5,14 +5,12 @@
import 'vs/css!./gridview';
import { Orientation } from 'vs/base/browser/ui/sash/sash';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { Disposable } from 'vs/base/common/lifecycle';
import { tail2 as tail, equals } from 'vs/base/common/arrays';
import { orthogonal, IView, GridView, Sizing as GridViewSizing, Box, IGridViewStyles } from './gridview';
import { Event, Emitter } from 'vs/base/common/event';
import { $ } from 'vs/base/browser/dom';
import { LayoutPriority } from 'vs/base/browser/ui/splitview/splitview';
import { orthogonal, IView, GridView, Sizing as GridViewSizing, Box, IGridViewStyles, IViewSize } from './gridview';
import { Event } from 'vs/base/common/event';
export { Orientation } from './gridview';
export { Orientation, Sizing as GridViewSizing } from './gridview';
export const enum Direction {
Up,
@@ -117,10 +115,6 @@ function getDirectionOrientation(direction: Direction): Orientation {
return direction === Direction.Up || direction === Direction.Down ? Orientation.VERTICAL : Orientation.HORIZONTAL;
}
function getSize(dimensions: { width: number; height: number; }, orientation: Orientation) {
return orientation === Orientation.HORIZONTAL ? dimensions.width : dimensions.height;
}
export function getRelativeLocation(rootOrientation: Orientation, location: number[], direction: Direction): number[] {
const orientation = getLocationOrientation(rootOrientation, location);
const directionOrientation = getDirectionOrientation(direction);
@@ -191,12 +185,10 @@ export interface IGridOptions {
proportionalLayout?: boolean;
}
export class Grid<T extends IView> implements IDisposable {
export class Grid<T extends IView = IView> extends Disposable {
protected gridview: GridView;
private views = new Map<T, HTMLElement>();
private disposables: IDisposable[] = [];
get orientation(): Orientation { return this.gridview.orientation; }
set orientation(orientation: Orientation) { this.gridview.orientation = orientation; }
@@ -211,13 +203,12 @@ export class Grid<T extends IView> implements IDisposable {
get element(): HTMLElement { return this.gridview.element; }
sashResetSizing: Sizing = Sizing.Distribute;
constructor(view: T, options: IGridOptions = {}) {
super();
this.gridview = new GridView(options);
this.disposables.push(this.gridview);
this._register(this.gridview);
this.gridview.onDidSashReset(this.doResetViewSize, this, this.disposables);
this._register(this.gridview.onDidSashReset(this.doResetViewSize, this));
this._addView(view, 0, [0]);
}
@@ -299,15 +290,14 @@ export class Grid<T extends IView> implements IDisposable {
return this.gridview.swapViews(fromLocation, toLocation);
}
resizeView(view: T, size: number): void {
resizeView(view: T, size: IViewSize): void {
const location = this.getViewLocation(view);
return this.gridview.resizeView(location, size);
}
getViewSize(view: T): number {
getViewSize(view: T): IViewSize {
const location = this.getViewLocation(view);
const viewSize = this.gridview.getViewSize(location);
return getLocationOrientation(this.orientation, location) === Orientation.HORIZONTAL ? viewSize.width : viewSize.height;
return this.gridview.getViewSize(location);
}
// TODO@joao cleanup
@@ -325,6 +315,16 @@ export class Grid<T extends IView> implements IDisposable {
this.gridview.distributeViewSizes();
}
isViewVisible(view: T): boolean {
const location = this.getViewLocation(view);
return this.gridview.isViewVisible(location);
}
setViewVisible(view: T, visible: boolean): void {
const location = this.getViewLocation(view);
this.gridview.setViewVisible(location, visible);
}
getViews(): GridBranchNode<T> {
return this.gridview.getViews() as GridBranchNode<T>;
}
@@ -362,22 +362,8 @@ export class Grid<T extends IView> implements IDisposable {
}
private doResetViewSize(location: number[]): void {
if (this.sashResetSizing === Sizing.Split) {
const orientation = getLocationOrientation(this.orientation, location);
const firstViewSize = getSize(this.gridview.getViewSize(location), orientation);
const [parentLocation, index] = tail(location);
const secondViewSize = getSize(this.gridview.getViewSize([...parentLocation, index + 1]), orientation);
const totalSize = firstViewSize + secondViewSize;
this.gridview.resizeView(location, Math.floor(totalSize / 2));
} else {
const [parentLocation,] = tail(location);
this.gridview.distributeViewSizes(parentLocation);
}
}
dispose(): void {
this.disposables = dispose(this.disposables);
const [parentLocation,] = tail(location);
this.gridview.distributeViewSizes(parentLocation);
}
}
@@ -568,8 +554,11 @@ export class SerializableGrid<T extends ISerializableView> extends Grid<T> {
const childLocation = [...location, i];
if (i < node.children.length - 1) {
const size = orientation === Orientation.VERTICAL ? child.box.height : child.box.width;
this.gridview.resizeView(childLocation, Math.floor(size * scale));
const size = orientation === Orientation.VERTICAL
? { height: Math.floor(child.box.height * scale) }
: { width: Math.floor(child.box.width * scale) };
this.gridview.resizeView(childLocation, size);
}
this.restoreViewsSize(childLocation, child, orthogonal(orientation), widthScale, heightScale);
@@ -653,63 +642,3 @@ export function createSerializedGrid(gridDescriptor: GridDescriptor): ISerialize
height: height || 1
};
}
export class View implements IView {
readonly element = $('.grid-view-view');
private visible = false;
private width: number | undefined;
private height: number | undefined;
private orientation: Orientation = Orientation.HORIZONTAL;
get minimumWidth(): number { return this.visible ? this.view.minimumWidth : 0; }
get maximumWidth(): number { return this.visible ? this.view.maximumWidth : (this.orientation === Orientation.HORIZONTAL ? 0 : Number.POSITIVE_INFINITY); }
get minimumHeight(): number { return this.visible ? this.view.minimumHeight : 0; }
get maximumHeight(): number { return this.visible ? this.view.maximumHeight : (this.orientation === Orientation.VERTICAL ? 0 : Number.POSITIVE_INFINITY); }
private onDidChangeVisibility = new Emitter<{ width: number; height: number; } | undefined>();
readonly onDidChange: Event<{ width: number; height: number; } | undefined>;
get priority(): LayoutPriority | undefined { return this.view.priority; }
get snapSize(): number | undefined { return this.visible ? this.view.snapSize : undefined; }
constructor(private view: IView) {
this.show();
this.onDidChange = Event.any(this.onDidChangeVisibility.event, Event.filter(view.onDidChange, () => this.visible));
}
show(): void {
if (this.visible) {
return;
}
this.visible = true;
this.element.appendChild(this.view.element);
this.onDidChangeVisibility.fire(typeof this.width === 'number' ? { width: this.width, height: this.height! } : undefined);
}
hide(): void {
if (!this.visible) {
return;
}
this.visible = false;
this.element.removeChild(this.view.element);
this.onDidChangeVisibility.fire(undefined);
}
layout(width: number, height: number, orientation: Orientation): void {
this.orientation = orientation;
if (!this.visible) {
return;
}
this.view.layout(width, height, orientation);
this.width = width;
this.height = height;
}
}

View File

@@ -15,16 +15,22 @@ import { Color } from 'vs/base/common/color';
export { Sizing, LayoutPriority } from 'vs/base/browser/ui/splitview/splitview';
export { Orientation } from 'vs/base/browser/ui/sash/sash';
export interface IViewSize {
readonly width: number;
readonly height: number;
}
export interface IView {
readonly element: HTMLElement;
readonly minimumWidth: number;
readonly maximumWidth: number;
readonly minimumHeight: number;
readonly maximumHeight: number;
readonly onDidChange: Event<{ width: number; height: number; } | undefined>;
readonly onDidChange: Event<IViewSize | undefined>;
readonly priority?: LayoutPriority;
readonly snapSize?: number;
readonly snap?: boolean;
layout(width: number, height: number, orientation: Orientation): void;
setVisible?(visible: boolean): void;
}
export function orthogonal(orientation: Orientation): Orientation {
@@ -173,6 +179,12 @@ class BranchNode implements ISplitView, IDisposable {
}
}
setVisible(visible: boolean): void {
for (const child of this.children) {
child.setVisible(visible);
}
}
orthogonalLayout(size: number): void {
this._size = size;
this.splitview.layout(size);
@@ -299,6 +311,22 @@ class BranchNode implements ISplitView, IDisposable {
return this.splitview.getViewSize(index);
}
isChildVisible(index: number): boolean {
if (index < 0 || index >= this.children.length) {
throw new Error('Invalid index');
}
return this.splitview.isViewVisible(index);
}
setChildVisible(index: number, visible: boolean): void {
if (index < 0 || index >= this.children.length) {
throw new Error('Invalid index');
}
this.splitview.setViewVisible(index, visible);
}
private onDidChildrenChange(): void {
const onDidChildrenChange = Event.map(Event.any(...this.children.map(c => c.onDidChange)), () => undefined);
this.childrenChangeDisposable.dispose();
@@ -458,8 +486,8 @@ class LeafNode implements ISplitView, IDisposable {
return this.view.priority;
}
get snapSize(): number | undefined {
return this.view.snapSize;
get snap(): boolean | undefined {
return this.view.snap;
}
get minimumOrthogonalSize(): number {
@@ -483,6 +511,12 @@ class LeafNode implements ISplitView, IDisposable {
return this.view.layout(this.width, this.height, orthogonal(this.orientation));
}
setVisible(visible: boolean): void {
if (this.view.setVisible) {
this.view.setVisible(visible);
}
}
orthogonalLayout(size: number): void {
this._orthogonalSize = size;
return this.view.layout(this.width, this.height, orthogonal(this.orientation));
@@ -573,7 +607,7 @@ export class GridView implements IDisposable {
get maximumWidth(): number { return this.root.maximumHeight; }
get maximumHeight(): number { return this.root.maximumHeight; }
private _onDidChange = new Relay<{ width: number; height: number; } | undefined>();
private _onDidChange = new Relay<IViewSize | undefined>();
readonly onDidChange = this._onDidChange.event;
constructor(options: IGridViewOptions = {}) {
@@ -747,18 +781,33 @@ export class GridView implements IDisposable {
}
}
resizeView(location: number[], size: number): void {
resizeView(location: number[], { width, height }: Partial<IViewSize>): void {
const [rest, index] = tail(location);
const [, parent] = this.getNode(rest);
const [pathToParent, parent] = this.getNode(rest);
if (!(parent instanceof BranchNode)) {
throw new Error('Invalid location');
}
parent.resizeChild(index, size);
if (!width && !height) {
return;
}
const [parentSize, grandParentSize] = parent.orientation === Orientation.HORIZONTAL ? [width, height] : [height, width];
if (typeof grandParentSize === 'number' && pathToParent.length > 0) {
const [, grandParent] = tail(pathToParent);
const [, parentIndex] = tail(rest);
grandParent.resizeChild(parentIndex, grandParentSize);
}
if (typeof parentSize === 'number') {
parent.resizeChild(index, parentSize);
}
}
getViewSize(location: number[]): { width: number; height: number; } {
getViewSize(location: number[]): IViewSize {
const [, node] = this.getNode(location);
return { width: node.width, height: node.height };
}
@@ -790,6 +839,28 @@ export class GridView implements IDisposable {
node.distributeViewSizes();
}
isViewVisible(location: number[]): boolean {
const [rest, index] = tail(location);
const [, parent] = this.getNode(rest);
if (!(parent instanceof BranchNode)) {
throw new Error('Invalid from location');
}
return parent.isChildVisible(index);
}
setViewVisible(location: number[], visible: boolean): void {
const [rest, index] = tail(location);
const [, parent] = this.getNode(rest);
if (!(parent instanceof BranchNode)) {
throw new Error('Invalid from location');
}
parent.setChildVisible(index, visible);
}
getViews(): GridBranchNode {
return this._getViews(this.root, this.orientation, { top: 0, left: 0, width: this.width, height: this.height }) as GridBranchNode;
}