ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.RVAScratchPad/Form1.cs
Revision: 708
Committed: Tue Jun 18 07:23:04 2013 UTC (9 years, 11 months ago) by william
File size: 6628 byte(s)
Log Message:

File Contents

# Content
1 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 using RomCheater.Logging;
9 using RomCheater.Docking;
10 using WeifenLuo.WinFormsUI.Docking;
11 using System.IO;
12
13 namespace RomCheater.RVAScratchPad
14 {
15 public partial class Form1 : Form
16 {
17 private bool m_bSaveLayout = true;
18 private DeserializeDockContent m_deserializeDockContent;
19 private FloatingLogWindow m_LogWindow = new FloatingLogWindow();
20 private FloatingWebBrowser m_wb = new FloatingWebBrowser();
21
22 #region LogWriterSupport
23 static LogWriter _LoggerInstance;
24 static LogWriter LoggerInstance
25 {
26 get { return _LoggerInstance; }
27 set { _LoggerInstance = value; }
28 }
29 #endregion
30
31 public Form1() : this(false) { }
32 public Form1(bool no_console_redirect)
33 {
34 InitializeComponent();
35 load_loggerflags();
36 //SetupDocks();
37 LoggerInstance = m_LogWindow.Logwriter;
38 LoggerInstance.CreateNewLog(false);
39 logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
40 load_plugins();
41 if (no_console_redirect)
42 LoggerInstance.RedirectConsoleOutput = false;
43 }
44 private void load_loggerflags()
45 {
46 logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags);
47 #if FORCE_ALL_LOGGING_FLAGS
48 logger.SetLoggingFlags(loggerflags.ALL);
49 #endif
50 }
51 private void load_plugins() { load_plugins(false); }
52 private void load_plugins_silent() { load_plugins(true); }
53 private void load_plugins(bool silent)
54 {
55 }
56
57
58
59 #region Dock Support
60 //void AddDockToWindowList(object sender, EventArgs e)
61 //{
62 // DockContent dc;
63 // TypeBinder.Bind(sender, out dc);
64 // ToolStripMenuItem tsmi = new ToolStripMenuItem(dc.Text);
65 // tsmi.Name = dc.Name;
66 // tsmi.Tag = dc;
67 // tsmi.Click += new EventHandler(tsmi_Click);
68 // mnuWindows.DropDownItems.Add(tsmi);
69 //}
70 //void tsmi_Click(object sender, EventArgs e)
71 //{
72 // ToolStripMenuItem tsmi;
73 // TypeBinder.Bind(sender, out tsmi);
74 // DockContent dc;
75 // TypeBinder.Bind(tsmi.Tag, out dc);
76 // dc.Activate();
77 //}
78 //void RemoveDockFromWindowList(object sender, FormClosedEventArgs e)
79 //{
80 // DockContent dc;
81 // TypeBinder.Bind(sender, out dc);
82 // mnuWindows.DropDownItems.RemoveByKey(dc.Name);
83 //}
84 private IDockContent GetContentFromPersistString(string persistString)
85 {
86 if (persistString == typeof(FloatingLogWindow).ToString()) { return m_LogWindow; }
87 if (persistString == typeof(FloatingWebBrowser).ToString()) { return m_wb; }
88 else { return null; }
89 }
90 public void SetupDocks()
91 {
92 m_LogWindow = new FloatingLogWindow();
93 m_wb = new FloatingWebBrowser();
94 }
95 #region SetupDockWindowHandler support
96 public void SetupDockWindowHandler()
97 {
98 SetupLogWindowHandler();
99 SetupWebBrowserWindowHandler();
100 }
101 private void SetupLogWindowHandler()
102 {
103 if (m_LogWindow == null) return;
104 //m_LogWindow.Shown += new EventHandler(AddDockToWindowList);
105 //m_LogWindow.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
106 //m_LogWindow.Activate();
107 }
108 private void SetupWebBrowserWindowHandler()
109 {
110 if (m_wb == null) return;
111 //m_wb.Shown += new EventHandler(AddDockToWindowList);
112 //m_wb.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
113 //m_msv.Activate();
114 }
115 #endregion
116 public void ShowDocks()
117 {
118 ShowLogWindow();
119 SetupLogWindowHandler();
120 ShowWebBrowser();
121 SetupWebBrowserWindowHandler();
122 }
123 public void ShowLogWindow()
124 {
125 if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); }
126 LoggerInstance = m_LogWindow.Logwriter;
127 LoggerInstance.CreateNewLog(false);
128 m_LogWindow.Show(dockPanel, DockState.DockBottom);
129 }
130
131
132 public void ShowWebBrowser()
133 {
134 //load_plugins_silent();
135 m_wb = new FloatingWebBrowser();
136 m_wb.Show(dockPanel);
137 }
138 #endregion
139
140 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
141 {
142 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
143 if (m_bSaveLayout)
144 dockPanel.SaveAsXml(configFile);
145 else if (File.Exists(configFile))
146 File.Delete(configFile);
147 // notify any docked windows of formclosing
148 foreach (var t in this.dockPanel.Contents)
149 {
150 t.OnDeactivate<FormClosingEventArgs>(e);
151 }
152 }
153
154 private void Form1_Shown(object sender, EventArgs e)
155 {
156 //dockPanel.SuspendLayout(true);
157 //ShowDocks();
158 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
159 if (File.Exists(configFile))
160 {
161 try
162 {
163 dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
164 SetupDockWindowHandler();
165 }
166 catch (Exception)
167 {
168 this.Controls.Remove(dockPanel);
169 dockPanel = new DockPanel();
170 dockPanel.Dock = DockStyle.Fill;
171 dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
172 this.Controls.Add(dockPanel);
173 ShowDocks();
174 }
175 }
176 else
177 {
178 ShowDocks();
179 }
180
181 //dockPanel.ResumeLayout(true, true);
182 }
183 }
184 }