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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 732 - (show annotations) (download)
Wed Jun 19 15:18:52 2013 UTC (7 years, 4 months ago) by william
File size: 11534 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22