mirror of
https://github.com/mathuo/dockview
synced 2025-02-21 23:55:44 +00:00
Merge pull request #119 from mathuo/118-enhance-api
feat: add clear method and fix .orientation setter
This commit is contained in:
commit
9dd307b5e3
@ -100,6 +100,10 @@ class ClassUnderTest extends BaseGrid<TestPanel> {
|
|||||||
public toJSON(): object {
|
public toJSON(): object {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public clear(): void {
|
||||||
|
//
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('baseComponentGridview', () => {
|
describe('baseComponentGridview', () => {
|
||||||
|
@ -43,6 +43,7 @@ export interface CommonApi<T = any> {
|
|||||||
layout(width: number, height: number): void;
|
layout(width: number, height: number): void;
|
||||||
fromJSON(data: T): void;
|
fromJSON(data: T): void;
|
||||||
toJSON(): T;
|
toJSON(): T;
|
||||||
|
clear(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SplitviewApi implements CommonApi<SerializedSplitview> {
|
export class SplitviewApi implements CommonApi<SerializedSplitview> {
|
||||||
@ -127,6 +128,10 @@ export class SplitviewApi implements CommonApi<SerializedSplitview> {
|
|||||||
toJSON(): SerializedSplitview {
|
toJSON(): SerializedSplitview {
|
||||||
return this.component.toJSON();
|
return this.component.toJSON();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear(): void {
|
||||||
|
this.component.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PaneviewApi implements CommonApi<SerializedPaneview> {
|
export class PaneviewApi implements CommonApi<SerializedPaneview> {
|
||||||
@ -214,6 +219,10 @@ export class PaneviewApi implements CommonApi<SerializedPaneview> {
|
|||||||
toJSON(): SerializedPaneview {
|
toJSON(): SerializedPaneview {
|
||||||
return this.component.toJSON();
|
return this.component.toJSON();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear(): void {
|
||||||
|
this.component.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GridviewApi implements CommonApi<SerializedGridview> {
|
export class GridviewApi implements CommonApi<SerializedGridview> {
|
||||||
@ -309,6 +318,10 @@ export class GridviewApi implements CommonApi<SerializedGridview> {
|
|||||||
toJSON(): SerializedGridview {
|
toJSON(): SerializedGridview {
|
||||||
return this.component.toJSON();
|
return this.component.toJSON();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear(): void {
|
||||||
|
this.component.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DockviewApi implements CommonApi<SerializedDockview> {
|
export class DockviewApi implements CommonApi<SerializedDockview> {
|
||||||
@ -453,4 +466,8 @@ export class DockviewApi implements CommonApi<SerializedDockview> {
|
|||||||
toJSON(): SerializedDockview {
|
toJSON(): SerializedDockview {
|
||||||
return this.component.toJSON();
|
return this.component.toJSON();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear(): void {
|
||||||
|
this.component.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ export class DockviewComponent
|
|||||||
{
|
{
|
||||||
private _deserializer: IPanelDeserializer | undefined;
|
private _deserializer: IPanelDeserializer | undefined;
|
||||||
private _api: DockviewApi;
|
private _api: DockviewApi;
|
||||||
private _options: DockviewComponentOptions;
|
private _options: Exclude<DockviewComponentOptions, 'orientation'>;
|
||||||
|
|
||||||
private readonly _onTabContextMenu = new Emitter<TabContextMenuEvent>();
|
private readonly _onTabContextMenu = new Emitter<TabContextMenuEvent>();
|
||||||
readonly onTabContextMenu: Event<TabContextMenuEvent> =
|
readonly onTabContextMenu: Event<TabContextMenuEvent> =
|
||||||
@ -237,7 +237,7 @@ export class DockviewComponent
|
|||||||
updateOptions(options: DockviewComponentUpdateOptions): void {
|
updateOptions(options: DockviewComponentUpdateOptions): void {
|
||||||
const hasOrientationChanged =
|
const hasOrientationChanged =
|
||||||
typeof options.orientation === 'string' &&
|
typeof options.orientation === 'string' &&
|
||||||
this.options.orientation !== options.orientation;
|
this.gridview.orientation !== options.orientation;
|
||||||
|
|
||||||
this._options = { ...this.options, ...options };
|
this._options = { ...this.options, ...options };
|
||||||
|
|
||||||
@ -333,25 +333,7 @@ export class DockviewComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
fromJSON(data: SerializedDockview): void {
|
fromJSON(data: SerializedDockview): void {
|
||||||
const groups = Array.from(this._groups.values()).map((_) => _.value);
|
this.clear()
|
||||||
|
|
||||||
const hasActiveGroup = !!this.activeGroup;
|
|
||||||
const hasActivePanel = !!this.activePanel
|
|
||||||
|
|
||||||
for (const group of groups) {
|
|
||||||
// remove the group will automatically remove the panels
|
|
||||||
this.removeGroup(group, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasActiveGroup) {
|
|
||||||
this.doSetGroupActive(undefined);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( hasActivePanel) {
|
|
||||||
this._onDidActivePanelChange.fire(undefined);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.gridview.clear();
|
|
||||||
|
|
||||||
if (!this.deserializer) {
|
if (!this.deserializer) {
|
||||||
throw new Error('invalid deserializer');
|
throw new Error('invalid deserializer');
|
||||||
@ -414,6 +396,28 @@ export class DockviewComponent
|
|||||||
this._onDidLayoutFromJSON.fire();
|
this._onDidLayoutFromJSON.fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear():void {
|
||||||
|
const groups = Array.from(this._groups.values()).map((_) => _.value);
|
||||||
|
|
||||||
|
const hasActiveGroup = !!this.activeGroup;
|
||||||
|
const hasActivePanel = !!this.activePanel
|
||||||
|
|
||||||
|
for (const group of groups) {
|
||||||
|
// remove the group will automatically remove the panels
|
||||||
|
this.removeGroup(group, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasActiveGroup) {
|
||||||
|
this.doSetGroupActive(undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( hasActivePanel) {
|
||||||
|
this._onDidActivePanelChange.fire(undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.gridview.clear();
|
||||||
|
}
|
||||||
|
|
||||||
closeAllGroups(): void {
|
closeAllGroups(): void {
|
||||||
for (const entry of this._groups.entries()) {
|
for (const entry of this._groups.entries()) {
|
||||||
const [_, group] = entry;
|
const [_, group] = entry;
|
||||||
|
@ -61,6 +61,7 @@ export interface IBaseGrid<T extends IGridPanelView> {
|
|||||||
getPanel(id: string): T | undefined;
|
getPanel(id: string): T | undefined;
|
||||||
toJSON(): object;
|
toJSON(): object;
|
||||||
fromJSON(data: any): void;
|
fromJSON(data: any): void;
|
||||||
|
clear(): void;
|
||||||
layout(width: number, height: number, force?: boolean): void;
|
layout(width: number, height: number, force?: boolean): void;
|
||||||
setVisible(panel: T, visible: boolean): void;
|
setVisible(panel: T, visible: boolean): void;
|
||||||
isVisible(panel: T): boolean;
|
isVisible(panel: T): boolean;
|
||||||
@ -173,6 +174,8 @@ export abstract class BaseGrid<T extends IGridPanelView>
|
|||||||
|
|
||||||
public abstract fromJSON(data: any): void;
|
public abstract fromJSON(data: any): void;
|
||||||
|
|
||||||
|
public abstract clear(): void;
|
||||||
|
|
||||||
public setVisible(panel: T, visible: boolean) {
|
public setVisible(panel: T, visible: boolean) {
|
||||||
this.gridview.setViewVisible(getGridLocation(panel.element), visible);
|
this.gridview.setViewVisible(getGridLocation(panel.element), visible);
|
||||||
this._onDidLayoutChange.fire();
|
this._onDidLayoutChange.fire();
|
||||||
|
@ -78,7 +78,7 @@ export class GridviewComponent
|
|||||||
extends BaseGrid<GridviewPanel>
|
extends BaseGrid<GridviewPanel>
|
||||||
implements IGridviewComponent
|
implements IGridviewComponent
|
||||||
{
|
{
|
||||||
private _options: GridviewComponentOptions;
|
private _options: Exclude<GridviewComponentOptions, 'orientation'>;
|
||||||
private _deserializer: IPanelDeserializer | undefined;
|
private _deserializer: IPanelDeserializer | undefined;
|
||||||
|
|
||||||
private readonly _onDidLayoutfromJSON = new Emitter<void>();
|
private readonly _onDidLayoutfromJSON = new Emitter<void>();
|
||||||
@ -124,7 +124,7 @@ export class GridviewComponent
|
|||||||
updateOptions(options: Partial<GridviewComponentUpdateOptions>): void {
|
updateOptions(options: Partial<GridviewComponentUpdateOptions>): void {
|
||||||
const hasOrientationChanged =
|
const hasOrientationChanged =
|
||||||
typeof options.orientation === 'string' &&
|
typeof options.orientation === 'string' &&
|
||||||
this.options.orientation !== options.orientation;
|
this.gridview.orientation !== options.orientation;
|
||||||
|
|
||||||
this._options = { ...this.options, ...options };
|
this._options = { ...this.options, ...options };
|
||||||
|
|
||||||
@ -173,22 +173,10 @@ export class GridviewComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
public fromJSON(serializedGridview: SerializedGridview) {
|
public fromJSON(serializedGridview: SerializedGridview) {
|
||||||
|
this.clear();
|
||||||
|
|
||||||
const { grid, activePanel } = serializedGridview;
|
const { grid, activePanel } = serializedGridview;
|
||||||
|
|
||||||
const hasActiveGroup = this.activeGroup;
|
|
||||||
|
|
||||||
const groups = Array.from(this._groups.values()); // reassign since group panels will mutate
|
|
||||||
for (const group of groups) {
|
|
||||||
group.disposable.dispose();
|
|
||||||
this.doRemoveGroup(group.value, { skipActive: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasActiveGroup) {
|
|
||||||
this.doSetGroupActive(undefined);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.gridview.clear();
|
|
||||||
|
|
||||||
const queue: Function[] = [];
|
const queue: Function[] = [];
|
||||||
|
|
||||||
this.gridview.deserialize(grid, {
|
this.gridview.deserialize(grid, {
|
||||||
@ -244,6 +232,22 @@ export class GridviewComponent
|
|||||||
this._onDidLayoutfromJSON.fire();
|
this._onDidLayoutfromJSON.fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear(): void {
|
||||||
|
const hasActiveGroup = this.activeGroup;
|
||||||
|
|
||||||
|
const groups = Array.from(this._groups.values()); // reassign since group panels will mutate
|
||||||
|
for (const group of groups) {
|
||||||
|
group.disposable.dispose();
|
||||||
|
this.doRemoveGroup(group.value, { skipActive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasActiveGroup) {
|
||||||
|
this.doSetGroupActive(undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.gridview.clear();
|
||||||
|
}
|
||||||
|
|
||||||
movePanel(
|
movePanel(
|
||||||
panel: GridviewPanel,
|
panel: GridviewPanel,
|
||||||
options: { direction: Direction; reference: string; size?: number }
|
options: { direction: Direction; reference: string; size?: number }
|
||||||
|
@ -113,6 +113,7 @@ export interface IPaneviewComponent extends IDisposable {
|
|||||||
getPanel(id: string): IPaneviewPanel | undefined;
|
getPanel(id: string): IPaneviewPanel | undefined;
|
||||||
movePanel(from: number, to: number): void;
|
movePanel(from: number, to: number): void;
|
||||||
updateOptions(options: Partial<PaneviewComponentOptions>): void;
|
updateOptions(options: Partial<PaneviewComponentOptions>): void;
|
||||||
|
clear(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PaneviewComponent
|
export class PaneviewComponent
|
||||||
@ -343,17 +344,12 @@ export class PaneviewComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
fromJSON(serializedPaneview: SerializedPaneview): void {
|
fromJSON(serializedPaneview: SerializedPaneview): void {
|
||||||
|
this.clear();
|
||||||
|
|
||||||
const { views, size } = serializedPaneview;
|
const { views, size } = serializedPaneview;
|
||||||
|
|
||||||
const queue: Function[] = [];
|
const queue: Function[] = [];
|
||||||
|
|
||||||
for (const [_, value] of this._viewDisposables.entries()) {
|
|
||||||
value.dispose();
|
|
||||||
}
|
|
||||||
this._viewDisposables.clear();
|
|
||||||
|
|
||||||
this.paneview.dispose();
|
|
||||||
|
|
||||||
this.paneview = new Paneview(this.element, {
|
this.paneview = new Paneview(this.element, {
|
||||||
orientation: Orientation.VERTICAL,
|
orientation: Orientation.VERTICAL,
|
||||||
descriptor: {
|
descriptor: {
|
||||||
@ -437,6 +433,15 @@ export class PaneviewComponent
|
|||||||
this._onDidLayoutfromJSON.fire();
|
this._onDidLayoutfromJSON.fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear(): void {
|
||||||
|
for (const [_, value] of this._viewDisposables.entries()) {
|
||||||
|
value.dispose();
|
||||||
|
}
|
||||||
|
this._viewDisposables.clear();
|
||||||
|
|
||||||
|
this.paneview.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
private doAddPanel(panel: PaneFramework) {
|
private doAddPanel(panel: PaneFramework) {
|
||||||
const disposable = panel.onDidDrop((event) => {
|
const disposable = panel.onDidDrop((event) => {
|
||||||
this._onDidDrop.fire(event);
|
this._onDidDrop.fire(event);
|
||||||
|
@ -72,6 +72,7 @@ export interface ISplitviewComponent extends IDisposable {
|
|||||||
removePanel(panel: ISplitviewPanel, sizing?: Sizing): void;
|
removePanel(panel: ISplitviewPanel, sizing?: Sizing): void;
|
||||||
setVisible(panel: ISplitviewPanel, visible: boolean): void;
|
setVisible(panel: ISplitviewPanel, visible: boolean): void;
|
||||||
movePanel(from: number, to: number): void;
|
movePanel(from: number, to: number): void;
|
||||||
|
clear(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -334,14 +335,9 @@ export class SplitviewComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
fromJSON(serializedSplitview: SerializedSplitview): void {
|
fromJSON(serializedSplitview: SerializedSplitview): void {
|
||||||
const { views, orientation, size, activeView } = serializedSplitview;
|
this.clear();
|
||||||
|
|
||||||
for (const [_, value] of this._panels.entries()) {
|
const { views, orientation, size, activeView } = serializedSplitview;
|
||||||
value.disposable.dispose();
|
|
||||||
value.value.dispose();
|
|
||||||
}
|
|
||||||
this._panels.clear();
|
|
||||||
this.splitview.dispose();
|
|
||||||
|
|
||||||
const queue: Function[] = [];
|
const queue: Function[] = [];
|
||||||
|
|
||||||
@ -409,6 +405,15 @@ export class SplitviewComponent
|
|||||||
this._onDidLayoutfromJSON.fire();
|
this._onDidLayoutfromJSON.fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear(): void {
|
||||||
|
for (const [_, value] of this._panels.entries()) {
|
||||||
|
value.disposable.dispose();
|
||||||
|
value.value.dispose();
|
||||||
|
}
|
||||||
|
this._panels.clear();
|
||||||
|
this.splitview.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
dispose(): void {
|
dispose(): void {
|
||||||
for (const [_, value] of this._panels.entries()) {
|
for (const [_, value] of this._panels.entries()) {
|
||||||
value.disposable.dispose();
|
value.disposable.dispose();
|
||||||
|
Loading…
Reference in New Issue
Block a user