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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 892 - (show annotations) (download)
Wed Sep 17 05:56:41 2014 UTC (6 years, 10 months ago) by william
File size: 12893 byte(s)
+ alot of dang work to force an icon to be shown on the docked panels
  ** when it was as simple as setting: DockPanel.ShowDocumentIcon to true

1 #define FORCE_DISABLE_PROFILER_LOGLEVEL // when define will forcibly disable the profiler loglevel
2 using System;
3 using System.Collections.Generic;
4 using System.ComponentModel;
5 using System.Data;
6 using System.Drawing;
7 using System.Text;
8 using System.Windows.Forms;
9 using RomCheater.Logging;
10 using RomCheater.Core.Docking;
11 using WeifenLuo.WinFormsUI.Docking;
12 using System.IO;
13 using RomCheater.PluginFramework.Core;
14 using RomCheater.Interfaces;
15 using RomCheater.UserSettingsSupport;
16 using Enterprise.Logging;
17
18 namespace RomCheater.RVAScratchPad
19 {
20 public partial class Form1 : Form
21 {
22 const string DockPanelConfig = "RVAScratchPad-DockPanel.conf";
23 private SettingSubscriber SettingsSubscriber = null;
24 private bool m_bSaveLayout = true;
25 PluginLoader loader = null;
26 IConfigPlugin ConfigPlugin = null;
27
28 IUserControlPlugin RVACheatListPlugin = null;
29 IUserControlPlugin ScratchPadPlugin = null;
30
31 private LogLevel logging_level = LogLevel.kLogLevel_All;
32 private DeserializeDockContent m_deserializeDockContent;
33 //private FloatingLogWindow m_LogWindow = new FloatingLogWindow();
34 //private FloatingWebBrowser m_wb = new FloatingWebBrowser();
35
36 //public IWebBrowserProvider WebBrowserProvider
37 //{
38 // get { return new WebBrowserProvider(m_wb); }
39 //}
40 #region LogWriterSupport
41 static LogWriter _LoggerInstance;
42 static LogWriter LoggerInstance
43 {
44 get { return _LoggerInstance; }
45 set { _LoggerInstance = value; }
46 }
47 #endregion
48
49 public Form1() : this(false) { }
50 public Form1(bool no_console_redirect)
51 {
52 InitializeComponent();
53 SettingsSubscriber = new SettingSubscriber();
54 SettingsSubscriber.AddSubscriber(this, RomCheater.Properties.Settings.Default);
55 //load_loggerflags();
56 SetupDocks();
57 //LoggerInstance = m_LogWindow.Logwriter;
58 LoggerInstance = new LogWriter();
59 load_loggerflags();
60 load_plugins();
61 //if (no_console_redirect)
62 // LoggerInstance.RedirectConsoleOutput = false;
63 }
64 private void load_loggerflags()
65 {
66 bool upgraded_flags = Logging.Properties.Settings.Default.UpgradedLogLevel;
67 if (!upgraded_flags)
68 {
69 logging_level = new LoggingFlagsConverter(Logging.Properties.Settings.Default.LoggingFlags).ConvertFlags();
70 Logging.Properties.Settings.Default.UpgradedLogLevel = true;
71 Logging.Properties.Settings.Default.gLogLoggingFlags = (uint)logging_level;
72 Logging.Properties.Settings.Default.Save();
73 }
74 logging_level = (LogLevel)Logging.Properties.Settings.Default.gLogLoggingFlags;
75 #if FORCE_ALL_LOGGING_FLAGS
76 logging_level = LogLevel.kLogLevel_All;
77 #endif
78 #if FORCE_DISABLE_PROFILER_LOGLEVEL
79 logging_level = logging_level & ~LogLevel.kLogLevel_Profiler;
80 logging_level = logging_level & ~LogLevel.kLogLevel_VerboseProfiler;
81 #endif
82 gLog.CreateLog(LoggingConstants.AppFullLogPath, true, logging_level, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush), LoggerInstance.Log);
83 }
84 private void Log_OnFlush(object sender, LoggerOnFlushEventArgs e)
85 {
86 }
87 private void load_plugins() { load_plugins(false); }
88 private void load_plugins_silent() { load_plugins(true); }
89 private void load_plugins(bool silent)
90 {
91 loader = new PluginLoader();
92 loader.LoadPlugins(silent);
93
94 var LastConfigPlugin = SettingsSubscriber.GetValue("LastConfigPlugin").ToString();
95 if (LastConfigPlugin != null)
96 {
97 ConfigPlugin = loader.GetConfigPlugin(LastConfigPlugin.ToString());
98 }
99 else
100 {
101 var config = PluginCollection.GetPluginByName(PluginNames.GenericConfig);
102 ConfigPlugin = loader.GetPluginByGuid<IConfigPlugin>(config.ID.ToString());
103 }
104
105 // update the Config plugin's reference to the webbrowswer
106 //ConfigPlugin.WebBrowserProvider = this.WebBrowserProvider;
107
108 SettingsSubscriber.SetValue("LastConfigPlugin", ConfigPlugin.ToString());
109
110 var scratchpad = PluginCollection.GetPluginByName(PluginNames.ScratchPadPlugin);
111 var rvacheatlist = PluginCollection.GetPluginByName(PluginNames.RVACheatListPlugin);
112 ScratchPadPlugin = loader.GetPluginByGuid<IUserControlPlugin>(scratchpad.ID.ToString());
113 RVACheatListPlugin = loader.GetPluginByGuid<IUserControlPlugin>(rvacheatlist.ID.ToString());
114
115 // update config of each plugin
116 ScratchPadPlugin.SetAcceptedConfig(ConfigPlugin);
117 RVACheatListPlugin.SetAcceptedConfig(ConfigPlugin);
118 }
119
120
121
122 #region Dock Support
123 private IDockContent GetContentFromPersistString(string persistString)
124 {
125 //if (persistString == typeof(FloatingLogWindow).ToString()) { return m_LogWindow; }
126 //if (persistString == typeof(FloatingWebBrowser).ToString()) { return m_wb; }
127 if (RVACheatListPlugin != null) { if (persistString == RVACheatListPlugin.IDockContentTypeName) { return RVACheatListPlugin.DockContent; } }
128 if (ScratchPadPlugin != null) { if (persistString == ScratchPadPlugin.IDockContentTypeName) { return ScratchPadPlugin.DockContent; } }
129 return null;
130 }
131 public void SetupDocks()
132 {
133 //m_LogWindow = new FloatingLogWindow();
134 //m_LogWindow.CloseButton = false;
135 //m_LogWindow.CloseButtonVisible = false;
136
137 //m_wb = new FloatingWebBrowser();
138 //m_wb.CloseButton = false;
139 //m_wb.CloseButtonVisible = false;
140
141 if (RVACheatListPlugin != null)
142 {
143 RVACheatListPlugin.DockHandler.CloseButton = false;
144 RVACheatListPlugin.DockHandler.CloseButtonVisible = false;
145 RVACheatListPlugin.DockHandler.AllowEndUserDocking = false;
146 }
147 if (ScratchPadPlugin != null)
148 {
149 ScratchPadPlugin.DockHandler.CloseButton = false;
150 ScratchPadPlugin.DockHandler.CloseButtonVisible = false;
151 ScratchPadPlugin.DockHandler.AllowEndUserDocking = false;
152 }
153
154 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
155 }
156 #region SetupDockWindowHandler support
157 public void SetupDockWindowHandler()
158 {
159 //SetupLogWindowHandler();
160 //SetupWebBrowserWindowHandler();
161 SetupPluginWindowHandlers();
162 }
163 private void SetupPluginWindowHandlers()
164 {
165 if (RVACheatListPlugin != null)
166 {
167 RVACheatListPlugin.DockHandler.CloseButton = false;
168 RVACheatListPlugin.DockHandler.CloseButtonVisible = false;
169 RVACheatListPlugin.DockHandler.AllowEndUserDocking = false;
170 RVACheatListPlugin.SetIcon(Core.Properties.Resources.romcheater_icon);
171 RVACheatListPlugin.Activate();
172 }
173 if (ScratchPadPlugin != null)
174 {
175 ScratchPadPlugin.DockHandler.CloseButton = false;
176 ScratchPadPlugin.DockHandler.CloseButtonVisible = false;
177 ScratchPadPlugin.DockHandler.AllowEndUserDocking = false;
178 ScratchPadPlugin.SetIcon(Core.Properties.Resources.romcheater_icon);
179 ScratchPadPlugin.Activate();
180 }
181 }
182 //private void SetupLogWindowHandler()
183 //{
184 // //if (m_LogWindow == null) return;
185 // ////m_LogWindow.Shown += new EventHandler(AddDockToWindowList);
186 // ////m_LogWindow.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
187 // //m_LogWindow.Activate();
188 //}
189 //private void SetupWebBrowserWindowHandler()
190 //{
191 // //if (m_wb == null) return;
192 // ////m_wb.Shown += new EventHandler(AddDockToWindowList);
193 // ////m_wb.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
194 // //m_wb.Activate();
195 //}
196 #endregion
197 public void ShowDocks()
198 {
199 //ShowLogWindow();
200 //SetupLogWindowHandler();
201 //ShowWebBrowser();
202 //SetupWebBrowserWindowHandler();
203 ShowPluginWindows();
204 SetupPluginWindowHandlers();
205
206 if (RVACheatListPlugin != null)
207 RVACheatListPlugin.Activate();
208 }
209 public void ShowLogWindow()
210 {
211 //if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); }
212 //if (LoggerInstance == null)
213 //{
214 // LoggerInstance = m_LogWindow.Logwriter;
215 // LoggerInstance.CreateNewLog(false);
216 //}
217 ////m_LogWindow.AllowEndUserDocking = true;
218 ////m_LogWindow.CloseButton = false;
219 ////m_LogWindow.CloseButtonVisible = false;
220 //m_LogWindow.Show(dockPanel, DockState.DockBottom);
221 }
222
223
224 public void ShowWebBrowser()
225 {
226 ////load_plugins_silent();
227 //m_wb = new FloatingWebBrowser();
228 ////m_wb.AllowEndUserDocking = true;
229 ////m_wb.CloseButton = false;
230 ////m_wb.CloseButtonVisible = false;
231 //m_wb.Show(dockPanel, DockState.Document);
232 }
233 public void ShowPluginWindows()
234 {
235 if (RVACheatListPlugin != null)
236 {
237 // RVA Calc
238 RVACheatListPlugin.DockHandler.CloseButton = false;
239 RVACheatListPlugin.DockHandler.CloseButtonVisible = false;
240 RVACheatListPlugin.DockHandler.AllowEndUserDocking = false;
241 RVACheatListPlugin.Show(dockPanel, DockState.DockLeft);
242 }
243 if (ScratchPadPlugin != null)
244 {
245 // ScratchPad
246 ScratchPadPlugin.DockHandler.CloseButton = false;
247 ScratchPadPlugin.DockHandler.CloseButtonVisible = false;
248 ScratchPadPlugin.DockHandler.AllowEndUserDocking = false;
249 ScratchPadPlugin.Show(dockPanel, DockState.Document);
250 }
251 }
252 #endregion
253
254 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
255 {
256 SettingsSubscriber.SaveSettings();
257 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig);
258 if (m_bSaveLayout)
259 dockPanel.SaveAsXml(configFile);
260 else if (File.Exists(configFile))
261 File.Delete(configFile);
262 // notify any docked windows of formclosing
263 foreach (var t in this.dockPanel.Contents)
264 {
265 t.OnDeactivate<FormClosingEventArgs>(e);
266 }
267 }
268
269 private void Form1_Shown(object sender, EventArgs e)
270 {
271 dockPanel.SuspendLayout(true);
272 ////ShowDocks();
273 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig);
274 if (File.Exists(configFile))
275 {
276 try
277 {
278 dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
279 SetupDockWindowHandler();
280 }
281 catch (Exception)
282 {
283 //this.Controls.Remove(dockPanel);
284 //dockPanel = new DockPanel();
285 //dockPanel.Dock = DockStyle.Fill;
286 //dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
287 //this.Controls.Add(dockPanel);
288 ShowDocks();
289 }
290 }
291 else
292 {
293 ShowDocks();
294 }
295
296 if (RVACheatListPlugin != null)
297 RVACheatListPlugin.Activate();
298 dockPanel.ResumeLayout(true, true);
299 }
300
301 private void mnuItemExit_Click(object sender, EventArgs e)
302 {
303 this.Close();
304 }
305
306 private void Form1_Load(object sender, EventArgs e) { }
307 }
308 }

  ViewVC Help
Powered by ViewVC 1.1.22