-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathDockGraphSerializer.ts
More file actions
54 lines (46 loc) · 1.84 KB
/
DockGraphSerializer.ts
File metadata and controls
54 lines (46 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { DockModel } from "./DockModel.js";
import { DockNode } from "./DockNode.js";
import { Dialog } from "./Dialog.js";
import { IPanelInfo } from "./interfaces/IPanelInfo.js";
import { INodeInfo } from "./interfaces/INodeInfo.js";
import { IState } from "./interfaces/IState.js";
/**
* The serializer saves / loads the state of the dock layout hierarchy
*/
export class DockGraphSerializer {
serialize(model: DockModel) {
let graphInfo = this._buildGraphInfo(model.rootNode);
let dialogs = this._buildDialogsInfo(model.dialogs.sort((x,y)=><number><any>x.elementDialog.style.zIndex-<number><any>y.elementDialog.style.zIndex));
return JSON.stringify({ graphInfo: graphInfo, dialogsInfo: dialogs });
}
_buildGraphInfo(node: DockNode): INodeInfo {
let nodeState: IState = {};
node.container.saveState(nodeState);
let childrenInfo: INodeInfo[] = [];
node.children.forEach((childNode) => {
childrenInfo.push(this._buildGraphInfo(childNode));
});
let nodeInfo: INodeInfo = {
containerType: node.container.containerType,
state: nodeState,
children: childrenInfo
};
return nodeInfo;
}
_buildDialogsInfo(dialogs: Dialog[]): IPanelInfo[] {
let dialogsInfo: IPanelInfo[] = [];
dialogs.forEach((dialog) => {
let panelState: IState = {};
let panelContainer = dialog.panel;
panelContainer.saveState(panelState);
let panelInfo: IPanelInfo = {
containerType: panelContainer.containerType,
state: panelState,
position: dialog.getPosition(),
isHidden: dialog.isHidden
}
dialogsInfo.push(panelInfo);
});
return dialogsInfo;
}
}