1
- using System . Runtime . InteropServices ;
1
+ using System . Linq ;
2
+ using System . Runtime . InteropServices ;
2
3
using NLog ;
3
4
using Rubberduck . AddRemoveReferences ;
4
5
using Rubberduck . Navigation . CodeExplorer ;
@@ -37,7 +38,7 @@ protected override void OnExecute(object parameter)
37
38
}
38
39
39
40
var declaration = parameter is CodeExplorerItemViewModel explorerItem
40
- ? GetDeclaration ( explorerItem )
41
+ ? explorerItem . Declaration
41
42
: GetDeclaration ( ) ;
42
43
43
44
if ( ! ( Declaration . GetProjectParent ( declaration ) is ProjectDeclaration project ) )
@@ -46,7 +47,8 @@ protected override void OnExecute(object parameter)
46
47
}
47
48
48
49
var dialog = _factory . Create ( project ) ;
49
- var model = dialog . Show ( ) ;
50
+
51
+ var model = dialog ? . Show ( ) ;
50
52
if ( model is null )
51
53
{
52
54
return ;
@@ -65,7 +67,7 @@ protected override bool EvaluateCanExecute(object parameter)
65
67
66
68
if ( parameter is CodeExplorerItemViewModel explorerNode )
67
69
{
68
- return GetDeclaration ( explorerNode ) is ProjectDeclaration ;
70
+ return explorerNode . Declaration is ProjectDeclaration ;
69
71
}
70
72
71
73
using ( var project = _vbe . ActiveVBProject )
@@ -74,16 +76,6 @@ protected override bool EvaluateCanExecute(object parameter)
74
76
}
75
77
}
76
78
77
- private Declaration GetDeclaration ( CodeExplorerItemViewModel node )
78
- {
79
- while ( node != null && ! ( node is ICodeExplorerDeclarationViewModel ) )
80
- {
81
- node = node . Parent ;
82
- }
83
-
84
- return ( node as ICodeExplorerDeclarationViewModel ) ? . Declaration ;
85
- }
86
-
87
79
private Declaration GetDeclaration ( )
88
80
{
89
81
using ( var project = _vbe . ActiveVBProject )
@@ -92,7 +84,9 @@ private Declaration GetDeclaration()
92
84
{
93
85
return null ;
94
86
}
95
- return _state . DeclarationFinder . FindProject ( project . Name ) ;
87
+
88
+ return _state . DeclarationFinder . Projects . OfType < ProjectDeclaration > ( )
89
+ . FirstOrDefault ( declaration => project . ProjectId . Equals ( declaration . ProjectId ) ) ;
96
90
}
97
91
}
98
92
}
0 commit comments