diff --git a/packages/dockview/src/api/groupPanelApi.ts b/packages/dockview/src/api/groupPanelApi.ts index 1d41cfa1d..bdcc5ff1b 100644 --- a/packages/dockview/src/api/groupPanelApi.ts +++ b/packages/dockview/src/api/groupPanelApi.ts @@ -7,6 +7,10 @@ export interface TitleEvent { title: string; } +export interface SuppressClosableEvent { + suppressClosable: boolean; +} + /* * omit visibility modifiers since the visibility of a single group doesn't make sense * because it belongs to a groupview @@ -15,9 +19,10 @@ export interface IDockviewPanelApi extends Omit { readonly group: GroupviewPanel | undefined; readonly isGroupActive: boolean; + readonly title: string; + readonly suppressClosable: boolean; onDidDirtyChange: Event; close: () => Promise; - tryClose: undefined | (() => Promise); interceptOnCloseAction(interceptor: () => Promise): void; setTitle(title: string): void; } @@ -38,6 +43,12 @@ export class DockviewPanelApi readonly _onDidTitleChange = new Emitter(); readonly onDidTitleChange = this._onDidTitleChange.event; + readonly _titleChanged = new Emitter(); + readonly titleChanged = this._titleChanged.event; + + readonly _suppressClosableChanged = new Emitter(); + readonly suppressClosableChanged = this._suppressClosableChanged.event; + // get isGroupVisible() { // return this._isGroupVisible; // } @@ -46,6 +57,14 @@ export class DockviewPanelApi return this._interceptor; } + get title() { + return this.panel.params?.title || ''; + } + + get suppressClosable() { + return !!this.panel.params?.suppressClosable; + } + get isGroupActive() { return !!this.group?.isActive; } diff --git a/packages/dockview/src/dockview/options.ts b/packages/dockview/src/dockview/options.ts index ca672b5e6..c071dfeac 100644 --- a/packages/dockview/src/dockview/options.ts +++ b/packages/dockview/src/dockview/options.ts @@ -49,11 +49,6 @@ export interface ViewFactoryData { } export interface DockviewOptions extends DockviewRenderFunctions { - // viewFactory: ( - // id: string, - // data: ViewFactoryData, - // options: DockviewRenderFunctions - // ) => IGroupPanelView; watermarkComponent?: WatermarkConstructor; watermarkFrameworkComponent?: any; frameworkComponentFactory?: GroupPanelFrameworkComponentFactory; diff --git a/packages/dockview/src/groupview/groupPanel.ts b/packages/dockview/src/groupview/groupPanel.ts index fe81c2cec..0cd348d43 100644 --- a/packages/dockview/src/groupview/groupPanel.ts +++ b/packages/dockview/src/groupview/groupPanel.ts @@ -22,6 +22,7 @@ export interface IGroupPanel extends IDisposable, IPanel { readonly view?: IGroupPanelView; readonly group?: GroupviewPanel; readonly api: IDockviewPanelApi; + readonly params?: IGroupPanelInitParameters; updateParentGroup(group: GroupviewPanel, isGroupActive: boolean): void; setDirty(isDirty: boolean): void; close?(): Promise; @@ -44,12 +45,16 @@ export class GroupPanel extends CompositeDisposable implements IGroupPanel { readonly api: DockviewPanelApi; private _group: GroupviewPanel | undefined; - private params?: IGroupPanelInitParameters; + private _params?: IGroupPanelInitParameters; readonly onDidStateChange: Event; private _view?: IGroupPanelView; + get params() { + return this._params; + } + get group(): GroupviewPanel | undefined { return this._group; } @@ -63,7 +68,6 @@ export class GroupPanel extends CompositeDisposable implements IGroupPanel { private readonly containerApi: DockviewApi ) { super(); - this.api = new DockviewPanelApi(this, this._group); this.onDidStateChange = this.api.onDidStateChange; @@ -95,7 +99,7 @@ export class GroupPanel extends CompositeDisposable implements IGroupPanel { } public toJSON(): GroupviewPanelState { - const params = this.params?.params; + const params = this._params?.params; const state = this.api.getState(); return { @@ -103,22 +107,44 @@ export class GroupPanel extends CompositeDisposable implements IGroupPanel { view: this.view!.toJSON(), params: params && Object.keys(params).length > 0 ? params : undefined, - title: this.params?.title as string, - suppressClosable: this.params?.suppressClosable, + title: this._params?.title as string, + suppressClosable: this._params?.suppressClosable, state: state && Object.keys(state).length > 0 ? state : undefined, }; } - public update(params: PanelUpdateEvent): void { - if (this.params) { - this.params.params = { ...(this.params?.params || {}), ...params }; + public update(params: PanelUpdateEvent): void { + let didTitleChange = false; + let didSuppressChangableClose = false; + + const innerParams = params.params as IGroupPanelInitParameters; + + if (this._params) { + didTitleChange = this._params.title !== innerParams.title; + didSuppressChangableClose = + this._params.suppressClosable !== innerParams.suppressClosable; + + this._params.params = { + ...(this._params?.params || {}), + ...params, + }; + } + + if (didTitleChange) { + this.api._titleChanged.fire({ title: innerParams.title }); + } + + if (didSuppressChangableClose) { + this.api._suppressClosableChanged.fire({ + suppressClosable: !!innerParams.suppressClosable, + }); } this.view?.update(params); } public init(params: IGroupPanelInitParameters): void { - this.params = params; + this._params = params; this._view = params.view; if (params.state) { diff --git a/packages/dockview/src/panel/types.ts b/packages/dockview/src/panel/types.ts index 96f10c8fd..0667a9815 100644 --- a/packages/dockview/src/panel/types.ts +++ b/packages/dockview/src/panel/types.ts @@ -14,15 +14,15 @@ export interface PanelInitParameters { state?: State; } -export interface PanelUpdateEvent { - params: Parameters; +export interface PanelUpdateEvent { + params: Partial; } export interface IPanel extends IDisposable { readonly id: string; init(params: PanelInitParameters): void; layout(width: number, height: number): void; - update(event: PanelUpdateEvent): void; + update(event: PanelUpdateEvent): void; toJSON(): object; focus(): void; }