feat: expose .title and .suppressClosable values/events through api

This commit is contained in:
mathuo 2021-04-10 16:29:41 +01:00
parent 24c98c5830
commit c98121edd6
4 changed files with 58 additions and 18 deletions

View File

@ -7,6 +7,10 @@ export interface TitleEvent {
title: string; title: string;
} }
export interface SuppressClosableEvent {
suppressClosable: boolean;
}
/* /*
* omit visibility modifiers since the visibility of a single group doesn't make sense * omit visibility modifiers since the visibility of a single group doesn't make sense
* because it belongs to a groupview * because it belongs to a groupview
@ -15,9 +19,10 @@ export interface IDockviewPanelApi
extends Omit<IGridviewPanelApi, 'setVisible' | 'visible'> { extends Omit<IGridviewPanelApi, 'setVisible' | 'visible'> {
readonly group: GroupviewPanel | undefined; readonly group: GroupviewPanel | undefined;
readonly isGroupActive: boolean; readonly isGroupActive: boolean;
readonly title: string;
readonly suppressClosable: boolean;
onDidDirtyChange: Event<boolean>; onDidDirtyChange: Event<boolean>;
close: () => Promise<boolean>; close: () => Promise<boolean>;
tryClose: undefined | (() => Promise<boolean>);
interceptOnCloseAction(interceptor: () => Promise<boolean>): void; interceptOnCloseAction(interceptor: () => Promise<boolean>): void;
setTitle(title: string): void; setTitle(title: string): void;
} }
@ -38,6 +43,12 @@ export class DockviewPanelApi
readonly _onDidTitleChange = new Emitter<TitleEvent>(); readonly _onDidTitleChange = new Emitter<TitleEvent>();
readonly onDidTitleChange = this._onDidTitleChange.event; readonly onDidTitleChange = this._onDidTitleChange.event;
readonly _titleChanged = new Emitter<TitleEvent>();
readonly titleChanged = this._titleChanged.event;
readonly _suppressClosableChanged = new Emitter<SuppressClosableEvent>();
readonly suppressClosableChanged = this._suppressClosableChanged.event;
// get isGroupVisible() { // get isGroupVisible() {
// return this._isGroupVisible; // return this._isGroupVisible;
// } // }
@ -46,6 +57,14 @@ export class DockviewPanelApi
return this._interceptor; return this._interceptor;
} }
get title() {
return this.panel.params?.title || '';
}
get suppressClosable() {
return !!this.panel.params?.suppressClosable;
}
get isGroupActive() { get isGroupActive() {
return !!this.group?.isActive; return !!this.group?.isActive;
} }

View File

@ -49,11 +49,6 @@ export interface ViewFactoryData {
} }
export interface DockviewOptions extends DockviewRenderFunctions { export interface DockviewOptions extends DockviewRenderFunctions {
// viewFactory: (
// id: string,
// data: ViewFactoryData,
// options: DockviewRenderFunctions
// ) => IGroupPanelView;
watermarkComponent?: WatermarkConstructor; watermarkComponent?: WatermarkConstructor;
watermarkFrameworkComponent?: any; watermarkFrameworkComponent?: any;
frameworkComponentFactory?: GroupPanelFrameworkComponentFactory; frameworkComponentFactory?: GroupPanelFrameworkComponentFactory;

View File

@ -22,6 +22,7 @@ export interface IGroupPanel extends IDisposable, IPanel {
readonly view?: IGroupPanelView; readonly view?: IGroupPanelView;
readonly group?: GroupviewPanel; readonly group?: GroupviewPanel;
readonly api: IDockviewPanelApi; readonly api: IDockviewPanelApi;
readonly params?: IGroupPanelInitParameters;
updateParentGroup(group: GroupviewPanel, isGroupActive: boolean): void; updateParentGroup(group: GroupviewPanel, isGroupActive: boolean): void;
setDirty(isDirty: boolean): void; setDirty(isDirty: boolean): void;
close?(): Promise<boolean>; close?(): Promise<boolean>;
@ -44,12 +45,16 @@ export class GroupPanel extends CompositeDisposable implements IGroupPanel {
readonly api: DockviewPanelApi; readonly api: DockviewPanelApi;
private _group: GroupviewPanel | undefined; private _group: GroupviewPanel | undefined;
private params?: IGroupPanelInitParameters; private _params?: IGroupPanelInitParameters;
readonly onDidStateChange: Event<void>; readonly onDidStateChange: Event<void>;
private _view?: IGroupPanelView; private _view?: IGroupPanelView;
get params() {
return this._params;
}
get group(): GroupviewPanel | undefined { get group(): GroupviewPanel | undefined {
return this._group; return this._group;
} }
@ -63,7 +68,6 @@ export class GroupPanel extends CompositeDisposable implements IGroupPanel {
private readonly containerApi: DockviewApi private readonly containerApi: DockviewApi
) { ) {
super(); super();
this.api = new DockviewPanelApi(this, this._group); this.api = new DockviewPanelApi(this, this._group);
this.onDidStateChange = this.api.onDidStateChange; this.onDidStateChange = this.api.onDidStateChange;
@ -95,7 +99,7 @@ export class GroupPanel extends CompositeDisposable implements IGroupPanel {
} }
public toJSON(): GroupviewPanelState { public toJSON(): GroupviewPanelState {
const params = this.params?.params; const params = this._params?.params;
const state = this.api.getState(); const state = this.api.getState();
return { return {
@ -103,22 +107,44 @@ export class GroupPanel extends CompositeDisposable implements IGroupPanel {
view: this.view!.toJSON(), view: this.view!.toJSON(),
params: params:
params && Object.keys(params).length > 0 ? params : undefined, params && Object.keys(params).length > 0 ? params : undefined,
title: this.params?.title as string, title: this._params?.title as string,
suppressClosable: this.params?.suppressClosable, suppressClosable: this._params?.suppressClosable,
state: state && Object.keys(state).length > 0 ? state : undefined, state: state && Object.keys(state).length > 0 ? state : undefined,
}; };
} }
public update(params: PanelUpdateEvent): void { public update(params: PanelUpdateEvent<IGroupPanelInitParameters>): void {
if (this.params) { let didTitleChange = false;
this.params.params = { ...(this.params?.params || {}), ...params }; 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); this.view?.update(params);
} }
public init(params: IGroupPanelInitParameters): void { public init(params: IGroupPanelInitParameters): void {
this.params = params; this._params = params;
this._view = params.view; this._view = params.view;
if (params.state) { if (params.state) {

View File

@ -14,15 +14,15 @@ export interface PanelInitParameters {
state?: State; state?: State;
} }
export interface PanelUpdateEvent { export interface PanelUpdateEvent<T extends Parameters = Parameters> {
params: Parameters; params: Partial<T>;
} }
export interface IPanel extends IDisposable { export interface IPanel extends IDisposable {
readonly id: string; readonly id: string;
init(params: PanelInitParameters): void; init(params: PanelInitParameters): void;
layout(width: number, height: number): void; layout(width: number, height: number): void;
update(event: PanelUpdateEvent): void; update(event: PanelUpdateEvent<Parameters>): void;
toJSON(): object; toJSON(): object;
focus(): void; focus(): void;
} }