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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22