@@ -29,23 +29,27 @@ private class ClassTreeNode : TreeNode, IDisposable
29
29
{
30
30
public ClassNode ClassNode { get ; }
31
31
32
+ private readonly ValueWrapper < bool > enableHierarchyView ;
32
33
private readonly ValueWrapper < bool > autoExpand ;
33
34
34
35
/// <summary>Constructor of the class.</summary>
35
36
/// <param name="node">The class node.</param>
36
37
/// <param name="autoExpand">The value if nodes should get expanded.</param>
37
- public ClassTreeNode ( ClassNode node , ValueWrapper < bool > autoExpand )
38
- : this ( node , autoExpand , null )
38
+ public ClassTreeNode ( ClassNode node , ValueWrapper < bool > enableHierarchyView , ValueWrapper < bool > autoExpand )
39
+ : this ( node , enableHierarchyView , autoExpand , null )
39
40
{
40
41
Contract . Requires ( node != null ) ;
42
+ Contract . Requires ( enableHierarchyView != null ) ;
41
43
Contract . Requires ( autoExpand != null ) ;
42
44
}
43
45
44
- private ClassTreeNode ( ClassNode node , ValueWrapper < bool > autoExpand , HashSet < ClassNode > seen )
46
+ private ClassTreeNode ( ClassNode node , ValueWrapper < bool > enableHierarchyView , ValueWrapper < bool > autoExpand , HashSet < ClassNode > seen )
45
47
{
46
48
Contract . Requires ( node != null ) ;
49
+ Contract . Requires ( enableHierarchyView != null ) ;
47
50
Contract . Requires ( autoExpand != null ) ;
48
51
52
+ this . enableHierarchyView = enableHierarchyView ;
49
53
this . autoExpand = autoExpand ;
50
54
51
55
ClassNode = node ;
@@ -86,19 +90,32 @@ private void RebuildClassHierarchy(HashSet<ClassNode> seen)
86
90
{
87
91
Contract . Requires ( seen != null ) ;
88
92
89
- Nodes . OfType < ClassTreeNode > ( ) . ForEach ( t => t . Dispose ( ) ) ;
90
- Nodes . Clear ( ) ;
93
+ if ( ! enableHierarchyView . Value )
94
+ {
95
+ return ;
96
+ }
91
97
92
- foreach ( var child in ClassNode . Nodes
98
+ var distinctClasses = ClassNode . Nodes
93
99
. OfType < BaseReferenceNode > ( )
94
100
. Select ( r => r . InnerNode )
95
101
. OfType < ClassNode > ( )
96
- . Distinct ( ) )
102
+ . Distinct ( )
103
+ . ToList ( ) ;
104
+
105
+ if ( distinctClasses . SequenceEqualsEx ( Nodes . OfType < ClassTreeNode > ( ) . Select ( t => t . ClassNode ) ) )
106
+ {
107
+ return ;
108
+ }
109
+
110
+ Nodes . OfType < ClassTreeNode > ( ) . ForEach ( t => t . Dispose ( ) ) ;
111
+ Nodes . Clear ( ) ;
112
+
113
+ foreach ( var child in distinctClasses )
97
114
{
98
115
var childSeen = new HashSet < ClassNode > ( seen ) ;
99
116
if ( childSeen . Add ( child ) )
100
117
{
101
- Nodes . Add ( new ClassTreeNode ( child , autoExpand , childSeen ) ) ;
118
+ Nodes . Add ( new ClassTreeNode ( child , enableHierarchyView , autoExpand , childSeen ) ) ;
102
119
}
103
120
}
104
121
@@ -110,6 +127,7 @@ private void RebuildClassHierarchy(HashSet<ClassNode> seen)
110
127
}
111
128
112
129
private readonly TreeNode root ;
130
+ private readonly ValueWrapper < bool > enableHierarchyView ;
113
131
private readonly ValueWrapper < bool > autoExpand ;
114
132
115
133
private ReClassNetProject project ;
@@ -179,6 +197,7 @@ public ClassNodeView()
179
197
180
198
DoubleBuffered = true ;
181
199
200
+ enableHierarchyView = new ValueWrapper < bool > ( true ) ;
182
201
autoExpand = new ValueWrapper < bool > ( false ) ;
183
202
184
203
classesTreeView . ImageList = new ImageList ( ) ;
@@ -287,6 +306,20 @@ private void classesTreeView_AfterLabelEdit(object sender, NodeLabelEditEventArg
287
306
}
288
307
}
289
308
309
+ private void enableHierarchyViewToolStripMenuItem_Click ( object sender , EventArgs e )
310
+ {
311
+ enableHierarchyViewToolStripMenuItem . Checked = ! enableHierarchyViewToolStripMenuItem . Checked ;
312
+
313
+ enableHierarchyView . Value = enableHierarchyViewToolStripMenuItem . Checked ;
314
+
315
+ var classes = root . Nodes . OfType < ClassTreeNode > ( ) . Select ( t => t . ClassNode ) . ToList ( ) ;
316
+
317
+ root . Nodes . OfType < ClassTreeNode > ( ) . ForEach ( t => t . Dispose ( ) ) ;
318
+ root . Nodes . Clear ( ) ;
319
+
320
+ classes . ForEach ( AddClass ) ;
321
+ }
322
+
290
323
private void autoExpandHierarchyViewToolStripMenuItem_Click ( object sender , EventArgs e )
291
324
{
292
325
autoExpandHierarchyViewToolStripMenuItem . Checked = ! autoExpandHierarchyViewToolStripMenuItem . Checked ;
@@ -317,7 +350,7 @@ public void AddClass(ClassNode node)
317
350
{
318
351
Contract . Requires ( node != null ) ;
319
352
320
- root . Nodes . Add ( new ClassTreeNode ( node , autoExpand ) ) ;
353
+ root . Nodes . Add ( new ClassTreeNode ( node , enableHierarchyView , autoExpand ) ) ;
321
354
322
355
classesTreeView . Sort ( ) ;
323
356
0 commit comments