Skip to content

Commit 810b421

Browse files
committed
added CodeExplorerViewModel
1 parent b2989bd commit 810b421

File tree

4 files changed

+97
-1
lines changed

4 files changed

+97
-1
lines changed

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@
347347
<Compile Include="UI\CodeExplorer\CodeExplorerControl.xaml.cs">
348348
<DependentUpon>CodeExplorerControl.xaml</DependentUpon>
349349
</Compile>
350+
<Compile Include="UI\CodeExplorer\CodeExplorerViewModel.cs" />
351+
<Compile Include="UI\CodeExplorer\CodeExplorerViewModelBuilder.cs" />
350352
<Compile Include="UI\CodeInspections\InspectionDescriptionConverter.cs" />
351353
<Compile Include="UI\CodeInspections\InspectionImageSourceConverter.cs" />
352354
<Compile Include="UI\CodeInspections\InspectionResultsControl.xaml.cs">

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
<Button Command="{Binding ToggleNamespaces}"
185185
IsEnabled="{Binding CanRefresh}"
186186
ToolTip="Toggle namespace folders">
187-
<Image Height="16" Source="../../Resources/blue-folder-horizontal-open.png" />
187+
<Image Height="16" Source="../../Resources/blue-folder-horizontal.png" />
188188
</Button>
189189

190190
<Button Command="{Binding ToggleFolders}"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Collections.ObjectModel;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using Rubberduck.Parsing.Symbols;
6+
using Rubberduck.Parsing.VBA;
7+
8+
namespace Rubberduck.UI.CodeExplorer
9+
{
10+
public class CodeExplorerViewModel : ViewModelBase
11+
{
12+
private readonly RubberduckParserState _state;
13+
private readonly ObservableCollection<ExplorerItemViewModel> _children;
14+
15+
public CodeExplorerViewModel(RubberduckParserState state, ObservableCollection<ExplorerItemViewModel> children)
16+
{
17+
_state = state;
18+
_children = children;
19+
}
20+
21+
private bool _isBusy;
22+
public bool IsBusy { get { return _isBusy; } set { _isBusy = value; OnPropertyChanged(); } }
23+
24+
25+
}
26+
27+
public class ExplorerItemViewModel : ViewModelBase
28+
{
29+
private readonly Declaration _declaration;
30+
private readonly ObservableCollection<ExplorerItemViewModel> _children = new ObservableCollection<ExplorerItemViewModel>();
31+
32+
public ExplorerItemViewModel(Declaration declaration)
33+
{
34+
_declaration = declaration;
35+
}
36+
37+
public void AddChild(ExplorerItemViewModel declaration)
38+
{
39+
_children.Add(declaration);
40+
}
41+
42+
public void Clear()
43+
{
44+
_children.Clear();
45+
}
46+
47+
public Declaration Declaration { get { return _declaration; } }
48+
}
49+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Rubberduck.Parsing.Symbols;
4+
using Rubberduck.Parsing.VBA;
5+
6+
namespace Rubberduck.UI.CodeExplorer
7+
{
8+
public class CodeExplorerViewModelBuilder
9+
{
10+
private readonly RubberduckParserState _state;
11+
12+
public CodeExplorerViewModelBuilder(RubberduckParserState state)
13+
{
14+
_state = state;
15+
}
16+
17+
public IEnumerable<ExplorerItemViewModel> Build()
18+
{
19+
var userDeclarations = _state.AllDeclarations.Where(d => !d.IsBuiltIn).ToList();
20+
foreach (var projectDeclaration in userDeclarations.Where(d => d.DeclarationType == DeclarationType.Project))
21+
{
22+
var project = projectDeclaration;
23+
var projectItem = new ExplorerItemViewModel(project);
24+
foreach (var componentDeclaration in userDeclarations.Where(d => ReferenceEquals(d.ParentDeclaration, project)))
25+
{
26+
var component = componentDeclaration;
27+
yield return new ExplorerItemViewModel(component);
28+
foreach (var member in userDeclarations.Where(d => ReferenceEquals(d.ParentDeclaration, component)))
29+
{
30+
yield return new ExplorerItemViewModel(member);
31+
if (member.DeclarationType == DeclarationType.UserDefinedType)
32+
{
33+
34+
}
35+
36+
if (member.DeclarationType == DeclarationType.Enumeration)
37+
{
38+
39+
}
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)