1
- using Microsoft . UI . Windowing ;
1
+ using System . Text . Json ;
2
+ using System . Text . Json . Nodes ;
3
+ using Microsoft . UI . Windowing ;
2
4
using Microsoft . UI . Xaml . Controls . Primitives ;
3
5
using Windows . Graphics ;
4
6
using WinUI . Dock . Helpers ;
@@ -9,15 +11,53 @@ public sealed partial class DockWindow : Window
9
11
{
10
12
private PointInt32 dragOffset ;
11
13
12
- public DockWindow ( DockManager manager , Document document )
14
+ public DockWindow ( DockManager manager , Document ? document )
13
15
{
14
16
InitializeComponent ( ) ;
15
17
16
18
InitializePanel ( manager , document ) ;
17
19
InitializeWindow ( manager , document ) ;
18
20
}
19
21
20
- private void InitializePanel ( DockManager manager , Document document )
22
+ internal void SaveLayout ( JsonObject writer )
23
+ {
24
+ writer [ "Position" ] = new JsonObject
25
+ {
26
+ [ "X" ] = AppWindow . Position . X ,
27
+ [ "Y" ] = AppWindow . Position . Y
28
+ } ;
29
+
30
+ writer [ "Size" ] = new JsonObject
31
+ {
32
+ [ "Width" ] = AppWindow . Size . Width ,
33
+ [ "Height" ] = AppWindow . Size . Height
34
+ } ;
35
+
36
+ JsonObject panelWriter = [ ] ;
37
+
38
+ Panel . SaveLayout ( panelWriter ) ;
39
+
40
+ writer [ nameof ( Panel ) ] = panelWriter ;
41
+ }
42
+
43
+ internal void LoadLayout ( JsonObject reader )
44
+ {
45
+ AppWindow . Move ( new ( )
46
+ {
47
+ X = reader [ "Position" ] ! . AsObject ( ) [ "X" ] . Deserialize < int > ( LayoutHelpers . SerializerOptions ) ,
48
+ Y = reader [ "Position" ] ! . AsObject ( ) [ "Y" ] . Deserialize < int > ( LayoutHelpers . SerializerOptions )
49
+ } ) ;
50
+
51
+ AppWindow . Resize ( new ( )
52
+ {
53
+ Width = reader [ "Size" ] ! . AsObject ( ) [ "Width" ] . Deserialize < int > ( LayoutHelpers . SerializerOptions ) ,
54
+ Height = reader [ "Size" ] ! . AsObject ( ) [ "Height" ] . Deserialize < int > ( LayoutHelpers . SerializerOptions )
55
+ } ) ;
56
+
57
+ Panel . LoadLayout ( reader [ nameof ( Panel ) ] ! . AsObject ( ) ) ;
58
+ }
59
+
60
+ private void InitializePanel ( DockManager manager , Document ? document )
21
61
{
22
62
Panel . Root = manager ;
23
63
@@ -29,18 +69,21 @@ private void InitializePanel(DockManager manager, Document document)
29
69
}
30
70
} ;
31
71
32
- document . Detach ( ) ;
72
+ if ( document is not null )
73
+ {
74
+ document . Detach ( ) ;
33
75
34
- DocumentGroup group = new ( ) ;
35
- group . Children . Add ( document ) ;
76
+ DocumentGroup group = new ( ) ;
77
+ group . Children . Add ( document ) ;
36
78
37
- LayoutPanel panel = new ( ) { Orientation = Orientation . Horizontal } ;
38
- panel . Children . Add ( group ) ;
79
+ LayoutPanel panel = new ( ) { Orientation = Orientation . Horizontal } ;
80
+ panel . Children . Add ( group ) ;
39
81
40
- Panel . Children . Add ( panel ) ;
82
+ Panel . Children . Add ( panel ) ;
83
+ }
41
84
}
42
85
43
- private void InitializeWindow ( DockManager manager , Document document )
86
+ private void InitializeWindow ( DockManager manager , Document ? document )
44
87
{
45
88
Closed += ( _ , _ ) => DockWindowHelpers . RemoveWindow ( manager , this ) ;
46
89
@@ -51,11 +94,15 @@ private void InitializeWindow(DockManager manager, Document document)
51
94
#endif
52
95
53
96
AppWindow . Move ( PointerHelpers . GetPointerPosition ( ) ) ;
54
- AppWindow . Resize ( new ( )
97
+
98
+ if ( document is not null )
55
99
{
56
- Width = ( int ) ( double . IsNaN ( document . DockWidth ) ? 400 : document . DockWidth ) ,
57
- Height = ( int ) ( double . IsNaN ( document . DockHeight ) ? 400 : document . DockHeight )
58
- } ) ;
100
+ AppWindow . Resize ( new ( )
101
+ {
102
+ Width = ( int ) ( double . IsNaN ( document . DockWidth ) ? 400 : document . DockWidth ) ,
103
+ Height = ( int ) ( double . IsNaN ( document . DockHeight ) ? 400 : document . DockHeight )
104
+ } ) ;
105
+ }
59
106
60
107
manager . InvokeCreateNewWindow ( TitleBar ) ;
61
108
0 commit comments