This repository has been archived by the owner on Oct 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 771
/
ContentNode.cs
189 lines (166 loc) · 5.58 KB
/
ContentNode.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// 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 ICSharpCode.Core;
using ICSharpCode.NRefactory.Ast;
using System;
using System.Collections.Generic;
using System.Linq;
using Debugger.AddIn.Visualizers.Utils;
namespace Debugger.AddIn.Visualizers.Graph.Layout
{
/// <summary>
/// ViewModel base for node in tree of properties, to be bound to View (ie. PositionedGraphNodeControl).
/// </summary>
public class ContentNode : Utils.ITreeNode<ContentNode>
{
public ContentNode(PositionedNode containingNode, ContentNode parent)
{
if (containingNode == null)
throw new ArgumentNullException("containingNode");
this.containingNode = containingNode;
this.parent = parent;
}
/// <summary>
/// Path to this content node in the whole <see cref="PositionedGraph"></see>.
/// </summary>
public string FullPath
{
get { return this.containingNode.ObjectNode.Expression.PrettyPrint() + "/" + this.Path; }
}
private ContentNode parent;
/// <summary>
/// Parent node in the content tree. Null if this node is root.
/// </summary>
public ContentNode Parent
{
get { return this.parent; }
}
private string path;
/// <summary>
/// Path to this content node in the content tree of containing <see cref="PositinedGraphNode"></see>.
/// </summary>
public string Path
{
get { return this.path; }
}
/// <summary>
/// Name displayed in GUI.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Text displayed in GUI.
/// </summary>
public string Text { get; set; }
/// <summary>
/// Is this expandable node?
/// </summary>
public bool IsNested { get; set; }
/// <summary>
/// Does this node have any children?
/// </summary>
public bool HasChildren { get { return this.Children.Count > 0; } }
// if we bound this ViewModel to a TreeView, this would not be needed,
// it is added "artificially" to support PositionedGraphNodeControl
public bool IsExpanded { get; set; }
private List<ContentNode> children = new List<ContentNode>();
public List<ContentNode> Children { get { return this.children; } }
PositionedNode containingNode;
/// <summary>
/// PositionedGraphNode that contains this PropertyNodeViewModel.
/// </summary>
public PositionedNode ContainingNode
{
get { return this.containingNode; }
}
/// <summary>
/// Show a button to expand property associated with this node?
/// </summary>
public virtual bool ShowExpandPropertyButton
{
get {
// this is ContentNode -> no property, don't show expand button
return false;
}
}
/// <summary>
/// Is this an expanded Property node?
/// </summary>
public virtual bool IsPropertyExpanded
{
get {
// this is ContentNode -> no property, don't show expand button
return false;
}
set { throw new InvalidOperationException("Cannot set IsPropertyExpanded on " + typeof(ContentNode).Name); }
}
/// <summary>
/// Returns flattened subtree.
/// </summary>
public IEnumerable<ContentNode> FlattenAll()
{
return Utils.TreeFlattener.Flatten(this);
}
/// <summary>
/// Returns flattened subtree (including root), skipping children of collapsed nodes.
/// </summary>
public IEnumerable<ContentNode> FlattenExpanded()
{
return Utils.TreeFlattener.FlattenSelectChildrenIf(this, node => node.IsExpanded);
}
/// <summary>
/// Returns flattened subtree (excluding root), skipping children of collapsed nodes.
/// </summary>
/// <returns></returns>
public IEnumerable<ContentNode> FlattenChildrenExpanded()
{
return Utils.TreeFlattener.FlattenSelectChildrenIf(this.Children, node => node.IsExpanded);
}
/// <summary>
/// Returns properties nodes from this tree.
/// </summary>
public IEnumerable<PositionedNodeProperty> FlattenProperties()
{
return Utils.TreeFlattener.Flatten(this).Where(node => node is ContentPropertyNode).
Select( propertyNode => ((ContentPropertyNode)propertyNode).Property);
}
#region Utils.ITreeNode implementation
IEnumerable<ContentNode> ITreeNode<ContentNode>.Children
{
get { return this.Children; }
}
#endregion
public virtual void InitOverride(AbstractNode source, Expanded expanded)
{
this.Name = GetContentNodeName(source);
this.Text = ""; // lazy evaluated later
this.IsNested = true;
this.path = this.Parent == null ? this.Name : this.Parent.Path + "." + this.Name;
this.IsExpanded = (source is ThisNode) || expanded.ContentNodes.IsExpanded(this);
foreach (AbstractNode child in source.Children) {
ContentNode newChild = null;
if (child is PropertyNode) {
newChild = new ContentPropertyNode(this.ContainingNode, this);
} else {
newChild = new ContentNode(this.ContainingNode, this);
}
newChild.InitOverride(child, expanded);
this.Children.Add(newChild);
}
}
private string GetContentNodeName(AbstractNode source)
{
if (source is ThisNode) {
return "this";
}
if (source is NonPublicMembersNode) {
return StringParser.Parse("${res:MainWindow.Windows.Debug.LocalVariables.NonPublicMembers}");
}
var sourceBaseClassNode = source as BaseClassNode;
if (sourceBaseClassNode != null) {
string baseClassString = StringParser.Parse("${res:MainWindow.Windows.Debug.LocalVariables.BaseClass}");
return string.Format("{0} ({1})", sourceBaseClassNode.TypeName, baseClassString);
}
throw new ApplicationException("Unknown AbstractNode.");
}
}
}