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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 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 using RomCheater.Core;
11 using System.IO;
12
13
14 namespace RomCheater.Docking
15 {
16 public partial class FloatingUserControlDock : DockContent
17 {
18 const string DockPanelConfig = "RomCheater-UserControls-DockPanel.conf";
19 private bool m_bSaveLayout = true;
20 private DeserializeDockContent m_deserializeDockContent;
21 private List<IUserControlPlugin> userplugins;
22
23 public List<IUserControlPlugin> UserPlugins
24 {
25 get { return userplugins; }
26 set { userplugins = value; }
27 }
28
29 public FloatingUserControlDock()
30 {
31 InitializeComponent();
32 this.Icon = Core.Properties.Resources.romcheater_icon;
33 this.UserPlugins = new List<IUserControlPlugin>();
34 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
35 }
36
37 //protected FloatingUserControlDock(List<IUserControlPlugin> plugins) : this()
38 //{
39 // this.UserPlugins = plugins;
40 //}
41
42
43 private void FloatingUserControlDock_Shown(object sender, EventArgs e)
44 {
45 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 foreach (var plugin in this.UserPlugins)
93 {
94 plugin.Show(this.dpanel);
95 }
96 }
97 private void SetupDockWindowHandler()
98 {
99 ShowDocks();
100 }
101 private void FloatingUserControlDock_Deactivate(object sender, EventArgs e)
102 {
103 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 foreach (var t in this.dpanel.Contents)
110 {
111 t.OnDeactivate(e);
112 }
113 }
114 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 }
134 }

  ViewVC Help
Powered by ViewVC 1.1.22