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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22