8
8
9
9
namespace Rubberduck . Navigation . CodeExplorer
10
10
{
11
- [ DebuggerDisplay ( "{Name}" ) ]
11
+ [ DebuggerDisplay ( "{" + nameof ( Name ) + " }") ]
12
12
public sealed class CodeExplorerCustomFolderViewModel : CodeExplorerItemViewModel
13
13
{
14
14
private static readonly DeclarationType [ ] ComponentTypes =
@@ -26,14 +26,14 @@ public CodeExplorerCustomFolderViewModel(
26
26
string name ,
27
27
string fullPath ,
28
28
IVBE vbe ,
29
- IEnumerable < Declaration > declarations ) : base ( parent , parent ? . Declaration )
29
+ ref List < Declaration > declarations ) : base ( parent , parent ? . Declaration )
30
30
{
31
31
_vbe = vbe ;
32
32
FolderDepth = parent is CodeExplorerCustomFolderViewModel folder ? folder . FolderDepth + 1 : 1 ;
33
33
FullPath = fullPath ? . Trim ( '"' ) ?? string . Empty ;
34
34
Name = name . Replace ( "\" " , string . Empty ) ;
35
35
36
- AddNewChildren ( declarations . ToList ( ) ) ;
36
+ AddNewChildren ( ref declarations ) ;
37
37
}
38
38
39
39
public override string Name { get ; }
@@ -63,84 +63,77 @@ public override bool IsErrorState
63
63
64
64
public override bool Filtered => false ;
65
65
66
- protected override void AddNewChildren ( List < Declaration > declarations )
66
+ protected override void AddNewChildren ( ref List < Declaration > declarations )
67
67
{
68
- var children = declarations . Where ( declaration => declaration . IsInSubFolder ( FullPath ) ) . ToList ( ) ;
68
+ var children = declarations . Where ( declaration => declaration . IsInFolderOrSubFolder ( FullPath ) ) . ToList ( ) ;
69
+ declarations = declarations . Except ( children ) . ToList ( ) ;
69
70
70
- foreach ( var folder in children . GroupBy ( declaration => declaration . CustomFolder . SubFolderRoot ( FullPath ) ) )
71
+ var subFolders = children . Where ( declaration => declaration . IsInSubFolder ( FullPath ) ) . ToList ( ) ;
72
+
73
+ foreach ( var folder in subFolders . GroupBy ( declaration => declaration . CustomFolder . SubFolderRoot ( FullPath ) ) )
71
74
{
72
- AddChild ( new CodeExplorerCustomFolderViewModel ( this , folder . Key , $ "{ FullPath } .{ folder . Key } ", _vbe , folder ) ) ;
73
- foreach ( var declaration in folder )
74
- {
75
- declarations . Remove ( declaration ) ;
76
- }
75
+ var contents = folder . ToList ( ) ;
76
+ AddChild ( new CodeExplorerCustomFolderViewModel ( this , folder . Key , $ "{ FullPath } .{ folder . Key } ", _vbe , ref contents ) ) ;
77
77
}
78
78
79
- foreach ( var declaration in declarations . Where ( child => child . IsInFolder ( FullPath ) ) . GroupBy ( item => item . ComponentName ) )
79
+ children = children . Except ( subFolders ) . ToList ( ) ;
80
+
81
+ foreach ( var declaration in children . Where ( child => child . IsInFolder ( FullPath ) ) . GroupBy ( item => item . ComponentName ) )
80
82
{
81
83
var moduleName = declaration . Key ;
82
- var parent = declarations . SingleOrDefault ( item =>
84
+ var parent = children . SingleOrDefault ( item =>
83
85
ComponentTypes . Contains ( item . DeclarationType ) && item . ComponentName == moduleName ) ;
84
86
85
87
if ( parent is null )
86
88
{
87
89
continue ;
88
90
}
89
91
90
- var members = declarations . Where ( item =>
91
- ! ComponentTypes . Contains ( item . DeclarationType ) && item . ComponentName == moduleName ) ;
92
+ var members = children . Where ( item =>
93
+ ! ComponentTypes . Contains ( item . DeclarationType ) && item . ComponentName == moduleName ) . ToList ( ) ;
92
94
93
- AddChild ( new CodeExplorerComponentViewModel ( this , parent , members , _vbe ) ) ;
94
- declarations . Remove ( parent ) ;
95
+ AddChild ( new CodeExplorerComponentViewModel ( this , parent , ref members , _vbe ) ) ;
95
96
}
96
97
}
97
98
98
- public override void Synchronize ( List < Declaration > updated )
99
+ public override void Synchronize ( ref List < Declaration > updated )
99
100
{
100
- SynchronizeChildren ( updated ) ;
101
+ SynchronizeChildren ( ref updated ) ;
101
102
}
102
103
103
- protected override void SynchronizeChildren ( List < Declaration > updated )
104
+ protected override void SynchronizeChildren ( ref List < Declaration > updated )
104
105
{
105
- var declarations = updated . Where ( declaration => declaration . IsInFolderOrSubFolder ( FullPath ) ) . ToList ( ) ;
106
+ var children = updated . Where ( declaration => declaration . IsInFolderOrSubFolder ( FullPath ) ) . ToList ( ) ;
107
+ updated = updated . Except ( children ) . ToList ( ) ;
106
108
107
- if ( ! declarations . Any ( ) )
109
+ if ( ! children . Any ( ) )
108
110
{
109
111
Declaration = null ;
110
112
return ;
111
113
}
112
114
113
- var synchronizing = declarations . ToList ( ) ;
115
+ var subFolders = children . Where ( declaration => declaration . IsInSubFolder ( FullPath ) ) . ToList ( ) ;
116
+ children = children . Except ( subFolders ) . ToList ( ) ;
114
117
115
118
foreach ( var subfolder in Children . OfType < CodeExplorerCustomFolderViewModel > ( ) . ToList ( ) )
116
119
{
117
- subfolder . SynchronizeChildren ( declarations ) ;
120
+ subfolder . SynchronizeChildren ( ref subFolders ) ;
118
121
if ( subfolder . Declaration is null )
119
122
{
120
123
RemoveChild ( subfolder ) ;
121
- continue ;
122
- }
123
-
124
- var synchronized = synchronizing . Where ( child => ! declarations . Contains ( child ) ) . ToList ( ) ;
125
- foreach ( var declaration in synchronized )
126
- {
127
- updated . Remove ( declaration ) ;
128
124
}
129
125
}
130
126
131
127
foreach ( var child in Children . OfType < CodeExplorerComponentViewModel > ( ) . ToList ( ) )
132
128
{
133
- child . Synchronize ( updated ) ;
129
+ child . Synchronize ( ref children ) ;
134
130
if ( child . Declaration is null )
135
131
{
136
132
RemoveChild ( child ) ;
137
- continue ;
138
133
}
139
-
140
- updated . Remove ( child . Declaration ) ;
141
134
}
142
135
143
- AddNewChildren ( updated ) ;
136
+ AddNewChildren ( ref children ) ;
144
137
}
145
138
}
146
139
}
0 commit comments