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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22