feat: locked mode

This commit is contained in:
mathuo 2024-01-19 14:17:37 +00:00
parent 6c670c1fbb
commit 22ba48e81e
No known key found for this signature in database
GPG Key ID: C6EEDEFD6CA07281
8 changed files with 90 additions and 8 deletions

View File

@ -369,6 +369,7 @@ export class DockviewComponent
styles: options.styles,
parentElement: options.parentElement,
disableAutoResizing: options.disableAutoResizing,
locked: options.locked,
});
const gready = document.createElement('div');

View File

@ -101,6 +101,7 @@ export interface DockviewComponentOptions extends DockviewRenderFunctions {
defaultRenderer?: DockviewPanelRenderer;
debug?: boolean;
rootOverlayModel?: DroptargetOverlayModel;
locked?: boolean;
}
export interface PanelOptions<P extends object = Parameters> {

View File

@ -34,6 +34,7 @@ export interface BaseGridOptions {
readonly styles?: ISplitviewStyles;
readonly parentElement?: HTMLElement;
readonly disableAutoResizing?: boolean;
readonly locked?: boolean;
}
export interface IGridPanelView extends IGridView, IPanel {
@ -133,6 +134,14 @@ export abstract class BaseGrid<T extends IGridPanelView>
return this._activeGroup;
}
get locked(): boolean {
return this.gridview.locked;
}
set locked(value: boolean) {
this.gridview.locked = value;
}
constructor(options: BaseGridOptions) {
super(options.parentElement, options.disableAutoResizing);
@ -142,6 +151,8 @@ export abstract class BaseGrid<T extends IGridPanelView>
options.orientation
);
this.gridview.locked = !!options.locked;
this.element.appendChild(this.gridview.element);
this.layout(0, 0, true); // set some elements height/widths

View File

@ -131,17 +131,27 @@ export class BranchNode extends CompositeDisposable implements IView {
return LayoutPriority.Normal;
}
get locked(): boolean {
return this.splitview.locked;
}
set locked(value: boolean) {
this.splitview.locked = value;
}
constructor(
readonly orientation: Orientation,
readonly proportionalLayout: boolean,
readonly styles: ISplitviewStyles | undefined,
size: number,
orthogonalSize: number,
disabled: boolean,
childDescriptors?: INodeDescriptor[]
) {
super();
this._orthogonalSize = orthogonalSize;
this._size = size;
this.element = document.createElement('div');
this.element.className = 'branch-node';
@ -177,6 +187,8 @@ export class BranchNode extends CompositeDisposable implements IView {
});
}
this.locked = disabled;
this.addDisposables(
this._onDidChange,
this._onDidVisibilityChange,
@ -202,7 +214,7 @@ export class BranchNode extends CompositeDisposable implements IView {
return this.splitview.isViewVisible(index);
}
setChildVisible(index: number, visible: boolean): void {
setChildVisible(index: number, visible: boolean): void {
if (index < 0 || index >= this.children.length) {
throw new Error('Invalid index');
}

View File

@ -41,7 +41,8 @@ function flipNode<T extends Node>(
node.proportionalLayout,
node.styles,
size,
orthogonalSize
orthogonalSize,
node.locked
);
let totalSize = 0;
@ -273,6 +274,7 @@ export class Gridview implements IDisposable {
readonly element: HTMLElement;
private _root: BranchNode | undefined;
private _locked = false;
private _maximizedNode: LeafNode | undefined = undefined;
private readonly disposable: MutableDisposable = new MutableDisposable();
@ -328,6 +330,30 @@ export class Gridview implements IDisposable {
return this.root.maximumHeight;
}
get locked(): boolean {
return this._locked;
}
set locked(value: boolean) {
this._locked = value;
const branch: Node[] = [this.root];
/**
* simple depth-first-search to cover all nodes
*
* @see https://en.wikipedia.org/wiki/Depth-first_search
*/
while (branch.length > 0) {
const node = branch.pop();
if (node instanceof BranchNode) {
node.locked = value;
branch.push(...node.children);
}
}
}
maximizedView(): IGridView | undefined {
return this._maximizedNode?.view;
}
@ -427,7 +453,8 @@ export class Gridview implements IDisposable {
this.proportionalLayout,
this.styles,
this.root.size,
this.root.orthogonalSize
this.root.orthogonalSize,
this._locked
);
}
@ -487,8 +514,8 @@ export class Gridview implements IDisposable {
this.proportionalLayout,
this.styles,
node.size, // <- orthogonal size - flips at each depth
orthogonalSize, // <- size - flips at each depth
orthogonalSize, // <- size - flips at each depth,
this._locked,
children
);
} else {
@ -540,7 +567,8 @@ export class Gridview implements IDisposable {
this.proportionalLayout,
this.styles,
this.root.orthogonalSize,
this.root.size
this.root.size,
this._locked
);
if (oldRoot.children.length === 0) {
@ -655,7 +683,8 @@ export class Gridview implements IDisposable {
proportionalLayout,
styles,
0,
0
0,
this._locked
);
}
@ -739,7 +768,8 @@ export class Gridview implements IDisposable {
this.proportionalLayout,
this.styles,
parent.size,
parent.orthogonalSize
parent.orthogonalSize,
this._locked
);
grandParent.addChild(newParent, parent.size, parentIndex);

View File

@ -25,6 +25,12 @@
height: 100%;
width: 100%;
&.dv-splitview-locked {
& > .sash-container > .sash {
pointer-events: none;
}
}
&.animation {
.view,
.sash {

View File

@ -109,6 +109,7 @@ export class Splitview {
private proportionalLayout: boolean;
private _startSnappingEnabled = true;
private _endSnappingEnabled = true;
private _disabled = false;
private readonly _onDidSashEnd = new Emitter<void>();
readonly onDidSashEnd = this._onDidSashEnd.event;
@ -200,6 +201,16 @@ export class Splitview {
this.updateSashEnablement();
}
get locked(): boolean {
return this._disabled;
}
set locked(value: boolean) {
this._disabled = value;
toggleClass(this.element, 'dv-splitview-locked', value);
}
constructor(
private readonly container: HTMLElement,
options: SplitViewOptions

View File

@ -81,6 +81,7 @@ export interface IDockviewReactProps {
debug?: boolean;
defaultRenderer?: DockviewPanelRenderer;
rootOverlayModel?: DroptargetOverlayModel;
locked?: boolean;
}
const DEFAULT_REACT_TAB = 'props.defaultTabComponent';
@ -183,6 +184,7 @@ export const DockviewReact = React.forwardRef(
defaultRenderer: props.defaultRenderer,
debug: props.debug,
rootOverlayModel: props.rootOverlayModel,
locked: props.locked,
});
const { clientWidth, clientHeight } = domRef.current;
@ -199,6 +201,14 @@ export const DockviewReact = React.forwardRef(
};
}, []);
React.useEffect(() => {
if (!dockviewRef.current) {
return;
}
dockviewRef.current.locked = !!props.locked;
}, [props.locked]);
React.useEffect(() => {
if (!dockviewRef.current) {
return () => {