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