@@ -29,23 +29,27 @@ private class ClassTreeNode : TreeNode, IDisposable
2929 {
3030 public ClassNode ClassNode { get ; }
3131
32+ private readonly ValueWrapper < bool > enableHierarchyView ;
3233 private readonly ValueWrapper < bool > autoExpand ;
3334
3435 /// <summary>Constructor of the class.</summary>
3536 /// <param name="node">The class node.</param>
3637 /// <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 )
3940 {
4041 Contract . Requires ( node != null ) ;
42+ Contract . Requires ( enableHierarchyView != null ) ;
4143 Contract . Requires ( autoExpand != null ) ;
4244 }
4345
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 )
4547 {
4648 Contract . Requires ( node != null ) ;
49+ Contract . Requires ( enableHierarchyView != null ) ;
4750 Contract . Requires ( autoExpand != null ) ;
4851
52+ this . enableHierarchyView = enableHierarchyView ;
4953 this . autoExpand = autoExpand ;
5054
5155 ClassNode = node ;
@@ -86,19 +90,32 @@ private void RebuildClassHierarchy(HashSet<ClassNode> seen)
8690 {
8791 Contract . Requires ( seen != null ) ;
8892
89- Nodes . OfType < ClassTreeNode > ( ) . ForEach ( t => t . Dispose ( ) ) ;
90- Nodes . Clear ( ) ;
93+ if ( ! enableHierarchyView . Value )
94+ {
95+ return ;
96+ }
9197
92- foreach ( var child in ClassNode . Nodes
98+ var distinctClasses = ClassNode . Nodes
9399 . OfType < BaseReferenceNode > ( )
94100 . Select ( r => r . InnerNode )
95101 . 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 )
97114 {
98115 var childSeen = new HashSet < ClassNode > ( seen ) ;
99116 if ( childSeen . Add ( child ) )
100117 {
101- Nodes . Add ( new ClassTreeNode ( child , autoExpand , childSeen ) ) ;
118+ Nodes . Add ( new ClassTreeNode ( child , enableHierarchyView , autoExpand , childSeen ) ) ;
102119 }
103120 }
104121
@@ -110,6 +127,7 @@ private void RebuildClassHierarchy(HashSet<ClassNode> seen)
110127 }
111128
112129 private readonly TreeNode root ;
130+ private readonly ValueWrapper < bool > enableHierarchyView ;
113131 private readonly ValueWrapper < bool > autoExpand ;
114132
115133 private ReClassNetProject project ;
@@ -179,6 +197,7 @@ public ClassNodeView()
179197
180198 DoubleBuffered = true ;
181199
200+ enableHierarchyView = new ValueWrapper < bool > ( true ) ;
182201 autoExpand = new ValueWrapper < bool > ( false ) ;
183202
184203 classesTreeView . ImageList = new ImageList ( ) ;
@@ -287,6 +306,20 @@ private void classesTreeView_AfterLabelEdit(object sender, NodeLabelEditEventArg
287306 }
288307 }
289308
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+
290323 private void autoExpandHierarchyViewToolStripMenuItem_Click ( object sender , EventArgs e )
291324 {
292325 autoExpandHierarchyViewToolStripMenuItem . Checked = ! autoExpandHierarchyViewToolStripMenuItem . Checked ;
@@ -317,7 +350,7 @@ public void AddClass(ClassNode node)
317350 {
318351 Contract . Requires ( node != null ) ;
319352
320- root . Nodes . Add ( new ClassTreeNode ( node , autoExpand ) ) ;
353+ root . Nodes . Add ( new ClassTreeNode ( node , enableHierarchyView , autoExpand ) ) ;
321354
322355 classesTreeView . Sort ( ) ;
323356
0 commit comments