Skip to content

Commit 0f6ff7f

Browse files
committed
implemented model builder
1 parent b9dd37c commit 0f6ff7f

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Concurrent;
23
using System.Collections.ObjectModel;
34
using System.Text;
45
using System.Threading.Tasks;
@@ -27,7 +28,7 @@ public CodeExplorerViewModel(RubberduckParserState state, ObservableCollection<E
2728
public class ExplorerItemViewModel : ViewModelBase
2829
{
2930
private readonly Declaration _declaration;
30-
private readonly ObservableCollection<ExplorerItemViewModel> _children = new ObservableCollection<ExplorerItemViewModel>();
31+
private readonly ConcurrentStack<ExplorerItemViewModel> _children = new ConcurrentStack<ExplorerItemViewModel>();
3132

3233
public ExplorerItemViewModel(Declaration declaration)
3334
{
@@ -36,7 +37,7 @@ public ExplorerItemViewModel(Declaration declaration)
3637

3738
public void AddChild(ExplorerItemViewModel declaration)
3839
{
39-
_children.Add(declaration);
40+
_children.Push(declaration);
4041
}
4142

4243
public void Clear()

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerViewModelBuilder.cs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using System.Linq;
3+
using System.Threading.Tasks;
34
using Rubberduck.Parsing.Symbols;
45
using Rubberduck.Parsing.VBA;
56

@@ -21,24 +22,42 @@ public IEnumerable<ExplorerItemViewModel> Build()
2122
{
2223
var project = projectDeclaration;
2324
var projectItem = new ExplorerItemViewModel(project);
24-
foreach (var componentDeclaration in userDeclarations.Where(d => ReferenceEquals(d.ParentDeclaration, project)))
25+
Parallel.ForEach(userDeclarations.Where(d => ReferenceEquals(d.ParentDeclaration, project)), (componentDeclaration) =>
2526
{
2627
var component = componentDeclaration;
27-
yield return new ExplorerItemViewModel(component);
28-
foreach (var member in userDeclarations.Where(d => ReferenceEquals(d.ParentDeclaration, component)))
28+
var componentItem = new ExplorerItemViewModel(component);
29+
foreach (var memberDeclaration in userDeclarations.Where(d => ReferenceEquals(d.ParentDeclaration, component)))
2930
{
30-
yield return new ExplorerItemViewModel(member);
31+
var member = memberDeclaration;
32+
var memberItem = new ExplorerItemViewModel(member);
3133
if (member.DeclarationType == DeclarationType.UserDefinedType)
3234
{
33-
35+
foreach (var item in userDeclarations.Where(d => ReferenceEquals(d.ParentDeclaration, component)
36+
&& d.DeclarationType == DeclarationType.UserDefinedTypeMember
37+
&& d.ParentScope == member.Scope))
38+
{
39+
memberItem.AddChild(new ExplorerItemViewModel(item));
40+
}
3441
}
3542

3643
if (member.DeclarationType == DeclarationType.Enumeration)
3744
{
38-
45+
foreach (var item in userDeclarations.Where(d => ReferenceEquals(d.ParentDeclaration, component)
46+
&& d.DeclarationType == DeclarationType.EnumerationMember
47+
&& d.ParentScope == member.Scope))
48+
{
49+
memberItem.AddChild(new ExplorerItemViewModel(item));
50+
}
3951
}
52+
53+
componentItem.AddChild(memberItem);
4054
}
41-
}
55+
56+
projectItem.AddChild(componentItem);
57+
});
58+
59+
// todo: figure out a way to yield return before that
60+
yield return projectItem;
4261
}
4362
}
4463
}

0 commit comments

Comments
 (0)