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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 716 - (hide annotations) (download)
Tue Jun 18 10:59:36 2013 UTC (7 years, 4 months ago) by william
File size: 8503 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 william 715 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 william 708 }
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 william 716 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
111 william 708 }
112     #region SetupDockWindowHandler support
113     public void SetupDockWindowHandler()
114     {
115     SetupLogWindowHandler();
116     SetupWebBrowserWindowHandler();
117 william 716 SetupPluginWindowHandlers();
118 william 708 }
119 william 716 private void SetupPluginWindowHandlers()
120     {
121     //if (RVACalcPlugin != null)
122     //{
123    
124     //}
125     //if (ScratchPadPlugin != null)
126     //{
127     //}
128     }
129 william 708 private void SetupLogWindowHandler()
130     {
131     if (m_LogWindow == null) return;
132     //m_LogWindow.Shown += new EventHandler(AddDockToWindowList);
133     //m_LogWindow.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
134 william 712 m_LogWindow.Activate();
135 william 708 }
136     private void SetupWebBrowserWindowHandler()
137     {
138     if (m_wb == null) return;
139     //m_wb.Shown += new EventHandler(AddDockToWindowList);
140     //m_wb.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
141 william 716 m_wb.Activate();
142 william 708 }
143     #endregion
144     public void ShowDocks()
145     {
146     ShowLogWindow();
147     SetupLogWindowHandler();
148     ShowWebBrowser();
149     SetupWebBrowserWindowHandler();
150 william 716 ShowPluginWindows();
151     SetupPluginWindowHandlers();
152 william 708 }
153     public void ShowLogWindow()
154     {
155     if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); }
156     LoggerInstance = m_LogWindow.Logwriter;
157     LoggerInstance.CreateNewLog(false);
158 william 709 m_LogWindow.CloseButton = false;
159     m_LogWindow.CloseButtonVisible = false;
160 william 708 m_LogWindow.Show(dockPanel, DockState.DockBottom);
161     }
162    
163    
164     public void ShowWebBrowser()
165     {
166     //load_plugins_silent();
167     m_wb = new FloatingWebBrowser();
168 william 709 m_wb.CloseButton = false;
169     m_wb.CloseButtonVisible = false;
170 william 708 m_wb.Show(dockPanel);
171     }
172 william 716 public void ShowPluginWindows()
173     {
174     // RVA Calc
175     RVACalcPlugin.Show(dockPanel);
176     // ScratchPad
177     ScratchPadPlugin.Show(dockPanel);
178     }
179 william 708 #endregion
180    
181     private void Form1_FormClosing(object sender, FormClosingEventArgs e)
182     {
183     string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
184     if (m_bSaveLayout)
185     dockPanel.SaveAsXml(configFile);
186     else if (File.Exists(configFile))
187     File.Delete(configFile);
188     // notify any docked windows of formclosing
189     foreach (var t in this.dockPanel.Contents)
190     {
191     t.OnDeactivate<FormClosingEventArgs>(e);
192     }
193     }
194    
195     private void Form1_Shown(object sender, EventArgs e)
196     {
197     //dockPanel.SuspendLayout(true);
198     //ShowDocks();
199 william 712 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
200 william 708 if (File.Exists(configFile))
201     {
202     try
203     {
204     dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
205     SetupDockWindowHandler();
206     }
207     catch (Exception)
208     {
209     this.Controls.Remove(dockPanel);
210     dockPanel = new DockPanel();
211     dockPanel.Dock = DockStyle.Fill;
212     dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
213     this.Controls.Add(dockPanel);
214     ShowDocks();
215     }
216     }
217     else
218     {
219     ShowDocks();
220     }
221    
222     //dockPanel.ResumeLayout(true, true);
223     }
224 william 712
225     private void mnuItemExit_Click(object sender, EventArgs e)
226     {
227     this.Close();
228     }
229 william 707 }
230     }

  ViewVC Help
Powered by ViewVC 1.1.22