Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
comparison FrmDebugOutput.cs @ 0:7dd160dacb60
Initial commit of WarFoundry code
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 19 Dec 2008 15:57:51 +0000 |
parents | |
children | 8935971e307c |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7dd160dacb60 |
---|---|
1 using System; | |
2 using System.Drawing; | |
3 using System.Collections; | |
4 using System.ComponentModel; | |
5 using System.Text; | |
6 using System.Windows.Forms; | |
7 using IBBoard.Lang; | |
8 using IBBoard.Logging; | |
9 using IBBoard.Windows.Forms; | |
10 | |
11 namespace IBBoard.WarFoundry | |
12 { | |
13 /// <summary> | |
14 /// Summary description for FrmDebugOutput. | |
15 /// </summary> | |
16 public class FrmDebugOutput : IBBForm | |
17 { | |
18 private System.Windows.Forms.ListBox lstDebugItems; | |
19 private System.Windows.Forms.ComboBox cmbDebugLevel; | |
20 private System.Windows.Forms.Label lblDebugLevel; | |
21 /// <summary> | |
22 /// Required designer variable. | |
23 /// </summary> | |
24 private System.ComponentModel.Container components = null; | |
25 private Logger logger; | |
26 private System.Windows.Forms.ContextMenu contextMenu; | |
27 private System.Windows.Forms.MenuItem miCopy; | |
28 private System.Windows.Forms.TextBox txtDetail; | |
29 private System.Windows.Forms.Splitter splitter1; | |
30 private System.Windows.Forms.Panel panel1; | |
31 private int MAX_LIST_LENGTH = 50; | |
32 | |
33 public FrmDebugOutput() | |
34 { | |
35 //this.logger = logger; | |
36 //logger.LogUpdatedEvent+=new IBBoard.Logging.Logger.LogUpdatedDelegate(logger_LogUpdatedEvent); | |
37 // | |
38 // Required for Windows Form Designer support | |
39 // | |
40 InitializeComponent(); | |
41 | |
42 /*if (LogLevels.Debug >= logger.LogLevel) | |
43 { | |
44 cmbDebugLevel.Items.Add(LogLevels.Debug); | |
45 } | |
46 | |
47 if (LogLevels.Info >= logger.LogLevel) | |
48 { | |
49 cmbDebugLevel.Items.Add(LogLevels.Info); | |
50 } | |
51 | |
52 if (LogLevels.Warning >= logger.LogLevel) | |
53 { | |
54 cmbDebugLevel.Items.Add(LogLevels.Warning); | |
55 } | |
56 | |
57 if (LogLevels.Error >= logger.LogLevel) | |
58 { | |
59 cmbDebugLevel.Items.Add(LogLevels.Error); | |
60 } | |
61 | |
62 if (LogLevels.Critical >= logger.LogLevel) | |
63 { | |
64 cmbDebugLevel.Items.Add(LogLevels.Critical); | |
65 }*/ | |
66 | |
67 this.Name = "DebugOutputForm"; | |
68 | |
69 cmbDebugLevel.SelectedItem = logger.LogLevel; | |
70 | |
71 Translation.Translate(this, true); | |
72 | |
73 fillDebugList(); | |
74 } | |
75 | |
76 /// <summary> | |
77 /// Clean up any resources being used. | |
78 /// </summary> | |
79 protected override void Dispose( bool disposing ) | |
80 { | |
81 if( disposing ) | |
82 { | |
83 if(components != null) | |
84 { | |
85 components.Dispose(); | |
86 } | |
87 } | |
88 base.Dispose( disposing ); | |
89 } | |
90 | |
91 #region Windows Form Designer generated code | |
92 /// <summary> | |
93 /// Required method for Designer support - do not modify | |
94 /// the contents of this method with the code editor. | |
95 /// </summary> | |
96 private void InitializeComponent() | |
97 { | |
98 this.lstDebugItems = new System.Windows.Forms.ListBox(); | |
99 this.contextMenu = new System.Windows.Forms.ContextMenu(); | |
100 this.miCopy = new System.Windows.Forms.MenuItem(); | |
101 this.cmbDebugLevel = new System.Windows.Forms.ComboBox(); | |
102 this.lblDebugLevel = new System.Windows.Forms.Label(); | |
103 this.txtDetail = new System.Windows.Forms.TextBox(); | |
104 this.splitter1 = new System.Windows.Forms.Splitter(); | |
105 this.panel1 = new System.Windows.Forms.Panel(); | |
106 this.SuspendLayout(); | |
107 // | |
108 // lstDebugItems | |
109 // | |
110 this.lstDebugItems.ContextMenu = this.contextMenu; | |
111 this.lstDebugItems.Dock = System.Windows.Forms.DockStyle.Fill; | |
112 this.lstDebugItems.IntegralHeight = false; | |
113 this.lstDebugItems.Location = new System.Drawing.Point(0, 24); | |
114 this.lstDebugItems.Name = "lstDebugItems"; | |
115 this.lstDebugItems.ScrollAlwaysVisible = true; | |
116 this.lstDebugItems.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended; | |
117 this.lstDebugItems.Size = new System.Drawing.Size(656, 144); | |
118 this.lstDebugItems.TabIndex = 0; | |
119 this.lstDebugItems.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lstDebugItems_MouseDown); | |
120 this.lstDebugItems.SelectedIndexChanged += new System.EventHandler(this.lstDebugItems_SelectedIndexChanged); | |
121 // | |
122 // contextMenu | |
123 // | |
124 this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { | |
125 this.miCopy}); | |
126 this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup); | |
127 // | |
128 // miCopy | |
129 // | |
130 this.miCopy.Index = 0; | |
131 this.miCopy.Text = "&Copy"; | |
132 this.miCopy.Click += new System.EventHandler(this.miCopy_Click); | |
133 // | |
134 // cmbDebugLevel | |
135 // | |
136 this.cmbDebugLevel.Location = new System.Drawing.Point(190, 2); | |
137 this.cmbDebugLevel.Name = "cmbDebugLevel"; | |
138 this.cmbDebugLevel.Size = new System.Drawing.Size(464, 21); | |
139 this.cmbDebugLevel.TabIndex = 1; | |
140 this.cmbDebugLevel.SelectedIndexChanged += new System.EventHandler(this.cmbDebugLevel_SelectedIndexChanged); | |
141 // | |
142 // lblDebugLevel | |
143 // | |
144 this.lblDebugLevel.Location = new System.Drawing.Point(16, 0); | |
145 this.lblDebugLevel.Name = "lblDebugLevel"; | |
146 this.lblDebugLevel.Size = new System.Drawing.Size(168, 21); | |
147 this.lblDebugLevel.TabIndex = 2; | |
148 this.lblDebugLevel.Text = "debug level:"; | |
149 this.lblDebugLevel.TextAlign = System.Drawing.ContentAlignment.MiddleRight; | |
150 // | |
151 // txtDetail | |
152 // | |
153 this.txtDetail.Dock = System.Windows.Forms.DockStyle.Bottom; | |
154 this.txtDetail.Location = new System.Drawing.Point(0, 172); | |
155 this.txtDetail.Multiline = true; | |
156 this.txtDetail.Name = "txtDetail"; | |
157 this.txtDetail.ReadOnly = true; | |
158 this.txtDetail.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; | |
159 this.txtDetail.Size = new System.Drawing.Size(656, 64); | |
160 this.txtDetail.TabIndex = 3; | |
161 this.txtDetail.TabStop = false; | |
162 this.txtDetail.Text = ""; | |
163 this.txtDetail.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtDetail_KeyDown); | |
164 // | |
165 // splitter1 | |
166 // | |
167 this.splitter1.Cursor = System.Windows.Forms.Cursors.HSplit; | |
168 this.splitter1.Dock = System.Windows.Forms.DockStyle.Bottom; | |
169 this.splitter1.Location = new System.Drawing.Point(0, 168); | |
170 this.splitter1.MinExtra = 50; | |
171 this.splitter1.MinSize = 50; | |
172 this.splitter1.Name = "splitter1"; | |
173 this.splitter1.Size = new System.Drawing.Size(656, 4); | |
174 this.splitter1.TabIndex = 4; | |
175 this.splitter1.TabStop = false; | |
176 // | |
177 // panel1 | |
178 // | |
179 this.panel1.Dock = System.Windows.Forms.DockStyle.Top; | |
180 this.panel1.Location = new System.Drawing.Point(0, 0); | |
181 this.panel1.Name = "panel1"; | |
182 this.panel1.Size = new System.Drawing.Size(656, 24); | |
183 this.panel1.TabIndex = 5; | |
184 // | |
185 // FrmDebugOutput | |
186 // | |
187 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); | |
188 this.ClientSize = new System.Drawing.Size(656, 236); | |
189 this.Controls.Add(this.lblDebugLevel); | |
190 this.Controls.Add(this.cmbDebugLevel); | |
191 this.Controls.Add(this.lstDebugItems); | |
192 this.Controls.Add(this.splitter1); | |
193 this.Controls.Add(this.panel1); | |
194 this.Controls.Add(this.txtDetail); | |
195 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; | |
196 this.Name = "FrmDebugOutput"; | |
197 this.ShowInTaskbar = false; | |
198 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; | |
199 this.Text = "FrmDebugOutput"; | |
200 this.ResumeLayout(false); | |
201 | |
202 } | |
203 #endregion | |
204 | |
205 private void cmbDebugLevel_SelectedIndexChanged(object sender, System.EventArgs e) | |
206 { | |
207 fillDebugList(); | |
208 } | |
209 | |
210 private void fillDebugList() | |
211 { | |
212 lstDebugItems.Items.Clear(); | |
213 /*LogItem[] items = logger.GetLogItems((LogLevels)cmbDebugLevel.SelectedItem); | |
214 int last = items.Length - 1; | |
215 int stop = last - MAX_LIST_LENGTH; | |
216 | |
217 if (stop < 0) | |
218 { | |
219 stop = 0; | |
220 } | |
221 | |
222 //reverse fill the list so that we can have newest items at the top | |
223 for (int i = last; i >= stop; i--) | |
224 { | |
225 lstDebugItems.Items.Add(items[i]); | |
226 }*/ | |
227 } | |
228 | |
229 private void logger_LogUpdatedEvent(LogItem item) | |
230 { | |
231 /*if (item.Level >= (LogLevels)cmbDebugLevel.SelectedItem) | |
232 { | |
233 lock (lstDebugItems) | |
234 { | |
235 lstDebugItems.Items.Insert(0, item); | |
236 | |
237 if (lstDebugItems.Items.Count > MAX_LIST_LENGTH) | |
238 { | |
239 lstDebugItems.Items.RemoveAt(lstDebugItems.Items.Count - 1); | |
240 } | |
241 } | |
242 }*/ | |
243 } | |
244 | |
245 private void miCopy_Click(object sender, System.EventArgs e) | |
246 { | |
247 if (lstDebugItems.SelectedIndices.Count==1) | |
248 { | |
249 Clipboard.SetDataObject(lstDebugItems.SelectedItem.ToString()); | |
250 } | |
251 else if (lstDebugItems.SelectedIndices.Count > 1) | |
252 { | |
253 StringBuilder sb = new StringBuilder(); | |
254 | |
255 foreach (int idx in lstDebugItems.SelectedIndices) | |
256 { | |
257 sb.Append(lstDebugItems.Items[idx].ToString()+Environment.NewLine); | |
258 } | |
259 | |
260 Clipboard.SetDataObject(sb.ToString().Trim()); | |
261 } | |
262 } | |
263 | |
264 private void contextMenu_Popup(object sender, System.EventArgs e) | |
265 { | |
266 foreach (MenuItem mi in contextMenu.MenuItems) | |
267 { | |
268 mi.Visible = lstDebugItems.SelectedIndex > -1; | |
269 } | |
270 } | |
271 | |
272 private void lstDebugItems_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) | |
273 { | |
274 if (e.Button == MouseButtons.Right) | |
275 { | |
276 int idx = lstDebugItems.IndexFromPoint(e.X, e.Y); | |
277 | |
278 if (lstDebugItems.SelectedIndices.Contains(idx)) | |
279 { | |
280 lstDebugItems.SelectedIndex = idx; | |
281 } | |
282 } | |
283 } | |
284 | |
285 private void lstDebugItems_SelectedIndexChanged(object sender, System.EventArgs e) | |
286 { | |
287 if (lstDebugItems.SelectedIndex > -1) | |
288 { | |
289 LogItem item = (LogItem)lstDebugItems.SelectedItem; | |
290 txtDetail.Text = item.ToString() + Environment.NewLine + Environment.NewLine + "Stack Trace: "+ item.StackTrace; | |
291 } | |
292 else | |
293 { | |
294 txtDetail.Text = ""; | |
295 } | |
296 } | |
297 | |
298 private void txtDetail_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) | |
299 { | |
300 if(e.KeyData == (Keys.Control|Keys.A) && e.Control) | |
301 { | |
302 txtDetail.SelectAll(); | |
303 } | |
304 } | |
305 } | |
306 } |