/[RomCheater]/trunk/RomCheater.RVAScratchPad/Form1.cs
ViewVC logotype

Contents of /trunk/RomCheater.RVAScratchPad/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 838 - (show annotations) (download)
Tue Sep 16 00:57:18 2014 UTC (6 years, 2 months ago) by william
File size: 11659 byte(s)
+ add an icon resource

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

  ViewVC Help
Powered by ViewVC 1.1.22