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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22