mirror of
https://github.com/colhountech/DarkUI.Net5.git
synced 2025-07-17 02:06:12 +03:00
Dock panel serialisation now persists group states.
This commit is contained in:
parent
31eaec9cb1
commit
a0ded1a34d
@ -127,8 +127,10 @@
|
||||
<Compile Include="Docking\DarkDockSplitter.cs" />
|
||||
<Compile Include="Docking\DarkDockTab.cs" />
|
||||
<Compile Include="Docking\DarkDockTabArea.cs" />
|
||||
<Compile Include="Docking\DockContentEvenArgs.cs" />
|
||||
<Compile Include="Docking\DockContentEventArgs.cs" />
|
||||
<Compile Include="Docking\DockGroupState.cs" />
|
||||
<Compile Include="Docking\DockPanelState.cs" />
|
||||
<Compile Include="Docking\DockRegionState.cs" />
|
||||
<Compile Include="Extensions\BitmapExtensions.cs" />
|
||||
<Compile Include="Extensions\IEnumerableExtensions.cs" />
|
||||
<Compile Include="Forms\DarkDialog.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<DarkDockGroup, DockGroupState>();
|
||||
|
||||
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<string, DarkDockContent> 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
|
||||
|
22
DarkUI/Docking/DockGroupState.cs
Normal file
22
DarkUI/Docking/DockGroupState.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DarkUI.Docking
|
||||
{
|
||||
public class DockGroupState
|
||||
{
|
||||
#region Property Region
|
||||
|
||||
public List<string> Contents { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor Region
|
||||
|
||||
public DockGroupState()
|
||||
{
|
||||
Contents = new List<string>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -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<string> OpenContent { get; set; }
|
||||
|
||||
public Size LeftRegionSize { get; set; }
|
||||
|
||||
public Size RightRegionSize { get; set; }
|
||||
|
||||
public Size BottomRegionSize { get; set; }
|
||||
public List<DockRegionState> Regions { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@ -21,16 +14,7 @@ namespace DarkUI.Docking
|
||||
|
||||
public DockPanelState()
|
||||
{
|
||||
OpenContent = new List<string>();
|
||||
}
|
||||
|
||||
public DockPanelState(List<string> openContent, Size leftRegionSize, Size rightRegionSize, Size bottomRegionSize)
|
||||
: this()
|
||||
{
|
||||
OpenContent = openContent;
|
||||
LeftRegionSize = leftRegionSize;
|
||||
RightRegionSize = rightRegionSize;
|
||||
BottomRegionSize = bottomRegionSize;
|
||||
Regions = new List<DockRegionState>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
39
DarkUI/Docking/DockRegionState.cs
Normal file
39
DarkUI/Docking/DockRegionState.cs
Normal file
@ -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<DockGroupState> Groups { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor Region
|
||||
|
||||
public DockRegionState()
|
||||
{
|
||||
Groups = new List<DockGroupState>();
|
||||
}
|
||||
|
||||
public DockRegionState(DarkDockArea area)
|
||||
: this()
|
||||
{
|
||||
Area = area;
|
||||
}
|
||||
|
||||
public DockRegionState(DarkDockArea area, Size size)
|
||||
: this(area)
|
||||
{
|
||||
Size = size;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -203,15 +203,7 @@ namespace Example
|
||||
private void DeserializeDockPanel(string path)
|
||||
{
|
||||
var state = SerializerHelper.Deserialize<DockPanelState>(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)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user