ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.RVAScratchPad/Form1.cs
Revision: 814
Committed: Tue Apr 15 15:58:50 2014 UTC (9 years, 1 month ago) by william
File size: 11591 byte(s)
Log Message:

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