diff --git a/DarkUI/DarkUI.csproj b/DarkUI/DarkUI.csproj index 9f868fa..cc238b4 100644 --- a/DarkUI/DarkUI.csproj +++ b/DarkUI/DarkUI.csproj @@ -127,8 +127,10 @@ - + + + diff --git a/DarkUI/Docking/DarkDockPanel.cs b/DarkUI/Docking/DarkDockPanel.cs index 54ac5b2..3c0075a 100644 --- a/DarkUI/Docking/DarkDockPanel.cs +++ b/DarkUI/Docking/DarkDockPanel.cs @@ -201,26 +201,77 @@ namespace DarkUI.Docking { var state = new DockPanelState(); - foreach (var content in _contents) - state.OpenContent.Add(content.SerializationKey); + state.Regions.Add(new DockRegionState(DarkDockArea.Document)); + state.Regions.Add(new DockRegionState(DarkDockArea.Left, _regions[DarkDockArea.Left].Size)); + state.Regions.Add(new DockRegionState(DarkDockArea.Right, _regions[DarkDockArea.Right].Size)); + state.Regions.Add(new DockRegionState(DarkDockArea.Bottom, _regions[DarkDockArea.Bottom].Size)); - state.LeftRegionSize = _regions[DarkDockArea.Left].Size; - state.RightRegionSize = _regions[DarkDockArea.Right].Size; - state.BottomRegionSize = _regions[DarkDockArea.Bottom].Size; + var _groupStates = new Dictionary(); + + foreach (var content in _contents) + { + foreach (var region in state.Regions) + { + if (region.Area == content.DockArea) + { + DockGroupState groupState; + + if (_groupStates.ContainsKey(content.DockGroup)) + { + groupState = _groupStates[content.DockGroup]; + } + else + { + groupState = new DockGroupState(); + region.Groups.Add(groupState); + _groupStates.Add(content.DockGroup, groupState); + } + + groupState.Contents.Add(content.SerializationKey); + } + } + } return state; } - public void RestoreDockPanelRegions(DockPanelState state) + public void RestoreDockPanelState(DockPanelState state, Func getContentBySerializationKey) { - if (state.LeftRegionSize.Width > 0 && state.LeftRegionSize.Height > 0) - _regions[DarkDockArea.Left].Size = state.LeftRegionSize; + foreach (var region in state.Regions) + { + switch (region.Area) + { + case DarkDockArea.Left: + _regions[DarkDockArea.Left].Size = region.Size; + break; + case DarkDockArea.Right: + _regions[DarkDockArea.Right].Size = region.Size; + break; + case DarkDockArea.Bottom: + _regions[DarkDockArea.Bottom].Size = region.Size; + break; + } - if (state.RightRegionSize.Width > 0 && state.RightRegionSize.Height > 0) - _regions[DarkDockArea.Right].Size = state.RightRegionSize; + foreach (var group in region.Groups) + { + DarkDockContent previousContent = null; - if (state.BottomRegionSize.Width > 0 && state.BottomRegionSize.Height > 0) - _regions[DarkDockArea.Bottom].Size = state.BottomRegionSize; + foreach (var contentKey in group.Contents) + { + var content = getContentBySerializationKey(contentKey); + + if (content == null) + continue; + + if (previousContent == null) + AddContent(content); + else + AddContent(content, previousContent.DockGroup); + + previousContent = content; + } + } + } } #endregion diff --git a/DarkUI/Docking/DockGroupState.cs b/DarkUI/Docking/DockGroupState.cs new file mode 100644 index 0000000..861d205 --- /dev/null +++ b/DarkUI/Docking/DockGroupState.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; + +namespace DarkUI.Docking +{ + public class DockGroupState + { + #region Property Region + + public List Contents { get; set; } + + #endregion + + #region Constructor Region + + public DockGroupState() + { + Contents = new List(); + } + + #endregion + } +} diff --git a/DarkUI/Docking/DockPanelState.cs b/DarkUI/Docking/DockPanelState.cs index 0d8f705..d45de8f 100644 --- a/DarkUI/Docking/DockPanelState.cs +++ b/DarkUI/Docking/DockPanelState.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Drawing; namespace DarkUI.Docking { @@ -7,13 +6,7 @@ namespace DarkUI.Docking { #region Property Region - public List OpenContent { get; set; } - - public Size LeftRegionSize { get; set; } - - public Size RightRegionSize { get; set; } - - public Size BottomRegionSize { get; set; } + public List Regions { get; set; } #endregion @@ -21,16 +14,7 @@ namespace DarkUI.Docking public DockPanelState() { - OpenContent = new List(); - } - - public DockPanelState(List openContent, Size leftRegionSize, Size rightRegionSize, Size bottomRegionSize) - : this() - { - OpenContent = openContent; - LeftRegionSize = leftRegionSize; - RightRegionSize = rightRegionSize; - BottomRegionSize = bottomRegionSize; + Regions = new List(); } #endregion diff --git a/DarkUI/Docking/DockRegionState.cs b/DarkUI/Docking/DockRegionState.cs new file mode 100644 index 0000000..9c9f6ae --- /dev/null +++ b/DarkUI/Docking/DockRegionState.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using System.Drawing; + +namespace DarkUI.Docking +{ + public class DockRegionState + { + #region Property Region + + public DarkDockArea Area { get; set; } + + public Size Size { get; set; } + + public List Groups { get; set; } + + #endregion + + #region Constructor Region + + public DockRegionState() + { + Groups = new List(); + } + + public DockRegionState(DarkDockArea area) + : this() + { + Area = area; + } + + public DockRegionState(DarkDockArea area, Size size) + : this(area) + { + Size = size; + } + + #endregion + } +} diff --git a/Example/Forms/MainForm.cs b/Example/Forms/MainForm.cs index a74d75a..4d717cd 100644 --- a/Example/Forms/MainForm.cs +++ b/Example/Forms/MainForm.cs @@ -203,15 +203,7 @@ namespace Example private void DeserializeDockPanel(string path) { var state = SerializerHelper.Deserialize(path); - DockPanel.RestoreDockPanelRegions(state); - - foreach (var key in state.OpenContent) - { - var content = GetContentBySerializationKey(key); - - if (content != null) - DockPanel.AddContent(content); - } + DockPanel.RestoreDockPanelState(state, GetContentBySerializationKey); } private DarkDockContent GetContentBySerializationKey(string key) diff --git a/Example/Helpers/SerializerHelper.cs b/Example/Helpers/SerializerHelper.cs index 8fff769..c56335c 100644 --- a/Example/Helpers/SerializerHelper.cs +++ b/Example/Helpers/SerializerHelper.cs @@ -11,7 +11,9 @@ namespace Example using (var fs = File.CreateText(file)) { var serializer = new JsonSerializer(); + serializer.Converters.Add(new StringEnumConverter()); serializer.Formatting = Formatting.Indented; + serializer.Serialize(fs, obj); } }