Skip to content

Commit bae177d

Browse files
committed
Match target project by ID, not name.
1 parent 8d1cbad commit bae177d

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

Rubberduck.Core/UI/Command/AddRemoveReferencesCommand.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.InteropServices;
1+
using System.Linq;
2+
using System.Runtime.InteropServices;
23
using NLog;
34
using Rubberduck.AddRemoveReferences;
45
using Rubberduck.Navigation.CodeExplorer;
@@ -37,7 +38,7 @@ protected override void OnExecute(object parameter)
3738
}
3839

3940
var declaration = parameter is CodeExplorerItemViewModel explorerItem
40-
? GetDeclaration(explorerItem)
41+
? explorerItem.Declaration
4142
: GetDeclaration();
4243

4344
if (!(Declaration.GetProjectParent(declaration) is ProjectDeclaration project))
@@ -46,7 +47,8 @@ protected override void OnExecute(object parameter)
4647
}
4748

4849
var dialog = _factory.Create(project);
49-
var model = dialog.Show();
50+
51+
var model = dialog?.Show();
5052
if (model is null)
5153
{
5254
return;
@@ -65,7 +67,7 @@ protected override bool EvaluateCanExecute(object parameter)
6567

6668
if (parameter is CodeExplorerItemViewModel explorerNode)
6769
{
68-
return GetDeclaration(explorerNode) is ProjectDeclaration;
70+
return explorerNode.Declaration is ProjectDeclaration;
6971
}
7072

7173
using (var project = _vbe.ActiveVBProject)
@@ -74,16 +76,6 @@ protected override bool EvaluateCanExecute(object parameter)
7476
}
7577
}
7678

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-
8779
private Declaration GetDeclaration()
8880
{
8981
using (var project = _vbe.ActiveVBProject)
@@ -92,7 +84,9 @@ private Declaration GetDeclaration()
9284
{
9385
return null;
9486
}
95-
return _state.DeclarationFinder.FindProject(project.Name);
87+
88+
return _state.DeclarationFinder.Projects.OfType<ProjectDeclaration>()
89+
.FirstOrDefault(declaration => project.ProjectId.Equals(declaration.ProjectId));
9690
}
9791
}
9892
}

0 commit comments

Comments
 (0)