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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22