mirror of
https://github.com/colhountech/DarkUI.Net5.git
synced 2025-07-02 23:29:28 +03:00
Added DockPanel serialization.
This commit is contained in:
parent
7a7607c959
commit
06e5d26801
@ -128,6 +128,7 @@
|
|||||||
<Compile Include="Docking\DarkDockTab.cs" />
|
<Compile Include="Docking\DarkDockTab.cs" />
|
||||||
<Compile Include="Docking\DarkDockTabArea.cs" />
|
<Compile Include="Docking\DarkDockTabArea.cs" />
|
||||||
<Compile Include="Docking\DockContentEvenArgs.cs" />
|
<Compile Include="Docking\DockContentEvenArgs.cs" />
|
||||||
|
<Compile Include="Docking\DockPanelState.cs" />
|
||||||
<Compile Include="Extensions\BitmapExtensions.cs" />
|
<Compile Include="Extensions\BitmapExtensions.cs" />
|
||||||
<Compile Include="Extensions\IEnumerableExtensions.cs" />
|
<Compile Include="Extensions\IEnumerableExtensions.cs" />
|
||||||
<Compile Include="Forms\DarkDialog.cs">
|
<Compile Include="Forms\DarkDialog.cs">
|
||||||
|
@ -51,6 +51,10 @@ namespace DarkUI.Docking
|
|||||||
[DefaultValue(DarkDockArea.Document)]
|
[DefaultValue(DarkDockArea.Document)]
|
||||||
public DarkDockArea DockArea { get; set; }
|
public DarkDockArea DockArea { get; set; }
|
||||||
|
|
||||||
|
[Category("Behavior")]
|
||||||
|
[Description("Determines the key used by this content in the dock serialization.")]
|
||||||
|
public string SerializationKey { get; set; }
|
||||||
|
|
||||||
[Browsable(false)]
|
[Browsable(false)]
|
||||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||||
public DarkDockPanel DockPanel { get; internal set; }
|
public DarkDockPanel DockPanel { get; internal set; }
|
||||||
|
@ -192,6 +192,36 @@ namespace DarkUI.Docking
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Serialization Region
|
||||||
|
|
||||||
|
public DockPanelState GetDockPanelState()
|
||||||
|
{
|
||||||
|
var state = new DockPanelState();
|
||||||
|
|
||||||
|
foreach (var content in _contents)
|
||||||
|
state.OpenContent.Add(content.SerializationKey);
|
||||||
|
|
||||||
|
state.LeftRegionSize = _regions[DarkDockArea.Left].Size;
|
||||||
|
state.RightRegionSize = _regions[DarkDockArea.Right].Size;
|
||||||
|
state.BottomRegionSize = _regions[DarkDockArea.Bottom].Size;
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RestoreDockPanelRegions(DockPanelState state)
|
||||||
|
{
|
||||||
|
if (state.LeftRegionSize.Width > 0 && state.LeftRegionSize.Height > 0)
|
||||||
|
_regions[DarkDockArea.Left].Size = state.LeftRegionSize;
|
||||||
|
|
||||||
|
if (state.RightRegionSize.Width > 0 && state.RightRegionSize.Height > 0)
|
||||||
|
_regions[DarkDockArea.Right].Size = state.RightRegionSize;
|
||||||
|
|
||||||
|
if (state.BottomRegionSize.Width > 0 && state.BottomRegionSize.Height > 0)
|
||||||
|
_regions[DarkDockArea.Bottom].Size = state.BottomRegionSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
38
DarkUI/Docking/DockPanelState.cs
Normal file
38
DarkUI/Docking/DockPanelState.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace DarkUI.Docking
|
||||||
|
{
|
||||||
|
public class DockPanelState
|
||||||
|
{
|
||||||
|
#region Property Region
|
||||||
|
|
||||||
|
public List<string> OpenContent { get; set; }
|
||||||
|
|
||||||
|
public Size LeftRegionSize { get; set; }
|
||||||
|
|
||||||
|
public Size RightRegionSize { get; set; }
|
||||||
|
|
||||||
|
public Size BottomRegionSize { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructor Region
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
@ -34,6 +34,9 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Newtonsoft.Json">
|
||||||
|
<HintPath>.\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
@ -95,6 +98,7 @@
|
|||||||
<Compile Include="Forms\MainForm.Designer.cs">
|
<Compile Include="Forms\MainForm.Designer.cs">
|
||||||
<DependentUpon>MainForm.cs</DependentUpon>
|
<DependentUpon>MainForm.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Helpers\SerializerHelper.cs" />
|
||||||
<Compile Include="Icons.Designer.cs">
|
<Compile Include="Icons.Designer.cs">
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
|
5
Example/Forms/Docking/DockConsole.Designer.cs
generated
5
Example/Forms/Docking/DockConsole.Designer.cs
generated
@ -31,7 +31,7 @@ namespace Example
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.lstConsole = new DarkListView();
|
this.lstConsole = new DarkUI.Controls.DarkListView();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// lstConsole
|
// lstConsole
|
||||||
@ -49,11 +49,12 @@ namespace Example
|
|||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.Controls.Add(this.lstConsole);
|
this.Controls.Add(this.lstConsole);
|
||||||
this.DockArea = DarkDockArea.Bottom;
|
this.DockArea = DarkUI.Docking.DarkDockArea.Bottom;
|
||||||
this.DockText = "Console";
|
this.DockText = "Console";
|
||||||
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
this.Icon = global::Example.Icons.Console;
|
this.Icon = global::Example.Icons.Console;
|
||||||
this.Name = "DockConsole";
|
this.Name = "DockConsole";
|
||||||
|
this.SerializationKey = "DockConsole";
|
||||||
this.Size = new System.Drawing.Size(500, 200);
|
this.Size = new System.Drawing.Size(500, 200);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
3
Example/Forms/Docking/DockHistory.Designer.cs
generated
3
Example/Forms/Docking/DockHistory.Designer.cs
generated
@ -49,11 +49,12 @@ namespace Example
|
|||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.Controls.Add(this.lstHistory);
|
this.Controls.Add(this.lstHistory);
|
||||||
this.DockArea = DarkDockArea.Right;
|
this.DockArea = DarkUI.Docking.DarkDockArea.Right;
|
||||||
this.DockText = "History";
|
this.DockText = "History";
|
||||||
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
this.Icon = global::Example.Icons.RefactoringLog_12810;
|
this.Icon = global::Example.Icons.RefactoringLog_12810;
|
||||||
this.Name = "DockHistory";
|
this.Name = "DockHistory";
|
||||||
|
this.SerializationKey = "DockHistory";
|
||||||
this.Size = new System.Drawing.Size(280, 450);
|
this.Size = new System.Drawing.Size(280, 450);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
5
Example/Forms/Docking/DockLayers.Designer.cs
generated
5
Example/Forms/Docking/DockLayers.Designer.cs
generated
@ -31,7 +31,7 @@ namespace Example
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.lstLayers = new DarkListView();
|
this.lstLayers = new DarkUI.Controls.DarkListView();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// lstLayers
|
// lstLayers
|
||||||
@ -48,11 +48,12 @@ namespace Example
|
|||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.Controls.Add(this.lstLayers);
|
this.Controls.Add(this.lstLayers);
|
||||||
this.DockArea = DarkDockArea.Right;
|
this.DockArea = DarkUI.Docking.DarkDockArea.Right;
|
||||||
this.DockText = "Layers";
|
this.DockText = "Layers";
|
||||||
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
this.Icon = global::Example.Icons.Collection_16xLG;
|
this.Icon = global::Example.Icons.Collection_16xLG;
|
||||||
this.Name = "DockLayers";
|
this.Name = "DockLayers";
|
||||||
|
this.SerializationKey = "DockLayers";
|
||||||
this.Size = new System.Drawing.Size(280, 450);
|
this.Size = new System.Drawing.Size(280, 450);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
6
Example/Forms/Docking/DockProject.Designer.cs
generated
6
Example/Forms/Docking/DockProject.Designer.cs
generated
@ -32,7 +32,7 @@ namespace Example
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.treeProject = new DarkTreeView();
|
this.treeProject = new DarkUI.Controls.DarkTreeView();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// treeProject
|
// treeProject
|
||||||
@ -40,6 +40,7 @@ namespace Example
|
|||||||
this.treeProject.AllowMoveNodes = true;
|
this.treeProject.AllowMoveNodes = true;
|
||||||
this.treeProject.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.treeProject.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.treeProject.Location = new System.Drawing.Point(0, 25);
|
this.treeProject.Location = new System.Drawing.Point(0, 25);
|
||||||
|
this.treeProject.MaxDragChange = 20;
|
||||||
this.treeProject.MultiSelect = true;
|
this.treeProject.MultiSelect = true;
|
||||||
this.treeProject.Name = "treeProject";
|
this.treeProject.Name = "treeProject";
|
||||||
this.treeProject.ShowIcons = true;
|
this.treeProject.ShowIcons = true;
|
||||||
@ -52,11 +53,12 @@ namespace Example
|
|||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.Controls.Add(this.treeProject);
|
this.Controls.Add(this.treeProject);
|
||||||
this.DockArea = DarkDockArea.Left;
|
this.DockArea = DarkUI.Docking.DarkDockArea.Left;
|
||||||
this.DockText = "Project Explorer";
|
this.DockText = "Project Explorer";
|
||||||
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
this.Icon = global::Example.Icons.application_16x;
|
this.Icon = global::Example.Icons.application_16x;
|
||||||
this.Name = "DockProject";
|
this.Name = "DockProject";
|
||||||
|
this.SerializationKey = "DockProject";
|
||||||
this.Size = new System.Drawing.Size(280, 450);
|
this.Size = new System.Drawing.Size(280, 450);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
3
Example/Forms/Docking/DockProperties.Designer.cs
generated
3
Example/Forms/Docking/DockProperties.Designer.cs
generated
@ -177,11 +177,12 @@ namespace Example
|
|||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.Controls.Add(this.pnlMain);
|
this.Controls.Add(this.pnlMain);
|
||||||
this.DockArea = DarkDockArea.Right;
|
this.DockArea = DarkUI.Docking.DarkDockArea.Right;
|
||||||
this.DockText = "Properties";
|
this.DockText = "Properties";
|
||||||
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
this.Icon = global::Example.Icons.properties_16xLG;
|
this.Icon = global::Example.Icons.properties_16xLG;
|
||||||
this.Name = "DockProperties";
|
this.Name = "DockProperties";
|
||||||
|
this.SerializationKey = "DockProperties";
|
||||||
this.Size = new System.Drawing.Size(280, 450);
|
this.Size = new System.Drawing.Size(280, 450);
|
||||||
this.pnlMain.ResumeLayout(false);
|
this.pnlMain.ResumeLayout(false);
|
||||||
this.pnlMain.PerformLayout();
|
this.pnlMain.PerformLayout();
|
||||||
|
@ -3,6 +3,7 @@ using DarkUI.Forms;
|
|||||||
using DarkUI.Win32;
|
using DarkUI.Win32;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Example
|
namespace Example
|
||||||
@ -52,12 +53,20 @@ namespace Example
|
|||||||
_toolWindows.Add(_dockLayers);
|
_toolWindows.Add(_dockLayers);
|
||||||
_toolWindows.Add(_dockHistory);
|
_toolWindows.Add(_dockHistory);
|
||||||
|
|
||||||
// Add the tool window list contents to the dock panel
|
// Deserialize if a previous state is stored
|
||||||
foreach (var toolWindow in _toolWindows)
|
if (File.Exists("dockpanel.config"))
|
||||||
DockPanel.AddContent(toolWindow);
|
{
|
||||||
|
DeserializeDockPanel("dockpanel.config");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Add the tool window list contents to the dock panel
|
||||||
|
foreach (var toolWindow in _toolWindows)
|
||||||
|
DockPanel.AddContent(toolWindow);
|
||||||
|
|
||||||
// Add the history panel to the layer panel group
|
// Add the history panel to the layer panel group
|
||||||
DockPanel.AddContent(_dockHistory, _dockLayers.DockGroup);
|
DockPanel.AddContent(_dockHistory, _dockLayers.DockGroup);
|
||||||
|
}
|
||||||
|
|
||||||
// Check window menu items which are contained in the dock panel
|
// Check window menu items which are contained in the dock panel
|
||||||
BuildWindowMenu();
|
BuildWindowMenu();
|
||||||
@ -74,6 +83,8 @@ namespace Example
|
|||||||
|
|
||||||
private void HookEvents()
|
private void HookEvents()
|
||||||
{
|
{
|
||||||
|
FormClosing += MainForm_FormClosing;
|
||||||
|
|
||||||
DockPanel.ContentAdded += DockPanel_ContentAdded;
|
DockPanel.ContentAdded += DockPanel_ContentAdded;
|
||||||
DockPanel.ContentRemoved += DockPanel_ContentRemoved;
|
DockPanel.ContentRemoved += DockPanel_ContentRemoved;
|
||||||
|
|
||||||
@ -114,6 +125,11 @@ namespace Example
|
|||||||
|
|
||||||
#region Event Handler Region
|
#region Event Handler Region
|
||||||
|
|
||||||
|
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
|
{
|
||||||
|
SerializeDockPanel("dockpanel.config");
|
||||||
|
}
|
||||||
|
|
||||||
private void DockPanel_ContentAdded(object sender, DockContentEventArgs e)
|
private void DockPanel_ContentAdded(object sender, DockContentEventArgs e)
|
||||||
{
|
{
|
||||||
if (_toolWindows.Contains(e.Content))
|
if (_toolWindows.Contains(e.Content))
|
||||||
@ -175,5 +191,40 @@ namespace Example
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Serialization Region
|
||||||
|
|
||||||
|
private void SerializeDockPanel(string path)
|
||||||
|
{
|
||||||
|
var state = DockPanel.GetDockPanelState();
|
||||||
|
SerializerHelper.Serialize(state, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private DarkDockContent GetContentBySerializationKey(string key)
|
||||||
|
{
|
||||||
|
foreach (var window in _toolWindows)
|
||||||
|
{
|
||||||
|
if (window.SerializationKey == key)
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
31
Example/Helpers/SerializerHelper.cs
Normal file
31
Example/Helpers/SerializerHelper.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Example
|
||||||
|
{
|
||||||
|
public class SerializerHelper
|
||||||
|
{
|
||||||
|
public static void Serialize<T>(T obj, string file)
|
||||||
|
{
|
||||||
|
using (var fs = File.CreateText(file))
|
||||||
|
{
|
||||||
|
var serializer = new JsonSerializer();
|
||||||
|
serializer.Formatting = Formatting.Indented;
|
||||||
|
serializer.Serialize(fs, obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T Deserialize<T>(string file) where T : class
|
||||||
|
{
|
||||||
|
using (var fs = File.OpenText(file))
|
||||||
|
{
|
||||||
|
var serializer = new JsonSerializer();
|
||||||
|
serializer.Converters.Add(new StringEnumConverter());
|
||||||
|
|
||||||
|
var result = serializer.Deserialize(fs, typeof(T));
|
||||||
|
return result as T;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
Example/Newtonsoft.Json.dll
Normal file
BIN
Example/Newtonsoft.Json.dll
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user