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;
}
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<IGridviewPanelApi, 'setVisible' | 'visible'> {
readonly group: GroupviewPanel | undefined;
readonly isGroupActive: boolean;
readonly title: string;
readonly suppressClosable: boolean;
onDidDirtyChange: Event<boolean>;
close: () => Promise<boolean>;
tryClose: undefined | (() => Promise<boolean>);
interceptOnCloseAction(interceptor: () => Promise<boolean>): void;
setTitle(title: string): void;
}
@ -38,6 +43,12 @@ export class DockviewPanelApi
readonly _onDidTitleChange = new Emitter<TitleEvent>();
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() {
// 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;
}

View File

@ -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;

View File

@ -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<boolean>;
@ -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<void>;
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<IGroupPanelInitParameters>): 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) {

View File

@ -14,15 +14,15 @@ export interface PanelInitParameters {
state?: State;
}
export interface PanelUpdateEvent {
params: Parameters;
export interface PanelUpdateEvent<T extends Parameters = Parameters> {
params: Partial<T>;
}
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<Parameters>): void;
toJSON(): object;
focus(): void;
}