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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 730 - (show annotations) (download)
Wed Jun 19 15:08:07 2013 UTC (7 years, 4 months ago) by william
File size: 10594 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 //m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
123 }
124 #region SetupDockWindowHandler support
125 public void SetupDockWindowHandler()
126 {
127 //SetupLogWindowHandler();
128 //SetupWebBrowserWindowHandler();
129 SetupPluginWindowHandlers();
130 }
131 private void SetupPluginWindowHandlers()
132 {
133 if (RVACalcPlugin != null)
134 {
135 RVACalcPlugin.Activate();
136 }
137 if (ScratchPadPlugin != null)
138 {
139 ScratchPadPlugin.Activate();
140 }
141 }
142 //private void SetupLogWindowHandler()
143 //{
144 // //if (m_LogWindow == null) return;
145 // ////m_LogWindow.Shown += new EventHandler(AddDockToWindowList);
146 // ////m_LogWindow.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
147 // //m_LogWindow.Activate();
148 //}
149 //private void SetupWebBrowserWindowHandler()
150 //{
151 // //if (m_wb == null) return;
152 // ////m_wb.Shown += new EventHandler(AddDockToWindowList);
153 // ////m_wb.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
154 // //m_wb.Activate();
155 //}
156 #endregion
157 public void ShowDocks()
158 {
159 //ShowLogWindow();
160 //SetupLogWindowHandler();
161 //ShowWebBrowser();
162 //SetupWebBrowserWindowHandler();
163 ShowPluginWindows();
164 SetupPluginWindowHandlers();
165
166 if (RVACalcPlugin != null)
167 RVACalcPlugin.Activate();
168 }
169 public void ShowLogWindow()
170 {
171 //if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); }
172 //if (LoggerInstance == null)
173 //{
174 // LoggerInstance = m_LogWindow.Logwriter;
175 // LoggerInstance.CreateNewLog(false);
176 //}
177 ////m_LogWindow.AllowEndUserDocking = true;
178 ////m_LogWindow.CloseButton = false;
179 ////m_LogWindow.CloseButtonVisible = false;
180 //m_LogWindow.Show(dockPanel, DockState.DockBottom);
181 }
182
183
184 public void ShowWebBrowser()
185 {
186 ////load_plugins_silent();
187 //m_wb = new FloatingWebBrowser();
188 ////m_wb.AllowEndUserDocking = true;
189 ////m_wb.CloseButton = false;
190 ////m_wb.CloseButtonVisible = false;
191 //m_wb.Show(dockPanel, DockState.Document);
192 }
193 public void ShowPluginWindows()
194 {
195 if (RVACalcPlugin != null)
196 {
197 // RVA Calc
198 RVACalcPlugin.DockHandler.CloseButton = false;
199 RVACalcPlugin.DockHandler.CloseButtonVisible = false;
200 RVACalcPlugin.DockHandler.AllowEndUserDocking = false;
201 RVACalcPlugin.Show(dockPanel);
202 }
203 if (ScratchPadPlugin != null)
204 {
205 // ScratchPad
206 //ScratchPadPlugin.DockHandler.CloseButton = false;
207 //ScratchPadPlugin.DockHandler.CloseButtonVisible = false;
208 //ScratchPadPlugin.DockHandler.AllowEndUserDocking = true;
209 ScratchPadPlugin.Show(dockPanel, DockState.Document);
210 }
211 }
212 #endregion
213
214 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
215 {
216 SettingsSubscriber.SaveSettings();
217 //string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
218 //if (m_bSaveLayout)
219 // dockPanel.SaveAsXml(configFile);
220 //else if (File.Exists(configFile))
221 // File.Delete(configFile);
222 // notify any docked windows of formclosing
223 foreach (var t in this.dockPanel.Contents)
224 {
225 t.OnDeactivate<FormClosingEventArgs>(e);
226 }
227 }
228
229 private void Form1_Shown(object sender, EventArgs e)
230 {
231 ////dockPanel.SuspendLayout(true);
232 ////ShowDocks();
233 //string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
234 //if (File.Exists(configFile))
235 //{
236 // try
237 // {
238 // dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
239 // SetupDockWindowHandler();
240 // }
241 // catch (Exception)
242 // {
243 // this.Controls.Remove(dockPanel);
244 // dockPanel = new DockPanel();
245 // dockPanel.Dock = DockStyle.Fill;
246 // dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
247 // this.Controls.Add(dockPanel);
248 // ShowDocks();
249 // }
250 //}
251 //else
252 //{
253 ShowDocks();
254 //}
255
256 if (RVACalcPlugin != null)
257 RVACalcPlugin.Activate();
258 ////dockPanel.ResumeLayout(true, true);
259 }
260
261 private void mnuItemExit_Click(object sender, EventArgs e)
262 {
263 this.Close();
264 }
265
266 private void Form1_Load(object sender, EventArgs e) { }
267 }
268 }

  ViewVC Help
Powered by ViewVC 1.1.22