This repository has been archived by the owner on Oct 16, 2020. It is now read-only.
/
TreeNode.cs
154 lines (129 loc) · 3.43 KB
/
TreeNode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Media;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Debugging;
namespace Debugger.AddIn.TreeModel
{
/// <summary>
/// A node in the variable tree.
/// The node is immutable.
/// </summary>
public class TreeNode : ITreeNode
{
IImage iconImage = null;
string name = string.Empty;
string imageName = string.Empty;
string text = string.Empty;
string type = string.Empty;
protected IEnumerable<TreeNode> childNodes = null;
/// <summary>
/// The image displayed for this node.
/// </summary>
public IImage IconImage {
get { return iconImage; }
protected set { iconImage = value; }
}
/// <summary>
/// System.Windows.Media.ImageSource version of <see cref="IconImage"/>.
/// </summary>
public ImageSource ImageSource {
get {
return iconImage == null ? null : iconImage.ImageSource;
}
}
/// <summary>
/// System.Drawing.Image version of <see cref="IconImage"/>.
/// </summary>
public Image Image {
get {
return iconImage == null ? null : iconImage.Bitmap;
}
}
public string Name {
get { return name; }
set { name = value; }
}
public string ImageName {
get { return imageName; }
set { imageName = value; }
}
public virtual string FullName {
get { return name; }
set { name = value; }
}
public virtual string Text
{
get { return text; }
set { text = value; }
}
public virtual string Type {
get { return type; }
protected set { type = value; }
}
public virtual TreeNode Parent { get; protected set; }
public virtual IEnumerable<TreeNode> ChildNodes {
get { return childNodes; }
}
IEnumerable<ITreeNode> ITreeNode.ChildNodes {
get { return childNodes; }
}
public virtual bool HasChildNodes {
get { return childNodes != null; }
}
public virtual bool CanSetText {
get { return false; }
}
public virtual IEnumerable<IVisualizerCommand> VisualizerCommands {
get {
return null;
}
}
public virtual bool HasVisualizerCommands {
get {
return (VisualizerCommands != null) && (VisualizerCommands.Count() > 0);
}
}
public bool IsPinned { get; set; }
public TreeNode(TreeNode parent)
{
this.Parent = parent;
}
public TreeNode(IImage iconImage, string name, string text, string type, TreeNode parent, Func<TreeNode, IEnumerable<TreeNode>> childNodes)
: this(parent)
{
if (childNodes == null)
throw new ArgumentNullException("childNodes");
this.iconImage = iconImage;
this.name = name;
this.text = text;
this.type = type;
this.childNodes = childNodes(this);
}
#region Equals and GetHashCode implementation
public override bool Equals(object obj)
{
TreeNode other = obj as TreeNode;
if (other == null)
return false;
return this.FullName == other.FullName;
}
public override int GetHashCode()
{
return this.FullName.GetHashCode();
}
#endregion
public int CompareTo(ITreeNode other)
{
return this.FullName.CompareTo(other.FullName);
}
public virtual bool SetText(string newValue) {
return false;
}
}
}