Skip to content

Commit c13d151

Browse files
authored
Merge pull request #4458 from bclothier/HostApplicationDocument
Host application document
2 parents 7c7bd25 + 72d11a4 commit c13d151

File tree

24 files changed

+611
-554
lines changed

24 files changed

+611
-554
lines changed

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerComponentViewModel.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
using System.Linq;
55
using System.Runtime.InteropServices;
66
using System.Windows.Media.Imaging;
7+
using NLog;
78
using Rubberduck.Parsing.Symbols;
89
using Rubberduck.VBEditor;
910
using Rubberduck.Parsing.Annotations;
1011
using Rubberduck.VBEditor.ComManagement;
1112
using Rubberduck.VBEditor.SafeComWrappers;
1213
using Rubberduck.Resources.CodeExplorer;
14+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
1315

1416
namespace Rubberduck.Navigation.CodeExplorer
1517
{
@@ -36,13 +38,15 @@ public class CodeExplorerComponentViewModel : CodeExplorerItemViewModel, ICodeEx
3638
};
3739

3840
private readonly IProjectsProvider _projectsProvider;
41+
private readonly IVBE _vbe;
3942

40-
public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declaration declaration, IEnumerable<Declaration> declarations, IProjectsProvider projectsProvider)
43+
public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declaration declaration, IEnumerable<Declaration> declarations, IProjectsProvider projectsProvider, IVBE vbe)
4144
{
4245
Parent = parent;
4346
Declaration = declaration;
4447
_projectsProvider = projectsProvider;
45-
48+
_vbe = vbe;
49+
4650
_icon = Icons.ContainsKey(DeclarationType)
4751
? Icons[DeclarationType]
4852
: GetImageSource(CodeExplorerUI.status_offline);
@@ -65,15 +69,19 @@ public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declarat
6569
switch (qualifiedModuleName.ComponentType)
6670
{
6771
case ComponentType.Document:
68-
var component = _projectsProvider.Component(qualifiedModuleName);
69-
string parenthesizedName;
70-
using (var properties = component.Properties)
71-
using (var nameProperty = properties["Name"])
72+
var parenthesizedName = string.Empty;
73+
var state = DocumentState.Inaccessible;
74+
using (var app = _vbe.HostApplication())
7275
{
73-
parenthesizedName = nameProperty.Value.ToString() ?? string.Empty;
76+
if (app != null)
77+
{
78+
var document = app.GetDocument(qualifiedModuleName);
79+
parenthesizedName = document?.DocumentName ?? string.Empty;
80+
state = document?.State ?? DocumentState.Inaccessible;
81+
}
7482
}
75-
76-
if (ContainsBuiltinDocumentPropertiesProperty())
83+
84+
if (state == DocumentState.DesignView && ContainsBuiltinDocumentPropertiesProperty())
7785
{
7886
CodeExplorerItemViewModel node = this;
7987
while (node.Parent != null)
@@ -85,7 +93,10 @@ public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declarat
8593
}
8694
else
8795
{
88-
_name += " (" + parenthesizedName + ")";
96+
if (!string.IsNullOrWhiteSpace(parenthesizedName))
97+
{
98+
_name += " (" + parenthesizedName + ")";
99+
}
89100
}
90101
break;
91102

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerCustomFolderViewModel.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Rubberduck.Parsing.Symbols;
66
using Rubberduck.VBEditor;
77
using Rubberduck.VBEditor.ComManagement;
8+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
89

910
namespace Rubberduck.Navigation.CodeExplorer
1011
{
@@ -19,11 +20,14 @@ public class CodeExplorerCustomFolderViewModel : CodeExplorerItemViewModel
1920
};
2021

2122
private readonly IProjectsProvider _projectsProvider;
23+
private readonly IVBE _vbe;
2224

23-
public CodeExplorerCustomFolderViewModel(CodeExplorerItemViewModel parent, string name, string fullPath, IProjectsProvider projectsProvider)
25+
public CodeExplorerCustomFolderViewModel(CodeExplorerItemViewModel parent, string name, string fullPath, IProjectsProvider projectsProvider, IVBE vbe)
2426
{
2527
_parent = parent;
2628
_projectsProvider = projectsProvider;
29+
_vbe = vbe;
30+
2731
FullPath = fullPath;
2832
Name = name.Replace("\"", string.Empty);
2933
FolderAttribute = string.Format("@Folder(\"{0}\")", fullPath.Replace("\"", string.Empty));
@@ -45,7 +49,7 @@ public void AddNodes(List<Declaration> declarations)
4549
var members = declarations.Where(item =>
4650
!ComponentTypes.Contains(item.DeclarationType) && item.ComponentName == moduleName);
4751

48-
AddChild(new CodeExplorerComponentViewModel(this, parent, members, _projectsProvider));
52+
AddChild(new CodeExplorerComponentViewModel(this, parent, members, _projectsProvider, _vbe));
4953
}
5054
catch (InvalidOperationException exception)
5155
{

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,13 @@ private void ParserState_ModuleStateChanged(object sender, ParseProgressEventArg
382382
{
383383
if (folderNode == null)
384384
{
385-
folderNode = new CodeExplorerCustomFolderViewModel(projectNode, projectName, projectName, _state.ProjectsProvider);
385+
folderNode = new CodeExplorerCustomFolderViewModel(projectNode, projectName, projectName, _state.ProjectsProvider, _vbe);
386386
projectNode.AddChild(folderNode);
387387
}
388388

389389
var declaration = CreateDeclaration(e.Module);
390390
var newNode =
391-
new CodeExplorerComponentViewModel(folderNode, declaration, new List<Declaration>(), _state.ProjectsProvider)
391+
new CodeExplorerComponentViewModel(folderNode, declaration, new List<Declaration>(), _state.ProjectsProvider, _vbe)
392392
{
393393
IsErrorState = true
394394
};

Rubberduck.Core/Navigation/Folders/FolderHelper.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
using Rubberduck.Navigation.CodeExplorer;
33
using Rubberduck.Parsing.Symbols;
44
using Rubberduck.Parsing.VBA;
5+
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
56

67
namespace Rubberduck.Navigation.Folders
78
{
89
public class FolderHelper
910
{
1011
private readonly RubberduckParserState _state;
12+
private readonly IVBE _vbe;
1113

1214
private static readonly DeclarationType[] ComponentTypes =
1315
{
@@ -17,13 +19,17 @@ public class FolderHelper
1719
DeclarationType.UserForm,
1820
};
1921

20-
public FolderHelper(RubberduckParserState state) => _state = state;
22+
public FolderHelper(RubberduckParserState state, IVBE vbe)
23+
{
24+
_state = state;
25+
_vbe = vbe;
26+
}
2127

2228
public CodeExplorerCustomFolderViewModel GetFolderTree(Declaration declaration = null)
2329
{
2430
var delimiter = GetDelimiter();
2531

26-
var root = new CodeExplorerCustomFolderViewModel(null, string.Empty, string.Empty, _state.ProjectsProvider);
32+
var root = new CodeExplorerCustomFolderViewModel(null, string.Empty, string.Empty, _state.ProjectsProvider, _vbe);
2733

2834
var items = declaration == null
2935
? _state.AllUserDeclarations.ToList()
@@ -46,7 +52,7 @@ public CodeExplorerCustomFolderViewModel GetFolderTree(Declaration declaration =
4652
var node = currentNode.Items.FirstOrDefault(i => i.Name == section);
4753
if (node == null)
4854
{
49-
node = new CodeExplorerCustomFolderViewModel(currentNode, section, fullPath, _state.ProjectsProvider);
55+
node = new CodeExplorerCustomFolderViewModel(currentNode, section, fullPath, _state.ProjectsProvider, _vbe);
5056
currentNode.AddChild(node);
5157
}
5258

Rubberduck.Core/Properties/Settings.Designer.cs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
using System.Reflection;
2-
using System.Runtime.InteropServices;
1+
using System.Runtime.InteropServices;
32
using System.Runtime.CompilerServices;
43

54
[assembly: InternalsVisibleTo("RubberduckTests")]
65

6+
//Allow Rubberduck.VBEditor.* projects to use internal class
7+
[assembly: InternalsVisibleTo("Rubberduck.VBEditor.VB6")]
8+
[assembly: InternalsVisibleTo("Rubberduck.VBEditor.VBA")]
9+
710
// The following GUID is for the ID of the typelib if this project is exposed to COM
811
[assembly: Guid("4758424b-266e-4a3a-83c6-4aa50af7ea9e")]
912
[assembly: ComVisible(false)]

0 commit comments

Comments
 (0)