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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22