/[RomCheater]/trunk/RomCheater/Docking/FloatingUserControlDock.cs
ViewVC logotype

Diff of /trunk/RomCheater/Docking/FloatingUserControlDock.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater/Docking/FloatingUserControlDock.cs	2014/09/16 21:08:49	854
+++ trunk/RomCheater/Docking/FloatingUserControlDock.cs	2014/09/16 21:09:17	855
@@ -8,12 +8,16 @@
 using System.Windows.Forms;
 using WeifenLuo.WinFormsUI.Docking;
 using RomCheater.Core;
+using System.IO;
 
 
 namespace RomCheater.Docking
 {
     public partial class FloatingUserControlDock : DockContent
     {
+        const string DockPanelConfig = "RomCheater-UserControls-DockPanel.conf";
+        private bool m_bSaveLayout = true;
+        private DeserializeDockContent m_deserializeDockContent;
         private List<IUserControlPlugin> userplugins;
 
         public List<IUserControlPlugin> UserPlugins
@@ -27,6 +31,7 @@
             InitializeComponent();
             this.Icon = Core.Properties.Resources.romcheater_icon;
             this.UserPlugins = new List<IUserControlPlugin>();
+            m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
         }
 
         //protected FloatingUserControlDock(List<IUserControlPlugin> plugins) : this()
@@ -34,20 +39,96 @@
         //  this.UserPlugins = plugins;
         //}
 
+
         private void FloatingUserControlDock_Shown(object sender, EventArgs e)
         {
+            this.dpanel.SuspendLayout(true);
+            //ShowDocks();
+            string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig);
+            if (File.Exists(configFile))
+            {
+                try
+                {
+                    this.dpanel.LoadFromXml(configFile, m_deserializeDockContent);
+
+                    try
+                    {
+                        List<IDockContent> contents = this.dpanel.Contents.ToList();
+                        if (contents != null)
+                        {
+                            foreach (IDockContent content in contents)
+                            {
+                                foreach (var plugin in this.UserPlugins)
+                                {
+                                    if (plugin.DockContent.ToString() == content.ToString())
+                                    {
+                                        plugin.DockHandler = content.DockHandler;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        throw ex;
+                    }
+                    
+                }
+                catch (Exception)
+                {
+                    ShowDocks();
+                }
+            }
+            else
+            {
+                ShowDocks();
+            }
+
+            this.dpanel.ResumeLayout(true, true);
+        }
+
+        private void ShowDocks()
+        {
             foreach (var plugin in this.UserPlugins)
             {
                 plugin.Show(this.dpanel);
             }
         }
-
+        private void SetupDockWindowHandler()
+        {
+            ShowDocks();
+        }
         private void FloatingUserControlDock_Deactivate(object sender, EventArgs e)
         {
+            string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig);
+            if (m_bSaveLayout)
+                this.dpanel.SaveAsXml(configFile);
+            else if (File.Exists(configFile))
+                File.Delete(configFile);
+
             foreach (var t in this.dpanel.Contents)
             {
                 t.OnDeactivate(e);
             }
         }
+        private IDockContent GetContentFromPersistString(string persistString)
+        {
+            IDockContent content = null;
+            foreach (var plugin in this.UserPlugins)
+            {
+                string t = plugin.DockContent.GetType().ToString();
+                if (persistString == t)
+                {
+                    content = plugin.DockContent;
+                    break;
+                }
+            }
+            return content;
+        }
+
+        private void FloatingUserControlDock_FormClosing(object sender, FormClosingEventArgs e)
+        {
+            FloatingUserControlDock_Deactivate(e, new EventArgs());
+        }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22