feat: enhance maximize group api methods

This commit is contained in:
mathuo 2024-01-03 13:51:43 +00:00
parent 3e9f96bdbf
commit b222de86f7
No known key found for this signature in database
GPG Key ID: C6EEDEFD6CA07281
5 changed files with 80 additions and 12 deletions

View File

@ -842,6 +842,11 @@ describe('gridview', () => {
); );
gridview.layout(1000, 1000); gridview.layout(1000, 1000);
let counter = 0;
const subscription = gridview.onDidMaxmizedNodeChange(() => {
counter++;
});
const view1 = new MockGridview('1'); const view1 = new MockGridview('1');
const view2 = new MockGridview('2'); const view2 = new MockGridview('2');
const view3 = new MockGridview('3'); const view3 = new MockGridview('3');
@ -891,18 +896,25 @@ describe('gridview', () => {
// base case assertions // base case assertions
assertLayout(); assertLayout();
expect(gridview.hasMaximizedView()).toBeFalsy(); expect(gridview.hasMaximizedView()).toBeFalsy();
expect(counter).toBe(0);
/** /**
* maximize each view individually and then return to the standard view * maximize each view individually and then return to the standard view
* checking on each iteration that the original layout dimensions * checking on each iteration that the original layout dimensions
* are restored * are restored
*/ */
for (const view of views) { for (let i = 0; i < views.length; i++) {
const view = views[i];
gridview.maximizeView(view); gridview.maximizeView(view);
expect(counter).toBe(i * 2 + 1);
expect(gridview.hasMaximizedView()).toBeTruthy(); expect(gridview.hasMaximizedView()).toBeTruthy();
gridview.exitMaximizedView(); gridview.exitMaximizedView();
expect(counter).toBe(i * 2 + 2);
assertLayout(); assertLayout();
} }
subscription.dispose();
}); });
test('that maximizedView is exited when a views visibility is changed', () => { test('that maximizedView is exited when a views visibility is changed', () => {

View File

@ -9,12 +9,18 @@ export interface DockviewGroupPanelApi extends GridviewPanelApi {
readonly onDidRenderPositionChange: Event<DockviewGroupPanelFloatingChangeEvent>; readonly onDidRenderPositionChange: Event<DockviewGroupPanelFloatingChangeEvent>;
readonly location: DockviewGroupLocation; readonly location: DockviewGroupLocation;
moveTo(options: { group: DockviewGroupPanel; position?: Position }): void; moveTo(options: { group: DockviewGroupPanel; position?: Position }): void;
maximize(): void;
isMaximized(): boolean;
exitMaximized(): void;
} }
export interface DockviewGroupPanelFloatingChangeEvent { export interface DockviewGroupPanelFloatingChangeEvent {
readonly location: DockviewGroupLocation; readonly location: DockviewGroupLocation;
} }
// TODO find a better way to initialize and avoid needing null checks
const NOT_INITIALIZED_MESSAGE = 'DockviewGroupPanelApiImpl not initialized';
export class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl { export class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl {
private _group: DockviewGroupPanel | undefined; private _group: DockviewGroupPanel | undefined;
@ -25,7 +31,7 @@ export class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl {
get location(): DockviewGroupLocation { get location(): DockviewGroupLocation {
if (!this._group) { if (!this._group) {
throw new Error(`DockviewGroupPanelApiImpl not initialized`); throw new Error(NOT_INITIALIZED_MESSAGE);
} }
return this._group.model.location; return this._group.model.location;
} }
@ -38,7 +44,7 @@ export class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl {
moveTo(options: { group: DockviewGroupPanel; position?: Position }): void { moveTo(options: { group: DockviewGroupPanel; position?: Position }): void {
if (!this._group) { if (!this._group) {
throw new Error(`DockviewGroupPanelApiImpl not initialized`); throw new Error(NOT_INITIALIZED_MESSAGE);
} }
this.accessor.moveGroupOrPanel( this.accessor.moveGroupOrPanel(
@ -49,6 +55,32 @@ export class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl {
); );
} }
maximize(): void {
if (!this._group) {
throw new Error(NOT_INITIALIZED_MESSAGE);
}
this.accessor.maximizeGroup(this._group);
}
isMaximized(): boolean {
if (!this._group) {
throw new Error(NOT_INITIALIZED_MESSAGE);
}
return this.accessor.isMaximizedGroup(this._group);
}
exitMaximized(): void {
if (!this._group) {
throw new Error(NOT_INITIALIZED_MESSAGE);
}
if (this.isMaximized()) {
this.accessor.exitMaximizedGroup();
}
}
initialize(group: DockviewGroupPanel): void { initialize(group: DockviewGroupPanel): void {
this._group = group; this._group = group;
} }

View File

@ -2,7 +2,7 @@ import { Emitter, Event } from '../events';
import { GridviewPanelApiImpl, GridviewPanelApi } from './gridviewPanelApi'; import { GridviewPanelApiImpl, GridviewPanelApi } from './gridviewPanelApi';
import { DockviewGroupPanel } from '../dockview/dockviewGroupPanel'; import { DockviewGroupPanel } from '../dockview/dockviewGroupPanel';
import { MutableDisposable } from '../lifecycle'; import { MutableDisposable } from '../lifecycle';
import { DockviewPanel, IDockviewPanel } from '../dockview/dockviewPanel'; import { DockviewPanel } from '../dockview/dockviewPanel';
import { DockviewComponent } from '../dockview/dockviewComponent'; import { DockviewComponent } from '../dockview/dockviewComponent';
import { Position } from '../dnd/droptarget'; import { Position } from '../dnd/droptarget';
import { DockviewPanelRenderer } from '../dockview/components/greadyRenderContainer'; import { DockviewPanelRenderer } from '../dockview/components/greadyRenderContainer';
@ -15,13 +15,10 @@ export interface RendererChangedEvent {
renderer: DockviewPanelRenderer; renderer: DockviewPanelRenderer;
} }
/*
* omit visibility modifiers since the visibility of a single group doesn't make sense
* because it belongs to a groupview
*/
export interface DockviewPanelApi export interface DockviewPanelApi
extends Omit< extends Omit<
GridviewPanelApi, GridviewPanelApi,
// omit properties that do not make sense here
'setVisible' | 'onDidConstraintsChange' | 'setConstraints' 'setVisible' | 'onDidConstraintsChange' | 'setConstraints'
> { > {
readonly group: DockviewGroupPanel; readonly group: DockviewGroupPanel;
@ -40,6 +37,8 @@ export interface DockviewPanelApi
index?: number; index?: number;
}): void; }): void;
maximize(): void; maximize(): void;
isMaximized(): boolean;
exitMaximized(): void;
} }
export class DockviewPanelApiImpl export class DockviewPanelApiImpl
@ -67,7 +66,7 @@ export class DockviewPanelApiImpl
} }
get isGroupActive(): boolean { get isGroupActive(): boolean {
return !!this.group?.isActive; return this.group.isActive;
} }
get renderer(): DockviewPanelRenderer { get renderer(): DockviewPanelRenderer {
@ -143,6 +142,14 @@ export class DockviewPanelApiImpl
} }
maximize(): void { maximize(): void {
this.accessor.maximizeGroup(this.panel.group); this.group.api.maximize();
}
isMaximized(): boolean {
return this.group.api.isMaximized();
}
exitMaximized(): void {
this.group.api.exitMaximized();
} }
} }

View File

@ -65,6 +65,7 @@ export interface IBaseGrid<T extends IGridPanelView> {
setVisible(panel: T, visible: boolean): void; setVisible(panel: T, visible: boolean): void;
isVisible(panel: T): boolean; isVisible(panel: T): boolean;
maximizeGroup(panel: T): void; maximizeGroup(panel: T): void;
isMaximizedGroup(panel: T): boolean;
exitMaximizedGroup(): void; exitMaximizedGroup(): void;
hasMaximizedGroup(): boolean; hasMaximizedGroup(): boolean;
readonly onDidMaxmizedGroupChange: Event<void>; readonly onDidMaxmizedGroupChange: Event<void>;
@ -182,6 +183,10 @@ export abstract class BaseGrid<T extends IGridPanelView>
this.gridview.maximizeView(panel); this.gridview.maximizeView(panel);
} }
isMaximizedGroup(panel: T): boolean {
return this.gridview.maximizedView() === panel;
}
exitMaximizedGroup(): void { exitMaximizedGroup(): void {
this.gridview.exitMaximizedView(); this.gridview.exitMaximizedView();
} }

View File

@ -273,7 +273,7 @@ export class Gridview implements IDisposable {
readonly element: HTMLElement; readonly element: HTMLElement;
private _root: BranchNode | undefined; private _root: BranchNode | undefined;
private _maximizedNode: Node | undefined = undefined; private _maximizedNode: LeafNode | undefined = undefined;
private readonly disposable: MutableDisposable = new MutableDisposable(); private readonly disposable: MutableDisposable = new MutableDisposable();
private readonly _onDidChange = new Emitter<{ private readonly _onDidChange = new Emitter<{
@ -307,6 +307,7 @@ export class Gridview implements IDisposable {
get width(): number { get width(): number {
return this.root.width; return this.root.width;
} }
get height(): number { get height(): number {
return this.root.height; return this.root.height;
} }
@ -314,16 +315,23 @@ export class Gridview implements IDisposable {
get minimumWidth(): number { get minimumWidth(): number {
return this.root.minimumWidth; return this.root.minimumWidth;
} }
get minimumHeight(): number { get minimumHeight(): number {
return this.root.minimumHeight; return this.root.minimumHeight;
} }
get maximumWidth(): number { get maximumWidth(): number {
return this.root.maximumHeight; return this.root.maximumHeight;
} }
get maximumHeight(): number { get maximumHeight(): number {
return this.root.maximumHeight; return this.root.maximumHeight;
} }
maximizedView(): IGridView | undefined {
return this._maximizedNode?.view;
}
hasMaximizedView(): boolean { hasMaximizedView(): boolean {
return this._maximizedNode !== undefined; return this._maximizedNode !== undefined;
} }
@ -332,6 +340,10 @@ export class Gridview implements IDisposable {
const location = getGridLocation(view.element); const location = getGridLocation(view.element);
const [_, node] = this.getNode(location); const [_, node] = this.getNode(location);
if (!(node instanceof LeafNode)) {
return;
}
if (this._maximizedNode === node) { if (this._maximizedNode === node) {
return; return;
} }
@ -353,7 +365,7 @@ export class Gridview implements IDisposable {
} }
} }
hideAllViewsBut(this.root, node as LeafNode); hideAllViewsBut(this.root, node);
this._maximizedNode = node; this._maximizedNode = node;
this._onDidMaxmizedNodeChange.fire(); this._onDidMaxmizedNodeChange.fire();
} }