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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 727 - (hide annotations) (download)
Wed Jun 19 01:37:36 2013 UTC (7 years, 4 months ago) by william
File size: 10388 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 william 726 public IWebBrowserProvider WebBrowserProvider
33     {
34     get { return new WebBrowserProvider(m_wb); }
35     }
36 william 708 #region LogWriterSupport
37     static LogWriter _LoggerInstance;
38     static LogWriter LoggerInstance
39 william 707 {
40 william 708 get { return _LoggerInstance; }
41     set { _LoggerInstance = value; }
42     }
43     #endregion
44    
45     public Form1() : this(false) { }
46     public Form1(bool no_console_redirect)
47     {
48 william 707 InitializeComponent();
49 william 722 SettingsSubscriber = new SettingSubscriber();
50     SettingsSubscriber.AddSubscriber(this, RomCheater.Properties.Settings.Default);
51 william 708 load_loggerflags();
52 william 717 SetupDocks();
53 william 708 LoggerInstance = m_LogWindow.Logwriter;
54     LoggerInstance.CreateNewLog(false);
55     logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
56     load_plugins();
57     if (no_console_redirect)
58     LoggerInstance.RedirectConsoleOutput = false;
59 william 707 }
60 william 708 private void load_loggerflags()
61     {
62     logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags);
63     #if FORCE_ALL_LOGGING_FLAGS
64     logger.SetLoggingFlags(loggerflags.ALL);
65     #endif
66     }
67     private void load_plugins() { load_plugins(false); }
68     private void load_plugins_silent() { load_plugins(true); }
69     private void load_plugins(bool silent)
70     {
71 william 712 loader = new PluginLoader();
72     loader.LoadPlugins(silent);
73 william 722
74     var LastConfigPlugin = SettingsSubscriber.GetValue("LastConfigPlugin").ToString();
75     if (LastConfigPlugin != null)
76     {
77     ConfigPlugin = loader.GetConfigPlugin(LastConfigPlugin.ToString());
78     }
79     else
80     {
81     var config = PluginCollection.GetPluginByName(PluginNames.GenericConfig);
82     ConfigPlugin = loader.GetPluginByGuid<IConfigPlugin>(config.ID.ToString());
83 william 724 }
84    
85 william 726 // update the Config plugin's reference to the webbrowswer
86     ConfigPlugin.WebBrowserProvider = this.WebBrowserProvider;
87    
88 william 724 SettingsSubscriber.SetValue("LastConfigPlugin", ConfigPlugin.ToString());
89    
90 william 715 var scratchpad = PluginCollection.GetPluginByName(PluginNames.ScratchPadPlugin);
91 william 722 var rvacalc = PluginCollection.GetPluginByName(PluginNames.RVACalculatorPlugin);
92 william 715 ScratchPadPlugin = loader.GetPluginByGuid<IUserControlPlugin>(scratchpad.ID.ToString());
93     RVACalcPlugin = loader.GetPluginByGuid<IUserControlPlugin>(rvacalc.ID.ToString());
94 william 726
95     // update config of each plugin
96     ScratchPadPlugin.SetAcceptedConfig(ConfigPlugin);
97     RVACalcPlugin.SetAcceptedConfig(ConfigPlugin);
98 william 708 }
99    
100    
101    
102     #region Dock Support
103     private IDockContent GetContentFromPersistString(string persistString)
104     {
105     if (persistString == typeof(FloatingLogWindow).ToString()) { return m_LogWindow; }
106     if (persistString == typeof(FloatingWebBrowser).ToString()) { return m_wb; }
107 william 717 if (RVACalcPlugin != null) { if (persistString == RVACalcPlugin.IDockContentTypeName) { return RVACalcPlugin.DockContent; } }
108     if (ScratchPadPlugin != null) { if (persistString == ScratchPadPlugin.IDockContentTypeName) { return ScratchPadPlugin.DockContent; } }
109     return null;
110 william 708 }
111     public void SetupDocks()
112     {
113     m_LogWindow = new FloatingLogWindow();
114 william 727 //m_LogWindow.CloseButton = false;
115     //m_LogWindow.CloseButtonVisible = false;
116 william 717
117 william 708 m_wb = new FloatingWebBrowser();
118 william 727 //m_wb.CloseButton = false;
119     //m_wb.CloseButtonVisible = false;
120 william 717
121 william 716 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
122 william 708 }
123     #region SetupDockWindowHandler support
124     public void SetupDockWindowHandler()
125     {
126     SetupLogWindowHandler();
127     SetupWebBrowserWindowHandler();
128 william 716 SetupPluginWindowHandlers();
129 william 708 }
130 william 716 private void SetupPluginWindowHandlers()
131     {
132 william 717 if (RVACalcPlugin != null)
133     {
134     RVACalcPlugin.Activate();
135     }
136     if (ScratchPadPlugin != null)
137     {
138     ScratchPadPlugin.Activate();
139     }
140 william 716 }
141 william 708 private void SetupLogWindowHandler()
142     {
143     if (m_LogWindow == null) return;
144     //m_LogWindow.Shown += new EventHandler(AddDockToWindowList);
145     //m_LogWindow.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
146 william 712 m_LogWindow.Activate();
147 william 708 }
148     private void SetupWebBrowserWindowHandler()
149     {
150     if (m_wb == null) return;
151     //m_wb.Shown += new EventHandler(AddDockToWindowList);
152     //m_wb.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
153 william 716 m_wb.Activate();
154 william 708 }
155     #endregion
156     public void ShowDocks()
157     {
158     ShowLogWindow();
159     SetupLogWindowHandler();
160     ShowWebBrowser();
161     SetupWebBrowserWindowHandler();
162 william 716 ShowPluginWindows();
163     SetupPluginWindowHandlers();
164 william 722
165     if (RVACalcPlugin != null)
166     RVACalcPlugin.Activate();
167 william 708 }
168     public void ShowLogWindow()
169     {
170     if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); }
171 william 727 if (LoggerInstance == null)
172     {
173     LoggerInstance = m_LogWindow.Logwriter;
174     LoggerInstance.CreateNewLog(false);
175     }
176     //m_LogWindow.AllowEndUserDocking = true;
177     //m_LogWindow.CloseButton = false;
178     //m_LogWindow.CloseButtonVisible = false;
179 william 708 m_LogWindow.Show(dockPanel, DockState.DockBottom);
180     }
181    
182    
183     public void ShowWebBrowser()
184     {
185     //load_plugins_silent();
186     m_wb = new FloatingWebBrowser();
187 william 727 //m_wb.AllowEndUserDocking = true;
188     //m_wb.CloseButton = false;
189     //m_wb.CloseButtonVisible = false;
190     m_wb.Show(dockPanel, DockState.Document);
191 william 708 }
192 william 716 public void ShowPluginWindows()
193     {
194 william 727 if (RVACalcPlugin != null)
195     {
196     // RVA Calc
197     //RVACalcPlugin.DockHandler.CloseButton = false;
198     //RVACalcPlugin.DockHandler.CloseButtonVisible = false;
199     //RVACalcPlugin.DockHandler.AllowEndUserDocking = true;
200     RVACalcPlugin.Show(dockPanel);
201     }
202     if (ScratchPadPlugin != null)
203     {
204     // ScratchPad
205     //ScratchPadPlugin.DockHandler.CloseButton = false;
206     //ScratchPadPlugin.DockHandler.CloseButtonVisible = false;
207     //ScratchPadPlugin.DockHandler.AllowEndUserDocking = true;
208     ScratchPadPlugin.Show(dockPanel, DockState.Document);
209     }
210 william 716 }
211 william 708 #endregion
212    
213     private void Form1_FormClosing(object sender, FormClosingEventArgs e)
214     {
215 william 722 SettingsSubscriber.SaveSettings();
216 william 708 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
217     if (m_bSaveLayout)
218     dockPanel.SaveAsXml(configFile);
219     else if (File.Exists(configFile))
220     File.Delete(configFile);
221     // notify any docked windows of formclosing
222     foreach (var t in this.dockPanel.Contents)
223     {
224     t.OnDeactivate<FormClosingEventArgs>(e);
225     }
226     }
227    
228     private void Form1_Shown(object sender, EventArgs e)
229     {
230     //dockPanel.SuspendLayout(true);
231     //ShowDocks();
232 william 712 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
233 william 708 if (File.Exists(configFile))
234     {
235     try
236     {
237     dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
238     SetupDockWindowHandler();
239     }
240     catch (Exception)
241     {
242     this.Controls.Remove(dockPanel);
243     dockPanel = new DockPanel();
244     dockPanel.Dock = DockStyle.Fill;
245     dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
246     this.Controls.Add(dockPanel);
247     ShowDocks();
248     }
249     }
250     else
251     {
252     ShowDocks();
253     }
254    
255 william 722 if (RVACalcPlugin != null)
256     RVACalcPlugin.Activate();
257 william 708 //dockPanel.ResumeLayout(true, true);
258     }
259 william 712
260     private void mnuItemExit_Click(object sender, EventArgs e)
261     {
262     this.Close();
263     }
264 william 719
265 william 725 private void Form1_Load(object sender, EventArgs e) { }
266 william 707 }
267     }

  ViewVC Help
Powered by ViewVC 1.1.22