提交 f3efccad 编写于 作者: J Joao Moreno

grid: onDidSashReset

上级 7d523ccd
......@@ -10,6 +10,7 @@ import { Orientation } from 'vs/base/browser/ui/sash/sash';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { tail2 as tail, tail2 } from 'vs/base/common/arrays';
import { orthogonal, IView, GridView, Sizing as GridViewSizing } from './gridview';
import { Event } from 'vs/base/common/event';
export { Orientation } from './gridview';
......@@ -107,6 +108,7 @@ export class Grid<T extends IView> implements IDisposable {
get width(): number { return this.gridview.width; }
get height(): number { return this.gridview.height; }
get onDidSashReset(): Event<number[]> { return this.gridview.onDidSashReset; }
constructor(container: HTMLElement, view: T) {
this.gridview = new GridView(container);
......
......@@ -6,7 +6,7 @@
'use strict';
import 'vs/css!./gridview';
import { Event, anyEvent, Emitter, mapEvent } from 'vs/base/common/event';
import { Event, anyEvent, Emitter, mapEvent, Relay } from 'vs/base/common/event';
import { Orientation } from 'vs/base/browser/ui/sash/sash';
import { SplitView, IView as ISplitView, Sizing } from 'vs/base/browser/ui/splitview/splitview';
import { empty as EmptyDisposable, IDisposable } from 'vs/base/common/lifecycle';
......@@ -85,7 +85,12 @@ class BranchNode implements ISplitView, IDisposable {
private _onDidChange: Emitter<number | undefined>;
get onDidChange(): Event<number | undefined> { return this._onDidChange.event; }
private onDidChangeDisposable: IDisposable;
private childrenChangeDisposable: IDisposable = EmptyDisposable;
private _onDidSashReset = new Emitter<number[]>();
readonly onDidSashReset: Event<number[]> = this._onDidSashReset.event;
private splitviewSashResetDisposable: IDisposable = EmptyDisposable;
private childrenSashResetDisposable: IDisposable = EmptyDisposable;
constructor(
readonly orientation: Orientation,
......@@ -97,11 +102,13 @@ class BranchNode implements ISplitView, IDisposable {
this._onDidChange = new Emitter<number | undefined>();
this.children = [];
this.onDidChangeDisposable = EmptyDisposable;
this.element = $('.monaco-grid-branch-node');
this.splitview = new SplitView(this.element, { orientation: this.orientation });
this.splitview.layout(size);
const onDidSashReset = mapEvent(this.splitview.onDidSashReset, i => [i]);
this.splitviewSashResetDisposable = onDidSashReset(this._onDidSashReset.fire, this._onDidSashReset);
}
layout(size: number): void {
......@@ -172,8 +179,13 @@ class BranchNode implements ISplitView, IDisposable {
private onDidChildrenChange(): void {
const onDidChildrenChange = anyEvent(...this.children.map(c => c.onDidChange));
this.onDidChangeDisposable.dispose();
this.onDidChangeDisposable = onDidChildrenChange(this._onDidChange.fire, this._onDidChange);
this.childrenChangeDisposable.dispose();
this.childrenChangeDisposable = onDidChildrenChange(this._onDidChange.fire, this._onDidChange);
const onDidChildrenSashReset = anyEvent(...this.children.map((c, i) => mapEvent(c.onDidSashReset, location => [i, ...location])));
this.childrenSashResetDisposable.dispose();
this.childrenSashResetDisposable = onDidChildrenSashReset(this._onDidSashReset.fire, this._onDidSashReset);
this._onDidChange.fire();
}
......@@ -182,7 +194,9 @@ class BranchNode implements ISplitView, IDisposable {
child.dispose();
}
this.onDidChangeDisposable.dispose();
this.splitviewSashResetDisposable.dispose();
this.childrenSashResetDisposable.dispose();
this.childrenChangeDisposable.dispose();
this.splitview.dispose();
}
}
......@@ -195,6 +209,8 @@ class LeafNode implements ISplitView, IDisposable {
private _orthogonalSize: number;
get orthogonalSize(): number { return this._orthogonalSize; }
readonly onDidSashReset: Event<number[]> = Event.None;
constructor(
readonly view: IView,
readonly orientation: Orientation,
......@@ -281,6 +297,8 @@ export class GridView implements IDisposable {
private element: HTMLElement;
private root: BranchNode;
private onDidSashResetRelay = new Relay<number[]>();
readonly onDidSashReset: Event<number[]> = this.onDidSashResetRelay.event;
get orientation(): Orientation {
return this.root.orientation;
......@@ -296,6 +314,7 @@ export class GridView implements IDisposable {
this.root = flipNode(oldRoot, oldRoot.orthogonalSize, oldRoot.size) as BranchNode;
this.element.appendChild(this.root.element);
this.onDidSashResetRelay.input = this.root.onDidSashReset;
this.root.layout(oldRoot.size);
this.root.orthogonalLayout(oldRoot.orthogonalSize);
......@@ -315,6 +334,7 @@ export class GridView implements IDisposable {
this.element = append(container, $('.monaco-grid-view'));
this.root = new BranchNode(Orientation.VERTICAL);
this.element.appendChild(this.root.element);
this.onDidSashResetRelay.input = this.root.onDidSashReset;
}
layout(width: number, height: number): void {
......@@ -494,6 +514,7 @@ export class GridView implements IDisposable {
}
dispose(): void {
this.onDidSashResetRelay.dispose();
this.root.dispose();
}
}
\ No newline at end of file
......@@ -375,7 +375,7 @@ export class PanelView implements IDisposable {
private _onDidDrop = new Emitter<{ from: Panel, to: Panel }>();
readonly onDidDrop: Event<{ from: Panel, to: Panel }> = this._onDidDrop.event;
readonly onDidSashChange: Event<void>;
readonly onDidSashChange: Event<number>;
constructor(container: HTMLElement, options: IPanelViewOptions = {}) {
this.dnd = options.dnd;
......
......@@ -117,9 +117,9 @@ export class SplitView implements IDisposable {
private sashDragState: ISashDragState;
private state: State = State.Idle;
private _onDidSashChange = new Emitter<void>();
private _onDidSashChange = new Emitter<number>();
readonly onDidSashChange = this._onDidSashChange.event;
private _onDidSashReset = new Emitter<void>();
private _onDidSashReset = new Emitter<number>();
readonly onDidSashReset = this._onDidSashReset.event;
get length(): number {
......@@ -194,10 +194,8 @@ export class SplitView implements IDisposable {
const onStartDisposable = onStart(this.onSashStart, this);
const onChange = mapEvent(sash.onDidChange, sashEventMapper);
const onSashChangeDisposable = onChange(this.onSashChange, this);
const onEnd = mapEvent<void, void>(sash.onDidEnd, () => null);
const onEndDisposable = onEnd(() => this._onDidSashChange.fire());
const onDidReset = mapEvent<void, void>(sash.onDidReset, () => null);
const onDidResetDisposable = onDidReset(() => this._onDidSashReset.fire());
const onEndDisposable = sash.onDidEnd(() => this._onDidSashChange.fire(firstIndex(this.sashItems, item => item.sash === sash)));
const onDidResetDisposable = sash.onDidReset(() => this._onDidSashReset.fire(firstIndex(this.sashItems, item => item.sash === sash)));
const disposable = combinedDisposable([onStartDisposable, onSashChangeDisposable, onEndDisposable, onDidResetDisposable, sash]);
const sashItem: ISashItem = { sash, disposable };
......
......@@ -450,6 +450,8 @@ export class NextEditorPart extends Part implements INextEditorGroupsService, IN
this.doSetGroupActive(initialGroup);
}
this.gridWidget.onDidSashReset(e => console.log('sash reset', e));
// Signal restored
always(TPromise.join(this.groups.map(group => group.whenRestored)), () => this.whenRestoredComplete(void 0));
......
......@@ -154,7 +154,7 @@ export class PanelViewlet extends Viewlet {
private panelItems: IViewletPanelItem[] = [];
private panelview: PanelView;
get onDidSashChange(): Event<void> {
get onDidSashChange(): Event<number> {
return this.panelview.onDidSashChange;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册