提交 4f5c928f 编写于 作者: J Joao Moreno

sash: use linked sashes as arrays

上级 44b554db
...@@ -72,6 +72,10 @@ export interface IGridViewOptions { ...@@ -72,6 +72,10 @@ export interface IGridViewOptions {
styles?: IGridViewStyles; styles?: IGridViewStyles;
} }
function arrayIdentity<T>(el: T): T[] {
return el ? [el] : [];
}
class BranchNode implements ISplitView, IDisposable { class BranchNode implements ISplitView, IDisposable {
readonly element: HTMLElement; readonly element: HTMLElement;
...@@ -136,10 +140,10 @@ class BranchNode implements ISplitView, IDisposable { ...@@ -136,10 +140,10 @@ class BranchNode implements ISplitView, IDisposable {
private splitviewSashResetDisposable: IDisposable = EmptyDisposable; private splitviewSashResetDisposable: IDisposable = EmptyDisposable;
private childrenSashResetDisposable: IDisposable = EmptyDisposable; private childrenSashResetDisposable: IDisposable = EmptyDisposable;
get orthogonalStartSash(): Sash | undefined { return this.splitview.orthogonalStartSash; } get linkedStartSashes(): Sash[] { return this.splitview.linkedStartSashes; }
set orthogonalStartSash(sash: Sash | undefined) { this.splitview.orthogonalStartSash = sash; } set linkedStartSashes(sashes: Sash[]) { this.splitview.linkedStartSashes = sashes; }
get orthogonalEndSash(): Sash | undefined { return this.splitview.orthogonalEndSash; } get linkedEndSashes(): Sash[] { return this.splitview.linkedEndSashes; }
set orthogonalEndSash(sash: Sash | undefined) { this.splitview.orthogonalEndSash = sash; } set linkedEndSashes(sashes: Sash[]) { this.splitview.linkedEndSashes = sashes; }
constructor( constructor(
readonly orientation: Orientation, readonly orientation: Orientation,
...@@ -195,15 +199,15 @@ class BranchNode implements ISplitView, IDisposable { ...@@ -195,15 +199,15 @@ class BranchNode implements ISplitView, IDisposable {
const last = index === this.splitview.length; const last = index === this.splitview.length;
this.splitview.addView(node, size, index); this.splitview.addView(node, size, index);
this.children.splice(index, 0, node); this.children.splice(index, 0, node);
node.orthogonalStartSash = this.splitview.sashes[index - 1]; node.linkedStartSashes = arrayIdentity(this.splitview.sashes[index - 1]);
node.orthogonalEndSash = this.splitview.sashes[index]; node.linkedEndSashes = arrayIdentity(this.splitview.sashes[index]);
if (!first) { if (!first) {
this.children[index - 1].orthogonalEndSash = this.splitview.sashes[index - 1]; this.children[index - 1].linkedEndSashes = arrayIdentity(this.splitview.sashes[index - 1]);
} }
if (!last) { if (!last) {
this.children[index + 1].orthogonalStartSash = this.splitview.sashes[index]; this.children[index + 1].linkedStartSashes = arrayIdentity(this.splitview.sashes[index]);
} }
this.onDidChildrenChange(); this.onDidChildrenChange();
...@@ -220,11 +224,11 @@ class BranchNode implements ISplitView, IDisposable { ...@@ -220,11 +224,11 @@ class BranchNode implements ISplitView, IDisposable {
this.children.splice(index, 1); this.children.splice(index, 1);
if (!first) { if (!first) {
this.children[index - 1].orthogonalEndSash = this.splitview.sashes[index - 1]; this.children[index - 1].linkedEndSashes = arrayIdentity(this.splitview.sashes[index - 1]);
} }
if (!last) { // [0,1,2,3] (2) => [0,1,3] if (!last) { // [0,1,2,3] (2) => [0,1,3]
this.children[index].orthogonalStartSash = this.splitview.sashes[Math.max(index - 1, 0)]; this.children[index].linkedStartSashes = arrayIdentity(this.splitview.sashes[Math.max(index - 1, 0)]);
} }
this.onDidChildrenChange(); this.onDidChildrenChange();
...@@ -244,7 +248,7 @@ class BranchNode implements ISplitView, IDisposable { ...@@ -244,7 +248,7 @@ class BranchNode implements ISplitView, IDisposable {
} }
this.splitview.swapViews(from, to); this.splitview.swapViews(from, to);
[this.children[from].orthogonalStartSash, this.children[from].orthogonalEndSash, this.children[to].orthogonalStartSash, this.children[to].orthogonalEndSash] = [this.children[to].orthogonalStartSash, this.children[to].orthogonalEndSash, this.children[from].orthogonalStartSash, this.children[from].orthogonalEndSash]; [this.children[from].linkedStartSashes, this.children[from].linkedEndSashes, this.children[to].linkedStartSashes, this.children[to].linkedEndSashes] = [this.children[to].linkedStartSashes, this.children[to].linkedEndSashes, this.children[from].linkedStartSashes, this.children[from].linkedEndSashes];
[this.children[from], this.children[to]] = [this.children[to], this.children[from]]; [this.children[from], this.children[to]] = [this.children[to], this.children[from]];
} }
...@@ -342,13 +346,10 @@ class LeafNode implements ISplitView, IDisposable { ...@@ -342,13 +346,10 @@ class LeafNode implements ISplitView, IDisposable {
return mapEvent(this.view.onDidChange, this.orientation === Orientation.HORIZONTAL ? ({ width }) => width : ({ height }) => height); return mapEvent(this.view.onDidChange, this.orientation === Orientation.HORIZONTAL ? ({ width }) => width : ({ height }) => height);
} }
set orthogonalStartSash(sash: Sash) { get linkedStartSashes(): Sash[] { return []; }
// noop set linkedStartSashes(sashes: Sash[]) { }
} get linkedEndSashes(): Sash[] { return []; }
set linkedEndSashes(sashes: Sash[]) { }
set orthogonalEndSash(sash: Sash) {
// noop
}
layout(size: number): void { layout(size: number): void {
this._size = size; this._size = size;
......
...@@ -51,8 +51,8 @@ ...@@ -51,8 +51,8 @@
cursor: n-resize; cursor: n-resize;
} }
.monaco-sash:not(.disabled).orthogonal-start::before, .monaco-sash:not(.disabled).linked-start::before,
.monaco-sash:not(.disabled).orthogonal-end::after { .monaco-sash:not(.disabled).linked-end::after {
content: ' '; content: ' ';
height: 8px; height: 8px;
width: 8px; width: 8px;
...@@ -62,22 +62,22 @@ ...@@ -62,22 +62,22 @@
position: absolute; position: absolute;
} }
.monaco-sash.orthogonal-start.vertical::before { .monaco-sash.linked-start.vertical::before {
left: -2px; left: -2px;
top: -4px; top: -4px;
} }
.monaco-sash.orthogonal-end.vertical::after { .monaco-sash.linked-end.vertical::after {
left: -2px; left: -2px;
bottom: -4px; bottom: -4px;
} }
.monaco-sash.orthogonal-start.horizontal::before { .monaco-sash.linked-start.horizontal::before {
top: -2px; top: -2px;
left: -4px; left: -4px;
} }
.monaco-sash.orthogonal-end.horizontal::after { .monaco-sash.linked-end.horizontal::after {
top: -2px; top: -2px;
right: -4px; right: -4px;
} }
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
background: cyan; background: cyan;
} }
.monaco-sash.debug:not(.disabled).orthogonal-start::before, .monaco-sash.debug:not(.disabled).linked-start::before,
.monaco-sash.debug:not(.disabled).orthogonal-end::after { .monaco-sash.debug:not(.disabled).linked-end::after {
background: red; background: red;
} }
\ No newline at end of file
...@@ -12,11 +12,11 @@ import { isMacintosh } from 'vs/base/common/platform'; ...@@ -12,11 +12,11 @@ import { isMacintosh } from 'vs/base/common/platform';
import * as types from 'vs/base/common/types'; import * as types from 'vs/base/common/types';
import { EventType, GestureEvent, Gesture } from 'vs/base/browser/touch'; import { EventType, GestureEvent, Gesture } from 'vs/base/browser/touch';
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent'; import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { Event, Emitter } from 'vs/base/common/event'; import { Event, Emitter, anyEvent, mapEvent } from 'vs/base/common/event';
import { getElementsByTagName, EventHelper, createStyleSheet, addDisposableListener, Dimension, append, $, addClass, removeClass, toggleClass } from 'vs/base/browser/dom'; import { getElementsByTagName, EventHelper, createStyleSheet, addDisposableListener, Dimension, append, $, addClass, removeClass, toggleClass } from 'vs/base/browser/dom';
import { domEvent } from 'vs/base/browser/event'; import { domEvent } from 'vs/base/browser/event';
const DEBUG = false; const DEBUG = true;
export interface ISashLayoutProvider { } export interface ISashLayoutProvider { }
...@@ -42,8 +42,8 @@ export interface ISashEvent { ...@@ -42,8 +42,8 @@ export interface ISashEvent {
export interface ISashOptions { export interface ISashOptions {
orientation?: Orientation; orientation?: Orientation;
orthogonalStartSash?: Sash; linkedStartSashes?: Sash[];
orthogonalEndSash?: Sash; linkedEndSashes?: Sash[];
} }
export enum Orientation { export enum Orientation {
...@@ -96,36 +96,40 @@ export class Sash { ...@@ -96,36 +96,40 @@ export class Sash {
private readonly _onDidEnd = new Emitter<void>(); private readonly _onDidEnd = new Emitter<void>();
readonly onDidEnd: Event<void> = this._onDidEnd.event; readonly onDidEnd: Event<void> = this._onDidEnd.event;
private orthogonalStartSashDisposables: IDisposable[] = []; private linkedStartSashesDisposables: IDisposable[] = [];
private _orthogonalStartSash: Sash | undefined; private _linkedStartSashes: Sash[] = [];
get orthogonalStartSash(): Sash | undefined { return this._orthogonalStartSash; } get linkedStartSashes(): Sash[] { return this._linkedStartSashes; }
set orthogonalStartSash(sash: Sash | undefined) { set linkedStartSashes(sashes: Sash[]) {
this.orthogonalStartSashDisposables = dispose(this.orthogonalStartSashDisposables); this.linkedStartSashesDisposables = dispose(this.linkedStartSashesDisposables);
if (sash) { if (sashes.length > 0) {
sash.onDidEnablementChange(this.onOrthogonalStartSashEnablementChange, this, this.orthogonalStartSashDisposables); mapEvent(anyEvent(...sashes.map(s => s.onDidEnablementChange)), () => sashes.map(s => s.state))
this.onOrthogonalStartSashEnablementChange(sash.state); (this.onLinkedStartSashEnablementChange, this, this.linkedStartSashesDisposables);
this.onLinkedStartSashEnablementChange(sashes.map(s => s.state));
} else { } else {
this.onOrthogonalStartSashEnablementChange(SashState.Disabled); this.onLinkedStartSashEnablementChange([]);
} }
this._orthogonalStartSash = sash; this._linkedStartSashes = sashes;
} }
private orthogonalEndSashDisposables: IDisposable[] = []; private linkedEndSashDisposables: IDisposable[] = [];
private _orthogonalEndSash: Sash | undefined; private _linkedEndSash: Sash[] = [];
get orthogonalEndSash(): Sash | undefined { return this._orthogonalEndSash; } get linkedEndSash(): Sash[] { return this._linkedEndSash; }
set orthogonalEndSash(sash: Sash | undefined) { set linkedEndSash(sashes: Sash[]) {
this.orthogonalEndSashDisposables = dispose(this.orthogonalEndSashDisposables); this.linkedEndSashDisposables = dispose(this.linkedEndSashDisposables);
if (sashes) {
mapEvent(anyEvent(...sashes.map(s => s.onDidEnablementChange)), () => sashes.map(s => s.state))
(this.onLinkedEndSashEnablementChange, this, this.linkedEndSashDisposables);
if (sash) { this.onLinkedEndSashEnablementChange(sashes.map(s => s.state));
sash.onDidEnablementChange(this.onOrthogonalEndSashEnablementChange, this, this.orthogonalEndSashDisposables);
this.onOrthogonalEndSashEnablementChange(sash.state);
} else { } else {
this.onOrthogonalEndSashEnablementChange(SashState.Disabled); this.onLinkedEndSashEnablementChange([]);
} }
this._orthogonalEndSash = sash; this._linkedEndSash = sashes;
} }
constructor(container: HTMLElement, layoutProvider: ISashLayoutProvider, options: ISashOptions = {}) { constructor(container: HTMLElement, layoutProvider: ISashLayoutProvider, options: ISashOptions = {}) {
...@@ -151,8 +155,8 @@ export class Sash { ...@@ -151,8 +155,8 @@ export class Sash {
this.hidden = false; this.hidden = false;
this.layoutProvider = layoutProvider; this.layoutProvider = layoutProvider;
this.orthogonalStartSash = options.orthogonalStartSash; this.linkedStartSashes = options.linkedStartSashes || [];
this.orthogonalEndSash = options.orthogonalEndSash; this.linkedEndSash = options.linkedEndSashes || [];
toggleClass(this.el, 'debug', DEBUG); toggleClass(this.el, 'debug', DEBUG);
} }
...@@ -178,27 +182,29 @@ export class Sash { ...@@ -178,27 +182,29 @@ export class Sash {
let isMultisashResize = false; let isMultisashResize = false;
if (!(e as any).__orthogonalSashEvent) { if (!(e as any).__linkedSashEvent) {
let orthogonalSash: Sash | undefined; let linkedSashes: Sash[] = [];
if (this.orientation === Orientation.VERTICAL) { if (this.orientation === Orientation.VERTICAL) {
if (e.offsetY <= 4) { if (e.offsetY <= 4) {
orthogonalSash = this.orthogonalStartSash; linkedSashes = this.linkedStartSashes;
} else if (e.offsetY >= this.el.clientHeight - 4) { } else if (e.offsetY >= this.el.clientHeight - 4) {
orthogonalSash = this.orthogonalEndSash; linkedSashes = this.linkedEndSash;
} }
} else { } else {
if (e.offsetX <= 4) { if (e.offsetX <= 4) {
orthogonalSash = this.orthogonalStartSash; linkedSashes = this.linkedStartSashes;
} else if (e.offsetX >= this.el.clientWidth - 4) { } else if (e.offsetX >= this.el.clientWidth - 4) {
orthogonalSash = this.orthogonalEndSash; linkedSashes = this.linkedEndSash;
} }
} }
if (orthogonalSash) { if (linkedSashes.length > 0) {
isMultisashResize = true; for (const sash of linkedSashes) {
(e as any).__orthogonalSashEvent = true; isMultisashResize = true;
orthogonalSash.onMouseDown(e); (e as any).__linkedSashEvent = true;
sash.onMouseDown(e);
}
} }
} }
...@@ -368,17 +374,17 @@ export class Sash { ...@@ -368,17 +374,17 @@ export class Sash {
return this.hidden; return this.hidden;
} }
private onOrthogonalStartSashEnablementChange(state: SashState): void { private onLinkedStartSashEnablementChange(states: SashState[]): void {
toggleClass(this.el, 'orthogonal-start', state !== SashState.Disabled); toggleClass(this.el, 'linked-start', states.some(state => state !== SashState.Disabled));
} }
private onOrthogonalEndSashEnablementChange(state: SashState): void { private onLinkedEndSashEnablementChange(states: SashState[]): void {
toggleClass(this.el, 'orthogonal-end', state !== SashState.Disabled); toggleClass(this.el, 'linked-end', states.some(state => state !== SashState.Disabled));
} }
dispose(): void { dispose(): void {
this.orthogonalStartSashDisposables = dispose(this.orthogonalStartSashDisposables); this.linkedStartSashesDisposables = dispose(this.linkedStartSashesDisposables);
this.orthogonalEndSashDisposables = dispose(this.orthogonalEndSashDisposables); this.linkedEndSashDisposables = dispose(this.linkedEndSashDisposables);
if (this.el && this.el.parentElement) { if (this.el && this.el.parentElement) {
this.el.parentElement.removeChild(this.el); this.el.parentElement.removeChild(this.el);
......
...@@ -27,8 +27,8 @@ const defaultStyles: ISplitViewStyles = { ...@@ -27,8 +27,8 @@ const defaultStyles: ISplitViewStyles = {
export interface ISplitViewOptions { export interface ISplitViewOptions {
orientation?: Orientation; // default Orientation.VERTICAL orientation?: Orientation; // default Orientation.VERTICAL
styles?: ISplitViewStyles; styles?: ISplitViewStyles;
orthogonalStartSash?: Sash; linkedStartSash?: Sash;
orthogonalEndSash?: Sash; linkedEndSash?: Sash;
} }
export interface IView { export interface IView {
...@@ -139,24 +139,24 @@ export class SplitView implements IDisposable { ...@@ -139,24 +139,24 @@ export class SplitView implements IDisposable {
return this.viewItems.length; return this.viewItems.length;
} }
private _orthogonalStartSash: Sash | undefined; private _linkedStartSashes: Sash[] = [];
get orthogonalStartSash(): Sash | undefined { return this._orthogonalStartSash; } get linkedStartSashes(): Sash[] { return this._linkedStartSashes; }
set orthogonalStartSash(sash: Sash | undefined) { set linkedStartSashes(sashes: Sash[]) {
for (const sashItem of this.sashItems) { for (const sashItem of this.sashItems) {
sashItem.sash.orthogonalStartSash = sash; sashItem.sash.linkedStartSashes = sashes;
} }
this._orthogonalStartSash = sash; this._linkedStartSashes = sashes;
} }
private _orthogonalEndSash: Sash | undefined; private _linkedEndSashes: Sash[] = [];
get orthogonalEndSash(): Sash | undefined { return this._orthogonalEndSash; } get linkedEndSashes(): Sash[] { return this._linkedEndSashes; }
set orthogonalEndSash(sash: Sash | undefined) { set linkedEndSashes(sashes: Sash[]) {
for (const sashItem of this.sashItems) { for (const sashItem of this.sashItems) {
sashItem.sash.orthogonalEndSash = sash; sashItem.sash.linkedEndSash = sashes;
} }
this._orthogonalEndSash = sash; this._linkedEndSashes = sashes;
} }
get sashes(): Sash[] { get sashes(): Sash[] {
...@@ -235,8 +235,8 @@ export class SplitView implements IDisposable { ...@@ -235,8 +235,8 @@ export class SplitView implements IDisposable {
const layoutProvider = this.orientation === Orientation.VERTICAL ? { getHorizontalSashTop: sash => this.getSashPosition(sash) } : { getVerticalSashLeft: sash => this.getSashPosition(sash) }; const layoutProvider = this.orientation === Orientation.VERTICAL ? { getHorizontalSashTop: sash => this.getSashPosition(sash) } : { getVerticalSashLeft: sash => this.getSashPosition(sash) };
const sash = new Sash(this.sashContainer, layoutProvider, { const sash = new Sash(this.sashContainer, layoutProvider, {
orientation, orientation,
orthogonalStartSash: this.orthogonalStartSash, linkedStartSashes: this.linkedStartSashes,
orthogonalEndSash: this.orthogonalEndSash linkedEndSashes: this.linkedEndSashes
}); });
const sashEventMapper = this.orientation === Orientation.VERTICAL const sashEventMapper = this.orientation === Orientation.VERTICAL
? (e: IBaseSashEvent) => ({ sash, start: e.startY, current: e.currentY }) ? (e: IBaseSashEvent) => ({ sash, start: e.startY, current: e.currentY })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册