codecoveragetreenode.cs

来自「SharpDevelop2.0.0 c#开发免费工具」· CS 代码 · 共 110 行

CS
110
字号
// <file>
//     <copyright see="prj:///doc/copyright.txt"/>
//     <license see="prj:///doc/license.txt"/>
//     <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
//     <version>$Revision: 1068 $</version>
// </file>

using ICSharpCode.SharpDevelop.Gui;
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Windows.Forms;

namespace ICSharpCode.CodeCoverage
{
	public class CodeCoverageTreeNode : ExtTreeNode
	{
		/// <summary>
		/// Code coverage is less than one hundred percent.
		/// </summary>
		public static readonly Color PartialCoverageTextColor = Color.Red;
		
		/// <summary>
		/// Code coverage is zero.
		/// </summary>
		public static readonly Color ZeroCoverageTextColor = Color.Gray;
		
		int visitedCount;
		int notVisitedCount;
		int baseImageIndex;
		
		public CodeCoverageTreeNode(string name, CodeCoverageImageListIndex index) : this(name, index, 0, 0)
		{
		}
		
		public CodeCoverageTreeNode(string name, CodeCoverageImageListIndex index, int visitedCount, int notVisitedCount)
		{
			this.visitedCount = visitedCount;
			this.notVisitedCount = notVisitedCount;
			
			Name = name;
			SetText();
			
			baseImageIndex = (int)index;
			SetImageIndex();
		}
		
		public int VisitedCount {
			get {
				return visitedCount;
			}
			set {
				visitedCount = value;
				SetText();
				SetImageIndex();
			}
		}
		
		public int NotVisitedCount {
			get {
				return notVisitedCount;
			}
			set {
				notVisitedCount = value;
				SetText();
			}
		}
		
		static string GetPercentage(int visitedCount, int totalCount)
		{
			int percentage = (visitedCount * 100) / totalCount;
			return percentage.ToString();
		}
		
		static string GetNodeText(string name, int visitedCount, int totalCount)
		{
			if (totalCount > 0) {
				return String.Concat(name, " (", GetPercentage(visitedCount, totalCount), "%)");
			}
			return name;
		}
		
		void SetText()
		{
			int total = visitedCount + notVisitedCount;
			
			// Change the text color for partial coverage.
			if (visitedCount == 0) {
				ForeColor = ZeroCoverageTextColor; 
			} else if(total != visitedCount) {
				ForeColor = PartialCoverageTextColor;
			} else {
				ForeColor = Color.Empty;
			}
			
			// Get the text for the node.
			Text = GetNodeText(Name, visitedCount, total);
		}
		
		void SetImageIndex()
		{
			ImageIndex = baseImageIndex;
			if (visitedCount == 0) {
				ImageIndex++;
			}
			SelectedImageIndex = ImageIndex;	
		}
	}
}

⌨️ 快捷键说明

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