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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 755 - (hide annotations) (download)
Thu Jun 20 20:04:53 2013 UTC (8 years ago) by william
File size: 11572 byte(s)
* rename DockPanel config files
* use a constant string to set the config filename (so we can update/maintain in one location)

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

  ViewVC Help
Powered by ViewVC 1.1.22