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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 838 - (hide annotations) (download)
Tue Sep 16 00:57:18 2014 UTC (6 years, 9 months ago) by william
File size: 11659 byte(s)
+ add an icon resource

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

  ViewVC Help
Powered by ViewVC 1.1.22