ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.RVAScratchPad/Form1.cs
Revision: 755
Committed: Thu Jun 20 20:04:53 2013 UTC (10 years, 3 months ago) by william
File size: 11572 byte(s)
Log Message:
* rename DockPanel config files
* use a constant string to set the config filename (so we can update/maintain in one location)

File Contents

# Content
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 using RomCheater.Logging;
9 using RomCheater.Docking;
10 using WeifenLuo.WinFormsUI.Docking;
11 using System.IO;
12 using RomCheater.PluginFramework.Core;
13 using RomCheater.Core;
14 using RomCheater.UserSettingsSupport;
15
16 namespace RomCheater.RVAScratchPad
17 {
18 public partial class Form1 : Form
19 {
20 const string DockPanelConfig = "RVAScratchPad-DockPanel.conf";
21 private SettingSubscriber SettingsSubscriber = null;
22 private bool m_bSaveLayout = true;
23 PluginLoader loader = null;
24 IConfigPlugin ConfigPlugin = null;
25
26 IUserControlPlugin RVACalcPlugin = null;
27 IUserControlPlugin ScratchPadPlugin = null;
28
29 private DeserializeDockContent m_deserializeDockContent;
30 //private FloatingLogWindow m_LogWindow = new FloatingLogWindow();
31 //private FloatingWebBrowser m_wb = new FloatingWebBrowser();
32
33 //public IWebBrowserProvider WebBrowserProvider
34 //{
35 // get { return new WebBrowserProvider(m_wb); }
36 //}
37 #region LogWriterSupport
38 static LogWriter _LoggerInstance;
39 static LogWriter LoggerInstance
40 {
41 get { return _LoggerInstance; }
42 set { _LoggerInstance = value; }
43 }
44 #endregion
45
46 public Form1() : this(false) { }
47 public Form1(bool no_console_redirect)
48 {
49 InitializeComponent();
50 SettingsSubscriber = new SettingSubscriber();
51 SettingsSubscriber.AddSubscriber(this, RomCheater.Properties.Settings.Default);
52 load_loggerflags();
53 SetupDocks();
54 //LoggerInstance = m_LogWindow.Logwriter;
55 LoggerInstance = new LogWriter(!no_console_redirect);
56 LoggerInstance.CreateNewLog(false);
57 logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
58 load_plugins();
59 if (no_console_redirect)
60 LoggerInstance.RedirectConsoleOutput = false;
61 }
62 private void load_loggerflags()
63 {
64 logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags);
65 #if FORCE_ALL_LOGGING_FLAGS
66 logger.SetLoggingFlags(loggerflags.ALL);
67 #endif
68 }
69 private void load_plugins() { load_plugins(false); }
70 private void load_plugins_silent() { load_plugins(true); }
71 private void load_plugins(bool silent)
72 {
73 loader = new PluginLoader();
74 loader.LoadPlugins(silent);
75
76 var LastConfigPlugin = SettingsSubscriber.GetValue("LastConfigPlugin").ToString();
77 if (LastConfigPlugin != null)
78 {
79 ConfigPlugin = loader.GetConfigPlugin(LastConfigPlugin.ToString());
80 }
81 else
82 {
83 var config = PluginCollection.GetPluginByName(PluginNames.GenericConfig);
84 ConfigPlugin = loader.GetPluginByGuid<IConfigPlugin>(config.ID.ToString());
85 }
86
87 // update the Config plugin's reference to the webbrowswer
88 //ConfigPlugin.WebBrowserProvider = this.WebBrowserProvider;
89
90 SettingsSubscriber.SetValue("LastConfigPlugin", ConfigPlugin.ToString());
91
92 var scratchpad = PluginCollection.GetPluginByName(PluginNames.ScratchPadPlugin);
93 var rvacalc = PluginCollection.GetPluginByName(PluginNames.RVACalculatorPlugin);
94 ScratchPadPlugin = loader.GetPluginByGuid<IUserControlPlugin>(scratchpad.ID.ToString());
95 RVACalcPlugin = loader.GetPluginByGuid<IUserControlPlugin>(rvacalc.ID.ToString());
96
97 // update config of each plugin
98 ScratchPadPlugin.SetAcceptedConfig(ConfigPlugin);
99 RVACalcPlugin.SetAcceptedConfig(ConfigPlugin);
100 }
101
102
103
104 #region Dock Support
105 private IDockContent GetContentFromPersistString(string persistString)
106 {
107 //if (persistString == typeof(FloatingLogWindow).ToString()) { return m_LogWindow; }
108 //if (persistString == typeof(FloatingWebBrowser).ToString()) { return m_wb; }
109 if (RVACalcPlugin != null) { if (persistString == RVACalcPlugin.IDockContentTypeName) { return RVACalcPlugin.DockContent; } }
110 if (ScratchPadPlugin != null) { if (persistString == ScratchPadPlugin.IDockContentTypeName) { return ScratchPadPlugin.DockContent; } }
111 return null;
112 }
113 public void SetupDocks()
114 {
115 //m_LogWindow = new FloatingLogWindow();
116 //m_LogWindow.CloseButton = false;
117 //m_LogWindow.CloseButtonVisible = false;
118
119 //m_wb = new FloatingWebBrowser();
120 //m_wb.CloseButton = false;
121 //m_wb.CloseButtonVisible = false;
122
123 if (RVACalcPlugin != null)
124 {
125 RVACalcPlugin.DockHandler.CloseButton = false;
126 RVACalcPlugin.DockHandler.CloseButtonVisible = false;
127 RVACalcPlugin.DockHandler.AllowEndUserDocking = false;
128 }
129 if (ScratchPadPlugin != null)
130 {
131 ScratchPadPlugin.DockHandler.CloseButton = false;
132 ScratchPadPlugin.DockHandler.CloseButtonVisible = false;
133 ScratchPadPlugin.DockHandler.AllowEndUserDocking = false;
134 }
135
136 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
137 }
138 #region SetupDockWindowHandler support
139 public void SetupDockWindowHandler()
140 {
141 //SetupLogWindowHandler();
142 //SetupWebBrowserWindowHandler();
143 SetupPluginWindowHandlers();
144 }
145 private void SetupPluginWindowHandlers()
146 {
147 if (RVACalcPlugin != null)
148 {
149 RVACalcPlugin.DockHandler.CloseButton = false;
150 RVACalcPlugin.DockHandler.CloseButtonVisible = false;
151 RVACalcPlugin.DockHandler.AllowEndUserDocking = false;
152 RVACalcPlugin.Activate();
153 }
154 if (ScratchPadPlugin != null)
155 {
156 ScratchPadPlugin.DockHandler.CloseButton = false;
157 ScratchPadPlugin.DockHandler.CloseButtonVisible = false;
158 ScratchPadPlugin.DockHandler.AllowEndUserDocking = false;
159 ScratchPadPlugin.Activate();
160 }
161 }
162 //private void SetupLogWindowHandler()
163 //{
164 // //if (m_LogWindow == null) return;
165 // ////m_LogWindow.Shown += new EventHandler(AddDockToWindowList);
166 // ////m_LogWindow.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
167 // //m_LogWindow.Activate();
168 //}
169 //private void SetupWebBrowserWindowHandler()
170 //{
171 // //if (m_wb == null) return;
172 // ////m_wb.Shown += new EventHandler(AddDockToWindowList);
173 // ////m_wb.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
174 // //m_wb.Activate();
175 //}
176 #endregion
177 public void ShowDocks()
178 {
179 //ShowLogWindow();
180 //SetupLogWindowHandler();
181 //ShowWebBrowser();
182 //SetupWebBrowserWindowHandler();
183 ShowPluginWindows();
184 SetupPluginWindowHandlers();
185
186 if (RVACalcPlugin != null)
187 RVACalcPlugin.Activate();
188 }
189 public void ShowLogWindow()
190 {
191 //if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); }
192 //if (LoggerInstance == null)
193 //{
194 // LoggerInstance = m_LogWindow.Logwriter;
195 // LoggerInstance.CreateNewLog(false);
196 //}
197 ////m_LogWindow.AllowEndUserDocking = true;
198 ////m_LogWindow.CloseButton = false;
199 ////m_LogWindow.CloseButtonVisible = false;
200 //m_LogWindow.Show(dockPanel, DockState.DockBottom);
201 }
202
203
204 public void ShowWebBrowser()
205 {
206 ////load_plugins_silent();
207 //m_wb = new FloatingWebBrowser();
208 ////m_wb.AllowEndUserDocking = true;
209 ////m_wb.CloseButton = false;
210 ////m_wb.CloseButtonVisible = false;
211 //m_wb.Show(dockPanel, DockState.Document);
212 }
213 public void ShowPluginWindows()
214 {
215 if (RVACalcPlugin != null)
216 {
217 // RVA Calc
218 RVACalcPlugin.DockHandler.CloseButton = false;
219 RVACalcPlugin.DockHandler.CloseButtonVisible = false;
220 RVACalcPlugin.DockHandler.AllowEndUserDocking = false;
221 RVACalcPlugin.Show(dockPanel, DockState.DockLeft);
222 }
223 if (ScratchPadPlugin != null)
224 {
225 // ScratchPad
226 ScratchPadPlugin.DockHandler.CloseButton = false;
227 ScratchPadPlugin.DockHandler.CloseButtonVisible = false;
228 ScratchPadPlugin.DockHandler.AllowEndUserDocking = false;
229 ScratchPadPlugin.Show(dockPanel, DockState.Document);
230 }
231 }
232 #endregion
233
234 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
235 {
236 SettingsSubscriber.SaveSettings();
237 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig);
238 if (m_bSaveLayout)
239 dockPanel.SaveAsXml(configFile);
240 else if (File.Exists(configFile))
241 File.Delete(configFile);
242 // notify any docked windows of formclosing
243 foreach (var t in this.dockPanel.Contents)
244 {
245 t.OnDeactivate<FormClosingEventArgs>(e);
246 }
247 }
248
249 private void Form1_Shown(object sender, EventArgs e)
250 {
251 ////dockPanel.SuspendLayout(true);
252 ////ShowDocks();
253 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig);
254 if (File.Exists(configFile))
255 {
256 try
257 {
258 dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
259 SetupDockWindowHandler();
260 }
261 catch (Exception)
262 {
263 this.Controls.Remove(dockPanel);
264 dockPanel = new DockPanel();
265 dockPanel.Dock = DockStyle.Fill;
266 dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
267 this.Controls.Add(dockPanel);
268 ShowDocks();
269 }
270 }
271 else
272 {
273 ShowDocks();
274 }
275
276 if (RVACalcPlugin != null)
277 RVACalcPlugin.Activate();
278 ////dockPanel.ResumeLayout(true, true);
279 }
280
281 private void mnuItemExit_Click(object sender, EventArgs e)
282 {
283 this.Close();
284 }
285
286 private void Form1_Load(object sender, EventArgs e) { }
287 }
288 }