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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 713 - (hide annotations) (download)
Tue Jun 18 10:25:55 2013 UTC (7 years, 4 months ago) by william
File size: 8827 byte(s)

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 707
15     namespace RomCheater.RVAScratchPad
16     {
17     public partial class Form1 : Form
18     {
19 william 708 private bool m_bSaveLayout = true;
20 william 712 PluginLoader loader = null;
21     IConfigPlugin ConfigPlugin = null;
22    
23     IUserControlPlugin RVACalcPlugin = null;
24     IUserControlPlugin ScratchPadPlugin = null;
25    
26 william 708 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 william 707 {
34 william 708 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 william 707 InitializeComponent();
43 william 708 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 william 707 }
52 william 708 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 william 712 loader = new PluginLoader();
64     loader.LoadPlugins(silent);
65    
66    
67     ConfigPlugin = loader.GetGenericConfigPlugin();
68     if (ConfigPlugin != null && !silent)
69     logger.Info.WriteLine("Loaded Config Plugin: {0}", ConfigPlugin.ToString());
70    
71     //var UserControlPlugins = new List<IUserControlPlugin>(loader.LoadedUserControlPlugins);
72     //foreach (var userplugin in UserControlPlugins) { }
73    
74    
75 william 713 //var config_guids = loader.GetKnownPluginGuids<IConfigPlugin>();
76     //var input_guids = loader.GetKnownPluginGuids<IInputPlugin>();
77     //var window_guids = loader.GetKnownPluginGuids<IWindowPlugin>();
78     //var userplugin_guids = loader.GetKnownPluginGuids<IUserControlPlugin>();
79     //var plugin1 = loader.GetPluginByName<IUserControlPlugin>("ScratchPad Plugin");
80     //var plugin2 = loader.GetPluginByName<IUserControlPlugin>("RVA Calculator Plugin");
81 william 712
82    
83 william 713 //var plugin1 = PluginCollection.UserControlPlugins.CheatCodePlugin.Plugin;
84     //var plugin2 = PluginCollection.UserControlPlugins.EmuMMAPPlugin.Plugin;
85     //var plugin3 = PluginCollection.UserControlPlugins.RVACalculatorPlugin.Plugin;
86     //var plugin4 = PluginCollection.UserControlPlugins.ScratchPadPlugin.Plugin;
87    
88     //var plugin1 = PluginCollection.GetPluginByName(PluginNames.ScratchPadPlugin);
89     //var plugin2 = PluginCollection.GetPluginByName(PluginNames.RVACalculatorPlugin);
90    
91     var plugins = PluginCollection.GetPluginsByType(PluginType.Window);
92    
93 william 708 }
94    
95    
96    
97     #region Dock Support
98     //void AddDockToWindowList(object sender, EventArgs e)
99     //{
100     // DockContent dc;
101     // TypeBinder.Bind(sender, out dc);
102     // ToolStripMenuItem tsmi = new ToolStripMenuItem(dc.Text);
103     // tsmi.Name = dc.Name;
104     // tsmi.Tag = dc;
105     // tsmi.Click += new EventHandler(tsmi_Click);
106     // mnuWindows.DropDownItems.Add(tsmi);
107     //}
108     //void tsmi_Click(object sender, EventArgs e)
109     //{
110     // ToolStripMenuItem tsmi;
111     // TypeBinder.Bind(sender, out tsmi);
112     // DockContent dc;
113     // TypeBinder.Bind(tsmi.Tag, out dc);
114     // dc.Activate();
115     //}
116     //void RemoveDockFromWindowList(object sender, FormClosedEventArgs e)
117     //{
118     // DockContent dc;
119     // TypeBinder.Bind(sender, out dc);
120     // mnuWindows.DropDownItems.RemoveByKey(dc.Name);
121     //}
122     private IDockContent GetContentFromPersistString(string persistString)
123     {
124     if (persistString == typeof(FloatingLogWindow).ToString()) { return m_LogWindow; }
125     if (persistString == typeof(FloatingWebBrowser).ToString()) { return m_wb; }
126     else { return null; }
127     }
128     public void SetupDocks()
129     {
130     m_LogWindow = new FloatingLogWindow();
131     m_wb = new FloatingWebBrowser();
132     }
133     #region SetupDockWindowHandler support
134     public void SetupDockWindowHandler()
135     {
136     SetupLogWindowHandler();
137     SetupWebBrowserWindowHandler();
138     }
139     private void SetupLogWindowHandler()
140     {
141     if (m_LogWindow == null) return;
142     //m_LogWindow.Shown += new EventHandler(AddDockToWindowList);
143     //m_LogWindow.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
144 william 712 m_LogWindow.Activate();
145 william 708 }
146     private void SetupWebBrowserWindowHandler()
147     {
148     if (m_wb == null) return;
149     //m_wb.Shown += new EventHandler(AddDockToWindowList);
150     //m_wb.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
151 william 712 //m_wb.Activate();
152 william 708 }
153     #endregion
154     public void ShowDocks()
155     {
156     ShowLogWindow();
157     SetupLogWindowHandler();
158     ShowWebBrowser();
159     SetupWebBrowserWindowHandler();
160     }
161     public void ShowLogWindow()
162     {
163     if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); }
164     LoggerInstance = m_LogWindow.Logwriter;
165     LoggerInstance.CreateNewLog(false);
166 william 709 m_LogWindow.CloseButton = false;
167     m_LogWindow.CloseButtonVisible = false;
168 william 708 m_LogWindow.Show(dockPanel, DockState.DockBottom);
169     }
170    
171    
172     public void ShowWebBrowser()
173     {
174     //load_plugins_silent();
175     m_wb = new FloatingWebBrowser();
176 william 709 m_wb.CloseButton = false;
177     m_wb.CloseButtonVisible = false;
178 william 708 m_wb.Show(dockPanel);
179     }
180     #endregion
181    
182     private void Form1_FormClosing(object sender, FormClosingEventArgs e)
183     {
184     string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
185     if (m_bSaveLayout)
186     dockPanel.SaveAsXml(configFile);
187     else if (File.Exists(configFile))
188     File.Delete(configFile);
189     // notify any docked windows of formclosing
190     foreach (var t in this.dockPanel.Contents)
191     {
192     t.OnDeactivate<FormClosingEventArgs>(e);
193     }
194     }
195    
196     private void Form1_Shown(object sender, EventArgs e)
197     {
198     //dockPanel.SuspendLayout(true);
199     //ShowDocks();
200 william 712 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
201 william 708 if (File.Exists(configFile))
202     {
203     try
204     {
205     dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
206     SetupDockWindowHandler();
207     }
208     catch (Exception)
209     {
210     this.Controls.Remove(dockPanel);
211     dockPanel = new DockPanel();
212     dockPanel.Dock = DockStyle.Fill;
213     dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
214     this.Controls.Add(dockPanel);
215     ShowDocks();
216     }
217     }
218     else
219     {
220     ShowDocks();
221     }
222    
223     //dockPanel.ResumeLayout(true, true);
224     }
225 william 712
226     private void mnuItemExit_Click(object sender, EventArgs e)
227     {
228     this.Close();
229     }
230 william 707 }
231     }

  ViewVC Help
Powered by ViewVC 1.1.22