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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 715 - (show annotations) (download)
Tue Jun 18 10:51:47 2013 UTC (7 years, 4 months ago) by william
File size: 7839 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 //void AddDockToWindowList(object sender, EventArgs e)
77 //{
78 // DockContent dc;
79 // TypeBinder.Bind(sender, out dc);
80 // ToolStripMenuItem tsmi = new ToolStripMenuItem(dc.Text);
81 // tsmi.Name = dc.Name;
82 // tsmi.Tag = dc;
83 // tsmi.Click += new EventHandler(tsmi_Click);
84 // mnuWindows.DropDownItems.Add(tsmi);
85 //}
86 //void tsmi_Click(object sender, EventArgs e)
87 //{
88 // ToolStripMenuItem tsmi;
89 // TypeBinder.Bind(sender, out tsmi);
90 // DockContent dc;
91 // TypeBinder.Bind(tsmi.Tag, out dc);
92 // dc.Activate();
93 //}
94 //void RemoveDockFromWindowList(object sender, FormClosedEventArgs e)
95 //{
96 // DockContent dc;
97 // TypeBinder.Bind(sender, out dc);
98 // mnuWindows.DropDownItems.RemoveByKey(dc.Name);
99 //}
100 private IDockContent GetContentFromPersistString(string persistString)
101 {
102 if (persistString == typeof(FloatingLogWindow).ToString()) { return m_LogWindow; }
103 if (persistString == typeof(FloatingWebBrowser).ToString()) { return m_wb; }
104 else { return null; }
105 }
106 public void SetupDocks()
107 {
108 m_LogWindow = new FloatingLogWindow();
109 m_wb = new FloatingWebBrowser();
110 }
111 #region SetupDockWindowHandler support
112 public void SetupDockWindowHandler()
113 {
114 SetupLogWindowHandler();
115 SetupWebBrowserWindowHandler();
116 }
117 private void SetupLogWindowHandler()
118 {
119 if (m_LogWindow == null) return;
120 //m_LogWindow.Shown += new EventHandler(AddDockToWindowList);
121 //m_LogWindow.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
122 m_LogWindow.Activate();
123 }
124 private void SetupWebBrowserWindowHandler()
125 {
126 if (m_wb == null) return;
127 //m_wb.Shown += new EventHandler(AddDockToWindowList);
128 //m_wb.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
129 //m_wb.Activate();
130 }
131 #endregion
132 public void ShowDocks()
133 {
134 ShowLogWindow();
135 SetupLogWindowHandler();
136 ShowWebBrowser();
137 SetupWebBrowserWindowHandler();
138 }
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 m_LogWindow.CloseButton = false;
145 m_LogWindow.CloseButtonVisible = false;
146 m_LogWindow.Show(dockPanel, DockState.DockBottom);
147 }
148
149
150 public void ShowWebBrowser()
151 {
152 //load_plugins_silent();
153 m_wb = new FloatingWebBrowser();
154 m_wb.CloseButton = false;
155 m_wb.CloseButtonVisible = false;
156 m_wb.Show(dockPanel);
157 }
158 #endregion
159
160 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
161 {
162 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
163 if (m_bSaveLayout)
164 dockPanel.SaveAsXml(configFile);
165 else if (File.Exists(configFile))
166 File.Delete(configFile);
167 // notify any docked windows of formclosing
168 foreach (var t in this.dockPanel.Contents)
169 {
170 t.OnDeactivate<FormClosingEventArgs>(e);
171 }
172 }
173
174 private void Form1_Shown(object sender, EventArgs e)
175 {
176 //dockPanel.SuspendLayout(true);
177 //ShowDocks();
178 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
179 if (File.Exists(configFile))
180 {
181 try
182 {
183 dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
184 SetupDockWindowHandler();
185 }
186 catch (Exception)
187 {
188 this.Controls.Remove(dockPanel);
189 dockPanel = new DockPanel();
190 dockPanel.Dock = DockStyle.Fill;
191 dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
192 this.Controls.Add(dockPanel);
193 ShowDocks();
194 }
195 }
196 else
197 {
198 ShowDocks();
199 }
200
201 //dockPanel.ResumeLayout(true, true);
202 }
203
204 private void mnuItemExit_Click(object sender, EventArgs e)
205 {
206 this.Close();
207 }
208 }
209 }

  ViewVC Help
Powered by ViewVC 1.1.22