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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22