Skip to content

Commit e79bde4

Browse files
Hosch250retailcoder
authored andcommitted
Close #1519 (#1534)
1 parent 67967a6 commit e79bde4

File tree

3 files changed

+69
-11
lines changed

3 files changed

+69
-11
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerComponentViewModel.cs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,53 @@ public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declarat
4747
.OrderBy(item => item.QualifiedSelection.Selection.StartLine)
4848
.Select(item => new CodeExplorerMemberViewModel(this, item, grouping)))
4949
.ToList<CodeExplorerItemViewModel>();
50-
50+
51+
_name = _declaration.IdentifierName;
52+
53+
var component = declaration.QualifiedName.QualifiedModuleName.Component;
54+
if (component.Type == vbext_ComponentType.vbext_ct_Document)
55+
{
56+
try
57+
{
58+
var parenthesizedName = component.Properties.Item("Name").Value.ToString();
59+
60+
if (ContainsBuiltinDocumentPropertiesProperty())
61+
{
62+
CodeExplorerItemViewModel node = this;
63+
while (node.Parent != null)
64+
{
65+
node = node.Parent;
66+
}
67+
68+
((CodeExplorerProjectViewModel) node).SetParenthesizedName(parenthesizedName);
69+
}
70+
else
71+
{
72+
_name += " (" + parenthesizedName + ")";
73+
}
74+
}
75+
catch
76+
{
77+
// gotcha! (this means that the property either doesn't exist or we weren't able to get it for some reason)
78+
}
79+
}
80+
}
81+
82+
private bool ContainsBuiltinDocumentPropertiesProperty()
83+
{
84+
var component = _declaration.QualifiedName.QualifiedModuleName.Component;
85+
86+
try
87+
{
88+
component.Properties.Item("BuiltinDocumentProperties");
89+
}
90+
catch
91+
{
92+
// gotcha! (this means that the property either doesn't exist or we weren't able to get it for some reason)
93+
return false;
94+
}
95+
96+
return true;
5197
}
5298

5399
private bool _isErrorState;
@@ -62,8 +108,9 @@ public bool IsTestModule
62108
}
63109
}
64110

65-
public override string Name { get { return _declaration.IdentifierName; } }
66-
public override string NameWithSignature { get { return Name; } }
111+
private readonly string _name;
112+
public override string Name { get { return _name; } }
113+
public override string NameWithSignature { get { return _name; } }
67114

68115
public override QualifiedSelection? QualifiedSelection { get { return _declaration.QualifiedSelection; } }
69116

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerProjectViewModel.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class CodeExplorerProjectViewModel : CodeExplorerItemViewModel, ICodeExpl
2727
public CodeExplorerProjectViewModel(FolderHelper folderHelper, Declaration declaration, IEnumerable<Declaration> declarations)
2828
{
2929
_declaration = declaration;
30+
_name = _declaration.IdentifierName;
3031
IsExpanded = true;
3132
_folderTree = folderHelper.GetFolderTree(declaration);
3233

@@ -43,11 +44,6 @@ public CodeExplorerProjectViewModel(FolderHelper folderHelper, Declaration decla
4344
{
4445
Console.WriteLine(e);
4546
}
46-
47-
foreach (var folder in _folderTree.Items.OfType<CodeExplorerCustomFolderViewModel>())
48-
{
49-
folder.SetParent(this);
50-
}
5147
}
5248

5349
private void FillFolders(IEnumerable<Declaration> declarations)
@@ -72,6 +68,11 @@ private bool AddNodesToTree(CodeExplorerCustomFolderViewModel tree, List<Declara
7268
continue;
7369
}
7470

71+
if (folder.Parent.Name == string.Empty)
72+
{
73+
folder.SetParent(this);
74+
}
75+
7576
var parents = grouping.Where(
7677
item => ComponentTypes.Contains(item.DeclarationType) &&
7778
item.CustomFolder.Replace("\"", string.Empty) == folder.FullPath)
@@ -94,8 +95,14 @@ private bool AddNodesToTree(CodeExplorerCustomFolderViewModel tree, List<Declara
9495
// projects are always at the top of the tree
9596
public override CodeExplorerItemViewModel Parent { get { return null; } }
9697

97-
public override string Name { get { return _declaration.IdentifierName; } }
98-
public override string NameWithSignature { get { return Name; } }
98+
private string _name;
99+
public override string Name { get { return _name; } }
100+
public override string NameWithSignature { get { return _name; } }
99101
public override QualifiedSelection? QualifiedSelection { get { return _declaration.QualifiedSelection; } }
102+
103+
public void SetParenthesizedName(string parenthesizedName)
104+
{
105+
_name += " (" + parenthesizedName + ")";
106+
}
100107
}
101108
}

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Windows.Input;
66
using System.Windows.Threading;
7+
using Microsoft.Vbe.Interop;
78
using Rubberduck.Navigation.Folders;
89
using Rubberduck.Parsing.Symbols;
910
using Rubberduck.Parsing.VBA;
@@ -218,7 +219,7 @@ private void ParserState_StateChanged(object sender, EventArgs e)
218219
{
219220
return;
220221
}
221-
222+
222223
var userDeclarations = _state.AllUserDeclarations
223224
.GroupBy(declaration => declaration.Project)
224225
.Where(grouping => grouping.Key != null)
@@ -230,6 +231,9 @@ private void ParserState_StateChanged(object sender, EventArgs e)
230231
return;
231232
}
232233

234+
235+
var components = userDeclarations.SelectMany(s => s.Key.VBComponents.Cast<VBComponent>()).FirstOrDefault(s => s.Name == "asdf");
236+
233237
var newProjects = userDeclarations.Select(grouping =>
234238
new CodeExplorerProjectViewModel(_folderHelper,
235239
grouping.SingleOrDefault(declaration => declaration.DeclarationType == DeclarationType.Project),

0 commit comments

Comments
 (0)