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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 855 - (hide annotations) (download)
Tue Sep 16 21:09:17 2014 UTC (6 years, 7 months ago) by william
File size: 4443 byte(s)
+ add support in UserControlDock to save and restore the user plugin layout

1 william 439 using System;
2     using System.Collections.Generic;
3     using System.ComponentModel;
4     using System.Data;
5     using System.Drawing;
6     using System.Linq;
7     using System.Text;
8     using System.Windows.Forms;
9     using WeifenLuo.WinFormsUI.Docking;
10 william 686 using RomCheater.Core;
11 william 855 using System.IO;
12 william 439
13 william 686
14 william 439 namespace RomCheater.Docking
15     {
16     public partial class FloatingUserControlDock : DockContent
17     {
18 william 855 const string DockPanelConfig = "RomCheater-UserControls-DockPanel.conf";
19     private bool m_bSaveLayout = true;
20     private DeserializeDockContent m_deserializeDockContent;
21 william 440 private List<IUserControlPlugin> userplugins;
22 william 639
23     public List<IUserControlPlugin> UserPlugins
24 william 439 {
25 william 639 get { return userplugins; }
26     set { userplugins = value; }
27 william 439 }
28    
29 william 639 public FloatingUserControlDock()
30 william 439 {
31 william 639 InitializeComponent();
32 william 838 this.Icon = Core.Properties.Resources.romcheater_icon;
33 william 639 this.UserPlugins = new List<IUserControlPlugin>();
34 william 855 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
35 william 439 }
36 william 440
37 william 639 //protected FloatingUserControlDock(List<IUserControlPlugin> plugins) : this()
38     //{
39     // this.UserPlugins = plugins;
40     //}
41    
42 william 855
43 william 440 private void FloatingUserControlDock_Shown(object sender, EventArgs e)
44     {
45 william 855 this.dpanel.SuspendLayout(true);
46     //ShowDocks();
47     string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig);
48     if (File.Exists(configFile))
49     {
50     try
51     {
52     this.dpanel.LoadFromXml(configFile, m_deserializeDockContent);
53    
54     try
55     {
56     List<IDockContent> contents = this.dpanel.Contents.ToList();
57     if (contents != null)
58     {
59     foreach (IDockContent content in contents)
60     {
61     foreach (var plugin in this.UserPlugins)
62     {
63     if (plugin.DockContent.ToString() == content.ToString())
64     {
65     plugin.DockHandler = content.DockHandler;
66     }
67     }
68     }
69     }
70     }
71     catch (Exception ex)
72     {
73     throw ex;
74     }
75    
76     }
77     catch (Exception)
78     {
79     ShowDocks();
80     }
81     }
82     else
83     {
84     ShowDocks();
85     }
86    
87     this.dpanel.ResumeLayout(true, true);
88     }
89    
90     private void ShowDocks()
91     {
92 william 639 foreach (var plugin in this.UserPlugins)
93 william 440 {
94     plugin.Show(this.dpanel);
95     }
96     }
97 william 855 private void SetupDockWindowHandler()
98     {
99     ShowDocks();
100     }
101 william 678 private void FloatingUserControlDock_Deactivate(object sender, EventArgs e)
102     {
103 william 855 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig);
104     if (m_bSaveLayout)
105     this.dpanel.SaveAsXml(configFile);
106     else if (File.Exists(configFile))
107     File.Delete(configFile);
108    
109 william 678 foreach (var t in this.dpanel.Contents)
110     {
111     t.OnDeactivate(e);
112     }
113     }
114 william 855 private IDockContent GetContentFromPersistString(string persistString)
115     {
116     IDockContent content = null;
117     foreach (var plugin in this.UserPlugins)
118     {
119     string t = plugin.DockContent.GetType().ToString();
120     if (persistString == t)
121     {
122     content = plugin.DockContent;
123     break;
124     }
125     }
126     return content;
127     }
128    
129     private void FloatingUserControlDock_FormClosing(object sender, FormClosingEventArgs e)
130     {
131     FloatingUserControlDock_Deactivate(e, new EventArgs());
132     }
133 william 439 }
134     }

  ViewVC Help
Powered by ViewVC 1.1.22