mirror of
https://github.com/mathuo/dockview
synced 2025-09-14 05:07:59 +00:00
feat: events cleanup
This commit is contained in:
parent
807ccf80de
commit
284fb1440b
@ -196,10 +196,7 @@ export class TestPanel implements IDockviewPanel {
|
|||||||
this._params = params;
|
this._params = params;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateParentGroup(
|
updateParentGroup(group: DockviewGroupPanel): void {
|
||||||
group: DockviewGroupPanel,
|
|
||||||
options: { isGroupActive: boolean }
|
|
||||||
): void {
|
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -631,7 +628,7 @@ describe('dockviewGroupPanelModel', () => {
|
|||||||
renderer: 'onlyWhenVisibile',
|
renderer: 'onlyWhenVisibile',
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
cut.openPanel(panel3, { skipRender: true });
|
cut.openPanel(panel3, { skipSetActive: true });
|
||||||
expect(contentContainer.length).toBe(1);
|
expect(contentContainer.length).toBe(1);
|
||||||
expect(contentContainer.item(0)).toBe(panel2.view.content.element);
|
expect(contentContainer.item(0)).toBe(panel2.view.content.element);
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ describe('componentPaneview', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
paneview.layout(600, 400);
|
paneview.layout(300, 200);
|
||||||
|
|
||||||
paneview.addPanel({
|
paneview.addPanel({
|
||||||
id: 'panel1',
|
id: 'panel1',
|
||||||
@ -108,6 +108,8 @@ describe('componentPaneview', () => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
paneview.layout(600, 400);
|
||||||
|
|
||||||
expect(panel1Dimensions).toEqual({ width: 600, height: 22 });
|
expect(panel1Dimensions).toEqual({ width: 600, height: 22 });
|
||||||
expect(panel2Dimensions).toEqual({ width: 600, height: 22 });
|
expect(panel2Dimensions).toEqual({ width: 600, height: 22 });
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ describe('componentSplitview', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
splitview.layout(600, 400);
|
splitview.layout(300, 200);
|
||||||
|
|
||||||
splitview.addPanel({ id: 'panel1', component: 'testPanel' });
|
splitview.addPanel({ id: 'panel1', component: 'testPanel' });
|
||||||
splitview.addPanel({ id: 'panel2', component: 'testPanel' });
|
splitview.addPanel({ id: 'panel2', component: 'testPanel' });
|
||||||
@ -255,6 +255,8 @@ describe('componentSplitview', () => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
splitview.layout(600, 400);
|
||||||
|
|
||||||
expect(panel1Dimensions).toEqual({ width: 600, height: 200 });
|
expect(panel1Dimensions).toEqual({ width: 600, height: 200 });
|
||||||
expect(panel2Dimensions).toEqual({ width: 600, height: 200 });
|
expect(panel2Dimensions).toEqual({ width: 600, height: 200 });
|
||||||
|
|
||||||
@ -283,7 +285,7 @@ describe('componentSplitview', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
splitview.layout(600, 400);
|
splitview.layout(300, 200);
|
||||||
|
|
||||||
splitview.addPanel({ id: 'panel1', component: 'testPanel' });
|
splitview.addPanel({ id: 'panel1', component: 'testPanel' });
|
||||||
splitview.addPanel({ id: 'panel2', component: 'testPanel' });
|
splitview.addPanel({ id: 'panel2', component: 'testPanel' });
|
||||||
@ -305,6 +307,8 @@ describe('componentSplitview', () => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
splitview.layout(600, 400);
|
||||||
|
|
||||||
expect(panel1Dimensions).toEqual({ width: 300, height: 400 });
|
expect(panel1Dimensions).toEqual({ width: 300, height: 400 });
|
||||||
expect(panel2Dimensions).toEqual({ width: 300, height: 400 });
|
expect(panel2Dimensions).toEqual({ width: 300, height: 400 });
|
||||||
|
|
||||||
|
@ -37,9 +37,7 @@ export class GridviewPanelApiImpl
|
|||||||
readonly onDidConstraintsChangeInternal: Event<GridConstraintChangeEvent2> =
|
readonly onDidConstraintsChangeInternal: Event<GridConstraintChangeEvent2> =
|
||||||
this._onDidConstraintsChangeInternal.event;
|
this._onDidConstraintsChangeInternal.event;
|
||||||
|
|
||||||
readonly _onDidConstraintsChange = new Emitter<GridConstraintChangeEvent>({
|
readonly _onDidConstraintsChange = new Emitter<GridConstraintChangeEvent>();
|
||||||
replay: true,
|
|
||||||
});
|
|
||||||
readonly onDidConstraintsChange: Event<GridConstraintChangeEvent> =
|
readonly onDidConstraintsChange: Event<GridConstraintChangeEvent> =
|
||||||
this._onDidConstraintsChange.event;
|
this._onDidConstraintsChange.event;
|
||||||
|
|
||||||
|
@ -82,22 +82,16 @@ export class PanelApiImpl extends CompositeDisposable implements PanelApi {
|
|||||||
|
|
||||||
private readonly panelUpdatesDisposable = new MutableDisposable();
|
private readonly panelUpdatesDisposable = new MutableDisposable();
|
||||||
|
|
||||||
readonly _onDidDimensionChange = new Emitter<PanelDimensionChangeEvent>({
|
readonly _onDidDimensionChange = new Emitter<PanelDimensionChangeEvent>();
|
||||||
replay: true,
|
|
||||||
});
|
|
||||||
readonly onDidDimensionsChange = this._onDidDimensionChange.event;
|
readonly onDidDimensionsChange = this._onDidDimensionChange.event;
|
||||||
|
|
||||||
readonly _onDidChangeFocus = new Emitter<FocusEvent>({
|
readonly _onDidChangeFocus = new Emitter<FocusEvent>();
|
||||||
replay: true,
|
|
||||||
});
|
|
||||||
readonly onDidFocusChange: Event<FocusEvent> = this._onDidChangeFocus.event;
|
readonly onDidFocusChange: Event<FocusEvent> = this._onDidChangeFocus.event;
|
||||||
//
|
//
|
||||||
readonly _onWillFocus = new Emitter<WillFocusEvent>();
|
readonly _onWillFocus = new Emitter<WillFocusEvent>();
|
||||||
readonly onWillFocus: Event<WillFocusEvent> = this._onWillFocus.event;
|
readonly onWillFocus: Event<WillFocusEvent> = this._onWillFocus.event;
|
||||||
//
|
//
|
||||||
readonly _onDidVisibilityChange = new Emitter<VisibilityEvent>({
|
readonly _onDidVisibilityChange = new Emitter<VisibilityEvent>();
|
||||||
replay: true,
|
|
||||||
});
|
|
||||||
readonly onDidVisibilityChange: Event<VisibilityEvent> =
|
readonly onDidVisibilityChange: Event<VisibilityEvent> =
|
||||||
this._onDidVisibilityChange.event;
|
this._onDidVisibilityChange.event;
|
||||||
|
|
||||||
@ -105,9 +99,7 @@ export class PanelApiImpl extends CompositeDisposable implements PanelApi {
|
|||||||
readonly onDidHiddenChange: Event<HiddenEvent> =
|
readonly onDidHiddenChange: Event<HiddenEvent> =
|
||||||
this._onDidHiddenChange.event;
|
this._onDidHiddenChange.event;
|
||||||
|
|
||||||
readonly _onDidActiveChange = new Emitter<ActiveEvent>({
|
readonly _onDidActiveChange = new Emitter<ActiveEvent>();
|
||||||
replay: true,
|
|
||||||
});
|
|
||||||
readonly onDidActiveChange: Event<ActiveEvent> =
|
readonly onDidActiveChange: Event<ActiveEvent> =
|
||||||
this._onDidActiveChange.event;
|
this._onDidActiveChange.event;
|
||||||
|
|
||||||
|
@ -632,7 +632,7 @@ export class DockviewComponent
|
|||||||
|
|
||||||
panels.forEach((panel) => {
|
panels.forEach((panel) => {
|
||||||
options.to.model.openPanel(panel, {
|
options.to.model.openPanel(panel, {
|
||||||
skipRender: activePanel !== panel,
|
skipSetActive: activePanel !== panel,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1207,7 +1207,7 @@ export class DockviewComponent
|
|||||||
activeView === panel.id;
|
activeView === panel.id;
|
||||||
|
|
||||||
group.model.openPanel(panel, {
|
group.model.openPanel(panel, {
|
||||||
skipRender: !isActive,
|
skipSetActive: !isActive,
|
||||||
skipSetGroupActive: true,
|
skipSetGroupActive: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1780,8 +1780,7 @@ export class DockviewComponent
|
|||||||
const removedPanel: IDockviewPanel | undefined = this.movingLock(
|
const removedPanel: IDockviewPanel | undefined = this.movingLock(
|
||||||
() =>
|
() =>
|
||||||
sourceGroup.model.removePanel(sourceItemId, {
|
sourceGroup.model.removePanel(sourceItemId, {
|
||||||
skipEvents: true,
|
skipSetActive: true,
|
||||||
skipActive: true,
|
|
||||||
skipSetActiveGroup: true,
|
skipSetActiveGroup: true,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -1873,8 +1872,7 @@ export class DockviewComponent
|
|||||||
const removedPanel: IDockviewPanel | undefined =
|
const removedPanel: IDockviewPanel | undefined =
|
||||||
this.movingLock(() =>
|
this.movingLock(() =>
|
||||||
sourceGroup.model.removePanel(sourceItemId, {
|
sourceGroup.model.removePanel(sourceItemId, {
|
||||||
skipEvents: true,
|
skipSetActive: true,
|
||||||
skipActive: true,
|
|
||||||
skipSetActiveGroup: true,
|
skipSetActiveGroup: true,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -1892,7 +1890,6 @@ export class DockviewComponent
|
|||||||
const group = this.createGroupAtLocation(dropLocation);
|
const group = this.createGroupAtLocation(dropLocation);
|
||||||
this.movingLock(() =>
|
this.movingLock(() =>
|
||||||
group.model.openPanel(removedPanel, {
|
group.model.openPanel(removedPanel, {
|
||||||
skipEvents: true,
|
|
||||||
skipSetGroupActive: true,
|
skipSetGroupActive: true,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -1912,8 +1909,7 @@ export class DockviewComponent
|
|||||||
const panels = this.movingLock(() =>
|
const panels = this.movingLock(() =>
|
||||||
[...from.panels].map((p) =>
|
[...from.panels].map((p) =>
|
||||||
from.model.removePanel(p.id, {
|
from.model.removePanel(p.id, {
|
||||||
skipRender: true,
|
skipSetActive: true,
|
||||||
skipEvents: true,
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -1925,7 +1921,7 @@ export class DockviewComponent
|
|||||||
this.movingLock(() => {
|
this.movingLock(() => {
|
||||||
for (const panel of panels) {
|
for (const panel of panels) {
|
||||||
to.model.openPanel(panel, {
|
to.model.openPanel(panel, {
|
||||||
skipRender: panel !== activePanel,
|
skipSetActive: panel !== activePanel,
|
||||||
skipSetGroupActive: panel !== activePanel,
|
skipSetGroupActive: panel !== activePanel,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -611,8 +611,7 @@ export class DockviewGroupPanelModel
|
|||||||
panel: IDockviewPanel,
|
panel: IDockviewPanel,
|
||||||
options: {
|
options: {
|
||||||
index?: number;
|
index?: number;
|
||||||
skipRender?: boolean;
|
skipSetActive?: boolean;
|
||||||
skipEvents?: boolean;
|
|
||||||
skipSetGroupActive?: boolean;
|
skipSetGroupActive?: boolean;
|
||||||
} = {}
|
} = {}
|
||||||
): void {
|
): void {
|
||||||
@ -630,13 +629,15 @@ export class DockviewGroupPanelModel
|
|||||||
options.index = this.panels.length;
|
options.index = this.panels.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
const skipRender = !!options.skipRender;
|
const skipSetActive = !!options.skipSetActive;
|
||||||
|
|
||||||
// ensure the group is updated before we fire any events
|
// ensure the group is updated before we fire any events
|
||||||
panel.updateParentGroup(this.groupPanel, { isGroupActive: true });
|
panel.updateParentGroup(this.groupPanel, {
|
||||||
|
skipSetActive: options.skipSetActive,
|
||||||
|
});
|
||||||
|
|
||||||
this.doAddPanel(panel, options.index, {
|
this.doAddPanel(panel, options.index, {
|
||||||
skipRender,
|
skipSetActive: skipSetActive,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this._activePanel === panel) {
|
if (this._activePanel === panel) {
|
||||||
@ -644,7 +645,7 @@ export class DockviewGroupPanelModel
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skipRender) {
|
if (!skipSetActive) {
|
||||||
this.doSetActivePanel(panel);
|
this.doSetActivePanel(panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -652,8 +653,7 @@ export class DockviewGroupPanelModel
|
|||||||
this.accessor.doSetGroupActive(this.groupPanel);
|
this.accessor.doSetGroupActive(this.groupPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.skipEvents) {
|
if (!options.skipSetActive) {
|
||||||
panel.runEvents();
|
|
||||||
this.updateContainer();
|
this.updateContainer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -661,14 +661,10 @@ export class DockviewGroupPanelModel
|
|||||||
public removePanel(
|
public removePanel(
|
||||||
groupItemOrId: IDockviewPanel | string,
|
groupItemOrId: IDockviewPanel | string,
|
||||||
options: {
|
options: {
|
||||||
skipRender?: boolean;
|
skipSetActive?: boolean;
|
||||||
skipEvents?: boolean;
|
|
||||||
skipActive?: boolean;
|
|
||||||
skipSetActiveGroup?: boolean;
|
skipSetActiveGroup?: boolean;
|
||||||
} = {
|
} = {
|
||||||
skipRender: false,
|
skipSetActive: false,
|
||||||
skipEvents: false,
|
|
||||||
skipActive: false,
|
|
||||||
}
|
}
|
||||||
): IDockviewPanel {
|
): IDockviewPanel {
|
||||||
const id =
|
const id =
|
||||||
@ -746,8 +742,7 @@ export class DockviewGroupPanelModel
|
|||||||
private _removePanel(
|
private _removePanel(
|
||||||
panel: IDockviewPanel,
|
panel: IDockviewPanel,
|
||||||
options: {
|
options: {
|
||||||
skipRender?: boolean;
|
skipSetActive?: boolean;
|
||||||
skipEvents?: boolean;
|
|
||||||
skipSetActiveGroup?: boolean;
|
skipSetActiveGroup?: boolean;
|
||||||
}
|
}
|
||||||
): IDockviewPanel {
|
): IDockviewPanel {
|
||||||
@ -758,8 +753,7 @@ export class DockviewGroupPanelModel
|
|||||||
if (isActivePanel && this.panels.length > 0) {
|
if (isActivePanel && this.panels.length > 0) {
|
||||||
const nextPanel = this.mostRecentlyUsed[0];
|
const nextPanel = this.mostRecentlyUsed[0];
|
||||||
this.openPanel(nextPanel, {
|
this.openPanel(nextPanel, {
|
||||||
skipRender: options.skipRender,
|
skipSetActive: options.skipSetActive,
|
||||||
skipEvents: options.skipEvents,
|
|
||||||
skipSetGroupActive: options.skipSetActiveGroup,
|
skipSetGroupActive: options.skipSetActiveGroup,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -768,7 +762,7 @@ export class DockviewGroupPanelModel
|
|||||||
this.doSetActivePanel(undefined);
|
this.doSetActivePanel(undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.skipEvents) {
|
if (!options.skipSetActive) {
|
||||||
this.updateContainer();
|
this.updateContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -799,8 +793,8 @@ export class DockviewGroupPanelModel
|
|||||||
panel: IDockviewPanel,
|
panel: IDockviewPanel,
|
||||||
index: number = this.panels.length,
|
index: number = this.panels.length,
|
||||||
options: {
|
options: {
|
||||||
skipRender: boolean;
|
skipSetActive: boolean;
|
||||||
} = { skipRender: false }
|
} = { skipSetActive: false }
|
||||||
): void {
|
): void {
|
||||||
const existingPanel = this._panels.indexOf(panel);
|
const existingPanel = this._panels.indexOf(panel);
|
||||||
const hasExistingPanel = existingPanel > -1;
|
const hasExistingPanel = existingPanel > -1;
|
||||||
@ -810,7 +804,7 @@ export class DockviewGroupPanelModel
|
|||||||
|
|
||||||
this.tabsContainer.openPanel(panel, index);
|
this.tabsContainer.openPanel(panel, index);
|
||||||
|
|
||||||
if (!options.skipRender) {
|
if (!options.skipSetActive) {
|
||||||
this.contentContainer.openPanel(panel);
|
this.contentContainer.openPanel(panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -858,12 +852,7 @@ export class DockviewGroupPanelModel
|
|||||||
private updateContainer(): void {
|
private updateContainer(): void {
|
||||||
toggleClass(this.container, 'empty', this.isEmpty);
|
toggleClass(this.container, 'empty', this.isEmpty);
|
||||||
|
|
||||||
this.panels.forEach((panel) =>
|
this.panels.forEach((panel) => panel.runEvents());
|
||||||
// panel.updateParentGroup(this.groupPanel, {
|
|
||||||
// isGroupActive: this.isActive,
|
|
||||||
// })
|
|
||||||
panel.runEvents()
|
|
||||||
);
|
|
||||||
|
|
||||||
if (this.isEmpty && !this.watermark) {
|
if (this.isEmpty && !this.watermark) {
|
||||||
const watermark = this.accessor.createWatermarkComponent();
|
const watermark = this.accessor.createWatermarkComponent();
|
||||||
|
@ -20,7 +20,7 @@ export interface IDockviewPanel extends IDisposable, IPanel {
|
|||||||
readonly params: Parameters | undefined;
|
readonly params: Parameters | undefined;
|
||||||
updateParentGroup(
|
updateParentGroup(
|
||||||
group: DockviewGroupPanel,
|
group: DockviewGroupPanel,
|
||||||
options: { isGroupActive: boolean }
|
options?: { skipSetActive?: boolean }
|
||||||
): void;
|
): void;
|
||||||
init(params: IGroupPanelInitParameters): void;
|
init(params: IGroupPanelInitParameters): void;
|
||||||
toJSON(): GroupviewPanelState;
|
toJSON(): GroupviewPanelState;
|
||||||
@ -179,34 +179,30 @@ export class DockviewPanel
|
|||||||
|
|
||||||
public updateParentGroup(
|
public updateParentGroup(
|
||||||
group: DockviewGroupPanel,
|
group: DockviewGroupPanel,
|
||||||
options: { isGroupActive: boolean }
|
options?: { skipSetActive?: boolean }
|
||||||
): void {
|
): void {
|
||||||
this._group = group;
|
this._group = group;
|
||||||
|
this.api.group = this._group;
|
||||||
|
|
||||||
// const isPanelVisible = this._group.model.isPanelActive(this);
|
const isPanelVisible = this._group.model.isPanelActive(this);
|
||||||
|
const isActive = this.group.api.isActive && isPanelVisible;
|
||||||
|
|
||||||
// const isActive = options.isGroupActive && isPanelVisible;
|
if (!options?.skipSetActive) {
|
||||||
|
if (this.api.isActive !== isActive) {
|
||||||
|
this.api._onDidActiveChange.fire({
|
||||||
|
isActive: this.group.api.isActive && isPanelVisible,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if (this.api.isActive !== isActive) {
|
if (this.api.isVisible !== isPanelVisible) {
|
||||||
// this.api._onDidActiveChange.fire({
|
this.api._onDidVisibilityChange.fire({
|
||||||
// isActive: options.isGroupActive && isPanelVisible,
|
isVisible: isPanelVisible,
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (this.api.isVisible !== isPanelVisible) {
|
|
||||||
// this.api._onDidVisibilityChange.fire({
|
|
||||||
// isVisible: isPanelVisible,
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this.view.updateParentGroup(
|
|
||||||
// this._group,
|
|
||||||
// this._group.model.isPanelActive(this)
|
|
||||||
// );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
runEvents(): void {
|
runEvents(): void {
|
||||||
this.api.group = this._group;
|
|
||||||
const isPanelVisible = this._group.model.isPanelActive(this);
|
const isPanelVisible = this._group.model.isPanelActive(this);
|
||||||
|
|
||||||
const isActive = this.group.api.isActive && isPanelVisible;
|
const isActive = this.group.api.isActive && isPanelVisible;
|
||||||
@ -225,7 +221,7 @@ export class DockviewPanel
|
|||||||
}
|
}
|
||||||
|
|
||||||
public layout(width: number, height: number): void {
|
public layout(width: number, height: number): void {
|
||||||
// the obtain the correct dimensions of the content panel we must deduct the tab height
|
// TODO: Can we somehow do height without header height or indicate what the header height is?
|
||||||
this.api._onDidDimensionChange.fire({
|
this.api._onDidDimensionChange.fire({
|
||||||
width,
|
width,
|
||||||
height: height,
|
height: height,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user