⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 treelistviewdebuggeritem.cs

📁 SharpDevelop2.0.0 c#开发免费工具
💻 CS
字号:
// <file>
//     <copyright see="prj:///doc/copyright.txt"/>
//     <license see="prj:///doc/license.txt"/>
//     <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
//     <version>$Revision$</version>
// </file>

using System;
using System.Drawing;
using System.Windows.Forms;

using Debugger;

namespace ICSharpCode.SharpDevelop.Gui.Pads
{
	public class TreeListViewDebuggerItem: TreeListViewItem
	{
		Variable variable;
		bool populated = false;
		
		public Variable Variable {
			get {
				return variable;
			}
		}
		
		public bool Highlight {
			set {
				if (value) {
					if (SubItems[1].ForeColor != Color.Blue) { // smart update
						SubItems[1].ForeColor = Color.Blue;
						SubItems[1].Font = new Font(SubItems[1].Font, FontStyle.Bold);
					}
				} else {
					if (SubItems[1].ForeColor != Color.Black) { // smart update
						SubItems[1].ForeColor = Color.Black;
						SubItems[1].Font = new Font(SubItems[1].Font, FontStyle.Regular);
					}
				}
			}
		}
		
		bool IsVisible {
			get {
				foreach(TreeListViewItem parent in this.ParentsInHierarch) {
					if (!parent.IsExpanded) {
						return false;
					}
				}
				return true;
			}
		}
		
		public TreeListViewDebuggerItem(Variable variable)
		{
			this.variable = variable;
			
			variable.ValueChanged += Update;
			
			variable.ValueRemovedFromCollection += delegate {
				variable.ValueChanged -= Update;
				this.Remove();
			};
			
			SubItems.Add("");
			SubItems.Add("");
			
			Update(this, null);
		}
		
		bool waitingForParentToExpand = false;
		
		void Update(object sender, DebuggerEventArgs e)
		{
			if (waitingForParentToExpand) return;
			
			if (this.Parent != null && !IsVisible) {
				// Delay the update until the parent is expanded
				TreeListViewItemHanlder update = null;
				update = delegate {
					waitingForParentToExpand = false;
					Update(this, null);
					foreach(TreeListViewItem parent in this.ParentsInHierarch) {
						parent.AfterExpand -= update;
					}
				};
				foreach(TreeListViewItem parent in this.ParentsInHierarch) {
					parent.AfterExpand += update;
				}
				waitingForParentToExpand = true;
				return;
			}
			
			if (this.TreeListView != null) {
				((DebuggerTreeListView)this.TreeListView).DelayRefresh();
				Highlight = (Variable.Value.AsString != SubItems[1].Text);
			}
			
			this.SubItems[0].Text = Variable.Name;
			this.SubItems[1].Text = Variable.Value.AsString;
			this.SubItems[2].Text = Variable.Value.Type;
			
			this.ImageIndex = DebuggerIcons.GetImageListIndex(variable);
			
			if (IsExpanded) {
				variable.SubVariables.Update();
			} else {
				// Show plus sign
				if (variable.Value.MayHaveSubVariables && Items.Count == 0) {
					TreeListViewItem dummy = new TreeListViewItem();
					this.AfterExpand += delegate { dummy.Remove(); };
					Items.Add(dummy);
				}
			}
		}
		
		public void BeforeExpand()
		{
			if (populated) {
				variable.SubVariables.Update();
			} else {
				Populate();
				populated = true;
			}
		}
		
		public void Populate()
		{
			Items.Clear();
			
			// Do not sort names of array items
			if (variable.Value is ArrayValue) {
				this.Items.SortOrder = SortOrder.None;
			} else {
				this.Items.SortOrder = SortOrder.Ascending;
			}
			
			LocalVarPad.AddVariableCollectionToTree(variable.SubVariables, this.Items);
		}
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -