Skip to content

Commit

Permalink
Merge branch 'grid2x2'
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Jun 12, 2018
2 parents 2b8f54b + 5c118a9 commit f9911c7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/vs/base/browser/ui/grid/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ export class SerializableGrid<T extends ISerializableView> extends Grid<T> {
result.orientation = orientation;
result.restoreViews(firstLeaf.view, orientation, root);
result.initialLayoutContext = { width, height, root };
result.gridview.trySet2x2();

return result;
}
Expand Down
43 changes: 42 additions & 1 deletion src/vs/base/browser/ui/grid/gridview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'vs/css!./gridview';
import { Event, anyEvent, Emitter, mapEvent, Relay } from 'vs/base/common/event';
import { Orientation, Sash } from 'vs/base/browser/ui/sash/sash';
import { SplitView, IView as ISplitView, Sizing, ISplitViewStyles } from 'vs/base/browser/ui/splitview/splitview';
import { empty as EmptyDisposable, IDisposable } from 'vs/base/common/lifecycle';
import { empty as EmptyDisposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { $, append } from 'vs/base/browser/dom';
import { tail2 as tail } from 'vs/base/common/arrays';
import { Color } from 'vs/base/common/color';
Expand Down Expand Up @@ -288,6 +288,22 @@ class BranchNode implements ISplitView, IDisposable {
this._onDidChange.fire();
}

trySet2x2(other: BranchNode): IDisposable {
if (this.children.length !== 2 || other.children.length !== 2) {
return EmptyDisposable;
}

if (this.getChildSize(0) !== other.getChildSize(0)) {
return EmptyDisposable;
}

const mySash = this.splitview.sashes[0];
const otherSash = other.splitview.sashes[0];
mySash.linkedSash = otherSash;
otherSash.linkedSash = mySash;
return toDisposable(() => mySash.linkedSash = otherSash.linkedSash = undefined);
}

dispose(): void {
for (const child of this.children) {
child.dispose();
Expand Down Expand Up @@ -409,6 +425,8 @@ export class GridView implements IDisposable {
private onDidSashResetRelay = new Relay<number[]>();
readonly onDidSashReset: Event<number[]> = this.onDidSashResetRelay.event;

private disposable2x2: IDisposable = EmptyDisposable;

private get root(): BranchNode {
return this._root;
}
Expand Down Expand Up @@ -483,6 +501,9 @@ export class GridView implements IDisposable {
}

addView(view: IView, size: number | Sizing, location: number[]): void {
this.disposable2x2.dispose();
this.disposable2x2 = EmptyDisposable;

const [rest, index] = tail(location);
const [pathToParent, parent] = this.getNode(rest);

Expand Down Expand Up @@ -512,6 +533,9 @@ export class GridView implements IDisposable {
}

removeView(location: number[], sizing?: Sizing): IView {
this.disposable2x2.dispose();
this.disposable2x2 = EmptyDisposable;

const [rest, index] = tail(location);
const [pathToParent, parent] = this.getNode(rest);

Expand Down Expand Up @@ -709,6 +733,23 @@ export class GridView implements IDisposable {
return this.getNode(rest, child, path);
}

trySet2x2(): void {
this.disposable2x2.dispose();
this.disposable2x2 = EmptyDisposable;

if (this.root.children.length !== 2) {
return;
}

const [first, second] = this.root.children;

if (!(first instanceof BranchNode) || !(second instanceof BranchNode)) {
return;
}

this.disposable2x2 = first.trySet2x2(second);
}

dispose(): void {
this.onDidSashResetRelay.dispose();
this.root.dispose();
Expand Down
8 changes: 7 additions & 1 deletion src/vs/base/browser/ui/sash/sash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export class Sash {
private readonly _onDidEnd = new Emitter<void>();
readonly onDidEnd: Event<void> = this._onDidEnd.event;

linkedSash: Sash | undefined = undefined;

private orthogonalStartSashDisposables: IDisposable[] = [];
private _orthogonalStartSash: Sash | undefined;
get orthogonalStartSash(): Sash | undefined { return this._orthogonalStartSash; }
Expand Down Expand Up @@ -178,6 +180,11 @@ export class Sash {

let isMultisashResize = false;

if (this.linkedSash && !(e as any).__linkedSashEvent) {
(e as any).__linkedSashEvent = true;
this.linkedSash.onMouseDown(e);
}

if (!(e as any).__orthogonalSashEvent) {
let orthogonalSash: Sash | undefined;

Expand Down Expand Up @@ -297,7 +304,6 @@ export class Sash {
const startY = event.pageY;
const altKey = event.altKey;


this._onDidStart.fire({
startX: startX,
currentX: startX,
Expand Down

0 comments on commit f9911c7

Please sign in to comment.