view 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
line wrap: on
line source

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
using IBBoard.Lang;
using IBBoard.Logging;
using IBBoard.Windows.Forms;

namespace IBBoard.WarFoundry
{
	/// <summary>
	/// Summary description for FrmDebugOutput.
	/// </summary>
	public class FrmDebugOutput : IBBForm
	{
		private System.Windows.Forms.ListBox lstDebugItems;
		private System.Windows.Forms.ComboBox cmbDebugLevel;
		private System.Windows.Forms.Label lblDebugLevel;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private Logger logger;
		private System.Windows.Forms.ContextMenu contextMenu;
		private System.Windows.Forms.MenuItem miCopy;
		private System.Windows.Forms.TextBox txtDetail;
		private System.Windows.Forms.Splitter splitter1;
		private System.Windows.Forms.Panel panel1;
		private int MAX_LIST_LENGTH = 50;

		public FrmDebugOutput()
		{
			//this.logger = logger;
			//logger.LogUpdatedEvent+=new IBBoard.Logging.Logger.LogUpdatedDelegate(logger_LogUpdatedEvent);
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			/*if (LogLevels.Debug >= logger.LogLevel)
			{
				cmbDebugLevel.Items.Add(LogLevels.Debug);
			}

			if (LogLevels.Info >= logger.LogLevel)
			{
				cmbDebugLevel.Items.Add(LogLevels.Info);
			}

			if (LogLevels.Warning >= logger.LogLevel)
			{
				cmbDebugLevel.Items.Add(LogLevels.Warning);
			}

			if (LogLevels.Error >= logger.LogLevel)
			{
				cmbDebugLevel.Items.Add(LogLevels.Error);
			}

			if (LogLevels.Critical >= logger.LogLevel)
			{
				cmbDebugLevel.Items.Add(LogLevels.Critical);
			}*/

			this.Name = "DebugOutputForm";

			cmbDebugLevel.SelectedItem = logger.LogLevel;

			Translation.Translate(this, true);

			fillDebugList();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.lstDebugItems = new System.Windows.Forms.ListBox();
			this.contextMenu = new System.Windows.Forms.ContextMenu();
			this.miCopy = new System.Windows.Forms.MenuItem();
			this.cmbDebugLevel = new System.Windows.Forms.ComboBox();
			this.lblDebugLevel = new System.Windows.Forms.Label();
			this.txtDetail = new System.Windows.Forms.TextBox();
			this.splitter1 = new System.Windows.Forms.Splitter();
			this.panel1 = new System.Windows.Forms.Panel();
			this.SuspendLayout();
			// 
			// lstDebugItems
			// 
			this.lstDebugItems.ContextMenu = this.contextMenu;
			this.lstDebugItems.Dock = System.Windows.Forms.DockStyle.Fill;
			this.lstDebugItems.IntegralHeight = false;
			this.lstDebugItems.Location = new System.Drawing.Point(0, 24);
			this.lstDebugItems.Name = "lstDebugItems";
			this.lstDebugItems.ScrollAlwaysVisible = true;
			this.lstDebugItems.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
			this.lstDebugItems.Size = new System.Drawing.Size(656, 144);
			this.lstDebugItems.TabIndex = 0;
			this.lstDebugItems.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lstDebugItems_MouseDown);
			this.lstDebugItems.SelectedIndexChanged += new System.EventHandler(this.lstDebugItems_SelectedIndexChanged);
			// 
			// contextMenu
			// 
			this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						this.miCopy});
			this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup);
			// 
			// miCopy
			// 
			this.miCopy.Index = 0;
			this.miCopy.Text = "&Copy";
			this.miCopy.Click += new System.EventHandler(this.miCopy_Click);
			// 
			// cmbDebugLevel
			// 
			this.cmbDebugLevel.Location = new System.Drawing.Point(190, 2);
			this.cmbDebugLevel.Name = "cmbDebugLevel";
			this.cmbDebugLevel.Size = new System.Drawing.Size(464, 21);
			this.cmbDebugLevel.TabIndex = 1;
			this.cmbDebugLevel.SelectedIndexChanged += new System.EventHandler(this.cmbDebugLevel_SelectedIndexChanged);
			// 
			// lblDebugLevel
			// 
			this.lblDebugLevel.Location = new System.Drawing.Point(16, 0);
			this.lblDebugLevel.Name = "lblDebugLevel";
			this.lblDebugLevel.Size = new System.Drawing.Size(168, 21);
			this.lblDebugLevel.TabIndex = 2;
			this.lblDebugLevel.Text = "debug level:";
			this.lblDebugLevel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtDetail
			// 
			this.txtDetail.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.txtDetail.Location = new System.Drawing.Point(0, 172);
			this.txtDetail.Multiline = true;
			this.txtDetail.Name = "txtDetail";
			this.txtDetail.ReadOnly = true;
			this.txtDetail.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.txtDetail.Size = new System.Drawing.Size(656, 64);
			this.txtDetail.TabIndex = 3;
			this.txtDetail.TabStop = false;
			this.txtDetail.Text = "";
			this.txtDetail.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtDetail_KeyDown);
			// 
			// splitter1
			// 
			this.splitter1.Cursor = System.Windows.Forms.Cursors.HSplit;
			this.splitter1.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.splitter1.Location = new System.Drawing.Point(0, 168);
			this.splitter1.MinExtra = 50;
			this.splitter1.MinSize = 50;
			this.splitter1.Name = "splitter1";
			this.splitter1.Size = new System.Drawing.Size(656, 4);
			this.splitter1.TabIndex = 4;
			this.splitter1.TabStop = false;
			// 
			// panel1
			// 
			this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
			this.panel1.Location = new System.Drawing.Point(0, 0);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(656, 24);
			this.panel1.TabIndex = 5;
			// 
			// FrmDebugOutput
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(656, 236);
			this.Controls.Add(this.lblDebugLevel);
			this.Controls.Add(this.cmbDebugLevel);
			this.Controls.Add(this.lstDebugItems);
			this.Controls.Add(this.splitter1);
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.txtDetail);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Name = "FrmDebugOutput";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "FrmDebugOutput";
			this.ResumeLayout(false);

		}
		#endregion

		private void cmbDebugLevel_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			fillDebugList();
		}

		private void fillDebugList()
		{
			lstDebugItems.Items.Clear();
			/*LogItem[] items = logger.GetLogItems((LogLevels)cmbDebugLevel.SelectedItem);
			int last = items.Length - 1;
			int stop = last - MAX_LIST_LENGTH;

			if (stop < 0)
			{
				stop = 0;
			}

			//reverse fill the list so that we can have newest items at the top
			for (int i = last; i >= stop; i--)
			{
				lstDebugItems.Items.Add(items[i]);
			}*/
		}

		private void logger_LogUpdatedEvent(LogItem item)
		{
			/*if (item.Level >= (LogLevels)cmbDebugLevel.SelectedItem)
			{
				lock (lstDebugItems)
				{
					lstDebugItems.Items.Insert(0, item);

					if (lstDebugItems.Items.Count > MAX_LIST_LENGTH)
					{
						lstDebugItems.Items.RemoveAt(lstDebugItems.Items.Count - 1);
					}
				}
			}*/
		}

		private void miCopy_Click(object sender, System.EventArgs e)
		{
			if (lstDebugItems.SelectedIndices.Count==1)
			{				
				Clipboard.SetDataObject(lstDebugItems.SelectedItem.ToString());
			}
			else if (lstDebugItems.SelectedIndices.Count > 1)
			{
				StringBuilder sb = new StringBuilder();

				foreach (int idx in lstDebugItems.SelectedIndices)
				{
					sb.Append(lstDebugItems.Items[idx].ToString()+Environment.NewLine);
				}

				Clipboard.SetDataObject(sb.ToString().Trim());
			}
		}

		private void contextMenu_Popup(object sender, System.EventArgs e)
		{
			foreach (MenuItem mi in contextMenu.MenuItems)
			{
				mi.Visible = lstDebugItems.SelectedIndex > -1;
			}
		}

		private void lstDebugItems_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Right)
			{
				int idx = lstDebugItems.IndexFromPoint(e.X, e.Y);

				if (lstDebugItems.SelectedIndices.Contains(idx))
				{
					lstDebugItems.SelectedIndex = idx;
				}
			}
		}

		private void lstDebugItems_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (lstDebugItems.SelectedIndex > -1)
			{
				LogItem item = (LogItem)lstDebugItems.SelectedItem;
				txtDetail.Text = item.ToString() + Environment.NewLine + Environment.NewLine + "Stack Trace: "+ item.StackTrace;
			}
			else
			{
				txtDetail.Text = "";
			}
		}

		private void txtDetail_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyData == (Keys.Control|Keys.A) && e.Control)
			{
				txtDetail.SelectAll();
			}
		}
	}
}