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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 709 - (show annotations) (download)
Tue Jun 18 07:24:44 2013 UTC (7 years, 3 months ago) by william
File size: 6812 byte(s)

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.CloseButton = false;
129 m_LogWindow.CloseButtonVisible = false;
130 m_LogWindow.Show(dockPanel, DockState.DockBottom);
131 }
132
133
134 public void ShowWebBrowser()
135 {
136 //load_plugins_silent();
137 m_wb = new FloatingWebBrowser();
138 m_wb.CloseButton = false;
139 m_wb.CloseButtonVisible = false;
140 m_wb.Show(dockPanel);
141 }
142 #endregion
143
144 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
145 {
146 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RVAScratchPad-DockPanel.config");
147 if (m_bSaveLayout)
148 dockPanel.SaveAsXml(configFile);
149 else if (File.Exists(configFile))
150 File.Delete(configFile);
151 // notify any docked windows of formclosing
152 foreach (var t in this.dockPanel.Contents)
153 {
154 t.OnDeactivate<FormClosingEventArgs>(e);
155 }
156 }
157
158 private void Form1_Shown(object sender, EventArgs e)
159 {
160 //dockPanel.SuspendLayout(true);
161 //ShowDocks();
162 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
163 if (File.Exists(configFile))
164 {
165 try
166 {
167 dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
168 SetupDockWindowHandler();
169 }
170 catch (Exception)
171 {
172 this.Controls.Remove(dockPanel);
173 dockPanel = new DockPanel();
174 dockPanel.Dock = DockStyle.Fill;
175 dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
176 this.Controls.Add(dockPanel);
177 ShowDocks();
178 }
179 }
180 else
181 {
182 ShowDocks();
183 }
184
185 //dockPanel.ResumeLayout(true, true);
186 }
187 }
188 }

  ViewVC Help
Powered by ViewVC 1.1.22