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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 728 - (hide annotations) (download)
Wed Jun 19 14:18:50 2013 UTC (7 years, 4 months ago) by william
File size: 10638 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 728 //private bool m_bSaveLayout = true;
22 william 712 PluginLoader loader = null;
23     IConfigPlugin ConfigPlugin = null;
24    
25     IUserControlPlugin RVACalcPlugin = null;
26 william 728 //IUserControlPlugin ScratchPadPlugin = null;
27 william 712
28 william 728 //private DeserializeDockContent m_deserializeDockContent;
29     //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 728 //// 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 728 //var scratchpad = PluginCollection.GetPluginByName(PluginNames.ScratchPadPlugin);
92     var rvacalc = PluginCollection.GetPluginByName(PluginNames.RVACalculatorPlugin);
93     //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 728 //ScratchPadPlugin.SetAcceptedConfig(ConfigPlugin);
98 william 726 RVACalcPlugin.SetAcceptedConfig(ConfigPlugin);
99 william 708 }
100    
101    
102    
103     #region Dock Support
104 william 728 //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 728 //m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
123 william 708 }
124     #region SetupDockWindowHandler support
125     public void SetupDockWindowHandler()
126     {
127 william 728 //SetupLogWindowHandler();
128     //SetupWebBrowserWindowHandler();
129 william 716 SetupPluginWindowHandlers();
130 william 708 }
131 william 716 private void SetupPluginWindowHandlers()
132     {
133 william 717 if (RVACalcPlugin != null)
134     {
135     RVACalcPlugin.Activate();
136     }
137 william 728 //if (ScratchPadPlugin != null)
138     //{
139     // ScratchPadPlugin.Activate();
140     //}
141 william 716 }
142 william 728 //private void SetupLogWindowHandler()
143     //{
144     // //if (m_LogWindow == null) return;
145     // ////m_LogWindow.Shown += new EventHandler(AddDockToWindowList);
146     // ////m_LogWindow.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
147     // //m_LogWindow.Activate();
148     //}
149     //private void SetupWebBrowserWindowHandler()
150     //{
151     // //if (m_wb == null) return;
152     // ////m_wb.Shown += new EventHandler(AddDockToWindowList);
153     // ////m_wb.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
154     // //m_wb.Activate();
155     //}
156 william 708 #endregion
157     public void ShowDocks()
158     {
159 william 728 //ShowLogWindow();
160     //SetupLogWindowHandler();
161     //ShowWebBrowser();
162     //SetupWebBrowserWindowHandler();
163 william 716 ShowPluginWindows();
164     SetupPluginWindowHandlers();
165 william 722
166 william 728 //if (RVACalcPlugin != null)
167     // RVACalcPlugin.Activate();
168 william 708 }
169     public void ShowLogWindow()
170     {
171 william 728 //if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); }
172     //if (LoggerInstance == null)
173     //{
174     // LoggerInstance = m_LogWindow.Logwriter;
175     // LoggerInstance.CreateNewLog(false);
176     //}
177     ////m_LogWindow.AllowEndUserDocking = true;
178     ////m_LogWindow.CloseButton = false;
179     ////m_LogWindow.CloseButtonVisible = false;
180     //m_LogWindow.Show(dockPanel, DockState.DockBottom);
181 william 708 }
182    
183    
184     public void ShowWebBrowser()
185     {
186 william 728 ////load_plugins_silent();
187     //m_wb = new FloatingWebBrowser();
188     ////m_wb.AllowEndUserDocking = true;
189     ////m_wb.CloseButton = false;
190     ////m_wb.CloseButtonVisible = false;
191     //m_wb.Show(dockPanel, DockState.Document);
192 william 708 }
193 william 716 public void ShowPluginWindows()
194     {
195 william 727 if (RVACalcPlugin != null)
196     {
197     // RVA Calc
198 william 728 RVACalcPlugin.DockHandler.CloseButton = false;
199     RVACalcPlugin.DockHandler.CloseButtonVisible = false;
200     RVACalcPlugin.DockHandler.AllowEndUserDocking = false;
201 william 727 RVACalcPlugin.Show(dockPanel);
202     }
203 william 728 //if (ScratchPadPlugin != null)
204     //{
205     // // ScratchPad
206     // //ScratchPadPlugin.DockHandler.CloseButton = false;
207     // //ScratchPadPlugin.DockHandler.CloseButtonVisible = false;
208     // //ScratchPadPlugin.DockHandler.AllowEndUserDocking = true;
209     // ScratchPadPlugin.Show(dockPanel, DockState.Document);
210     //}
211 william 716 }
212 william 708 #endregion
213    
214     private void Form1_FormClosing(object sender, FormClosingEventArgs e)
215     {
216 william 722 SettingsSubscriber.SaveSettings();
217 william 728 //string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
218     //if (m_bSaveLayout)
219     // dockPanel.SaveAsXml(configFile);
220     //else if (File.Exists(configFile))
221     // File.Delete(configFile);
222 william 708 // notify any docked windows of formclosing
223     foreach (var t in this.dockPanel.Contents)
224     {
225     t.OnDeactivate<FormClosingEventArgs>(e);
226     }
227     }
228    
229     private void Form1_Shown(object sender, EventArgs e)
230     {
231 william 728 ////dockPanel.SuspendLayout(true);
232     ////ShowDocks();
233     //string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
234     //if (File.Exists(configFile))
235     //{
236     // try
237     // {
238     // dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
239     // SetupDockWindowHandler();
240     // }
241     // catch (Exception)
242     // {
243     // this.Controls.Remove(dockPanel);
244     // dockPanel = new DockPanel();
245     // dockPanel.Dock = DockStyle.Fill;
246     // dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
247     // this.Controls.Add(dockPanel);
248     // ShowDocks();
249     // }
250     //}
251     //else
252     //{
253     ShowDocks();
254     //}
255 william 708
256 william 728 //if (RVACalcPlugin != null)
257     // RVACalcPlugin.Activate();
258     ////dockPanel.ResumeLayout(true, true);
259 william 708 }
260 william 712
261     private void mnuItemExit_Click(object sender, EventArgs e)
262     {
263     this.Close();
264     }
265 william 719
266 william 725 private void Form1_Load(object sender, EventArgs e) { }
267 william 707 }
268     }

  ViewVC Help
Powered by ViewVC 1.1.22