feat: add event

This commit is contained in:
mathuo 2022-03-17 20:14:05 +00:00
parent b14443c009
commit 87eb58d49f
No known key found for this signature in database
GPG Key ID: C6EEDEFD6CA07281
4 changed files with 73 additions and 7 deletions

View File

@ -91,6 +91,10 @@ describe('component.api', () => {
'focus',
'resizeToFit',
'toJSON',
'onDidActiveGroupChange',
'onDidAddGroup',
'onDidRemoveGroup',
'onDidLayoutFromJSON',
];
for (const _ of list) {
@ -130,6 +134,13 @@ describe('component.api', () => {
'closeAllGroups',
'resizeToFit',
'toJSON',
'onDidActiveGroupChange',
'onDidAddGroup',
'onDidRemoveGroup',
'onDidActivePanelChange',
'onDidAddPanel',
'onDidRemovePanel',
'onDidLayoutfromJSON',
];
for (const _ of list) {

View File

@ -255,6 +255,22 @@ export class GridviewApi implements CommonApi {
return this.component.onDidLayoutChange;
}
get onDidAddGroup(): Event<IGridviewPanel> {
return this.component.onDidAddGroup;
}
get onDidRemoveGroup(): Event<IGridviewPanel> {
return this.component.onDidRemoveGroup;
}
get onDidActiveGroupChange(): Event<IGridviewPanel | undefined> {
return this.component.onDidActiveGroupChange;
}
get onDidLayoutFromJSON(): Event<void> {
return this.component.onDidLayoutFromJSON;
}
get panels(): IGridviewPanel[] {
return this.component.groups;
}
@ -358,6 +374,34 @@ export class DockviewApi implements CommonApi {
return this.component.onGridEvent;
}
get onDidActiveGroupChange(): Event<IGroupviewPanel | undefined> {
return this.component.onDidActiveGroupChange;
}
get onDidAddGroup(): Event<IGroupviewPanel> {
return this.component.onDidAddGroup;
}
get onDidRemoveGroup(): Event<IGroupviewPanel> {
return this.component.onDidRemoveGroup;
}
get onDidActivePanelChange(): Event<IGroupPanel | undefined> {
return this.component.onDidActivePanelChange;
}
get onDidAddPanel(): Event<IGroupPanel> {
return this.component.onDidAddPanel;
}
get onDidRemovePanel(): Event<IGroupPanel> {
return this.component.onDidRemovePanel;
}
get onDidLayoutfromJSON(): Event<void> {
return this.component.onDidLayoutfromJSON;
}
get onDidLayoutChange(): Event<void> {
return this.component.onDidLayoutChange;
}

View File

@ -115,6 +115,7 @@ export interface IDockviewComponent extends IBaseGrid<GroupviewPanel> {
//
readonly onDidRemovePanel: Event<IGroupPanel>;
readonly onDidAddPanel: Event<IGroupPanel>;
readonly onDidLayoutfromJSON: Event<void>;
readonly onDidActivePanelChange: Event<IGroupPanel | undefined>;
}
@ -122,7 +123,9 @@ export class DockviewComponent
extends BaseGrid<GroupviewPanel>
implements IDockviewComponent
{
// private readonly _panels = new Map<string, IValueDisposable<IGroupPanel>>();
private _deserializer: IPanelDeserializer | undefined;
private _api: DockviewApi;
private _options: DockviewComponentOptions;
// events
private readonly _onTabInteractionEvent = new Emitter<LayoutMouseEvent>();
@ -143,17 +146,15 @@ export class DockviewComponent
private readonly _onDidAddPanel = new Emitter<IGroupPanel>();
readonly onDidAddPanel: Event<IGroupPanel> = this._onDidAddPanel.event;
private readonly _onDidLayoutfromJSON = new Emitter<void>();
readonly onDidLayoutfromJSON: Event<void> = this._onDidLayoutfromJSON.event;
private readonly _onDidActivePanelChange = new Emitter<
IGroupPanel | undefined
>();
readonly onDidActivePanelChange: Event<IGroupPanel | undefined> =
this._onDidActivePanelChange.event;
// everything else
private _deserializer: IPanelDeserializer | undefined;
private _api: DockviewApi;
private _options: DockviewComponentOptions;
get totalPanels(): number {
return this.panels.length;
}
@ -373,6 +374,7 @@ export class DockviewComponent
this.gridview.layout(this.width, this.height);
this._onGridEvent.fire({ kind: GroupChangeKind.LAYOUT_FROM_JSON });
this._onDidLayoutfromJSON.fire();
}
closeAllGroups(): void {
@ -602,7 +604,7 @@ export class DockviewComponent
override doSetGroupActive(
group: GroupviewPanel | undefined,
skipFocus?: boolean
) {
): void {
const isGroupAlreadyFocused = this._activeGroup === group;
super.doSetGroupActive(group, skipFocus);
@ -767,5 +769,6 @@ export class DockviewComponent
this._onDidActivePanelChange.dispose();
this._onDidAddPanel.dispose();
this._onDidRemovePanel.dispose();
this._onDidLayoutfromJSON.dispose();
}
}

View File

@ -27,6 +27,7 @@ import { GridviewPanelApiImpl } from '../api/gridviewPanelApi';
import { GridviewApi } from '../api/component.api';
import { Orientation, Sizing } from '../splitview/core/splitview';
import { createComponent } from '../panel/componentFactory';
import { Emitter, Event } from '../events';
interface PanelReference {
api: GridviewPanelApiImpl;
@ -66,6 +67,7 @@ export type GridviewComponentUpdateOptions = Pick<
export interface IGridviewComponent extends IBaseGrid<GridviewPanel> {
readonly orientation: Orientation;
readonly onDidLayoutFromJSON: Event<void>;
updateOptions(options: Partial<GridviewComponentUpdateOptions>): void;
addPanel(options: AddComponentOptions): void;
removePanel(panel: IGridviewPanel, sizing?: Sizing): void;
@ -91,6 +93,9 @@ export class GridviewComponent
private _options: GridviewComponentOptions;
private _deserializer: IPanelDeserializer | undefined;
private readonly _onDidLayoutfromJSON = new Emitter<void>();
readonly onDidLayoutFromJSON: Event<void> = this._onDidLayoutfromJSON.event;
get orientation() {
return this.gridview.orientation;
}
@ -249,6 +254,7 @@ export class GridviewComponent
}
this._onGridEvent.fire({ kind: GroupChangeKind.LAYOUT_FROM_JSON });
this._onDidLayoutfromJSON.fire();
}
movePanel(
@ -427,5 +433,7 @@ export class GridviewComponent
public dispose() {
super.dispose();
this._onDidLayoutfromJSON.dispose();
}
}