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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22