Skip to content

Commit 8850bbd

Browse files
committed
Working implementation of CanExecute for Implement Interface
1 parent 985f3b3 commit 8850bbd

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Diagnostics;
21
using System.Linq;
32
using Microsoft.Vbe.Interop;
43
using System.Runtime.InteropServices;
@@ -7,7 +6,6 @@
76
using Rubberduck.Parsing.VBA;
87
using Rubberduck.Refactorings.ImplementInterface;
98
using Rubberduck.VBEditor;
10-
using Rubberduck.VBEditor.VBEInterfaces.RubberduckCodePane;
119

1210
namespace Rubberduck.UI.Command.Refactorings
1311
{
@@ -29,30 +27,28 @@ public override bool CanExecute(object parameter)
2927
return false;
3028
}
3129

32-
//var target = _state.FindSelectedDeclaration(Vbe.ActiveCodePane); // nope. logic is a bit more complex here.
30+
var selection = Editor.GetSelection();
3331

34-
var selection = Vbe.ActiveCodePane.GetSelection();
35-
var targetInterface = _state.AllUserDeclarations.FindInterface(selection);
32+
if (!selection.HasValue)
33+
{
34+
return false;
35+
}
36+
37+
var targetInterface = _state.AllUserDeclarations.FindInterface(selection.Value);
3638

3739
var targetClass = _state.AllUserDeclarations.SingleOrDefault(d =>
3840
!d.IsBuiltIn && d.DeclarationType == DeclarationType.ClassModule &&
39-
d.QualifiedSelection.QualifiedName.Equals(selection.QualifiedName));
40-
41-
var canExecute = targetInterface != null && targetClass != null;
41+
d.QualifiedSelection.QualifiedName.Equals(selection.Value.QualifiedName));
4242

43-
Debug.WriteLine("{0}.CanExecute evaluates to {1}", GetType().Name, canExecute);
44-
return canExecute;
43+
return targetClass != null && targetInterface != null;
4544
}
4645

4746
public override void Execute(object parameter)
4847
{
49-
if (Vbe.ActiveCodePane == null)
50-
{
51-
return;
52-
}
53-
5448
var refactoring = new ImplementInterfaceRefactoring(_state, Editor, new MessageBox());
55-
refactoring.Refactor();
49+
50+
// ReSharper disable once PossibleInvalidOperationException
51+
refactoring.Refactor(Editor.GetSelection().Value);
5652
}
5753
}
5854
}

0 commit comments

Comments
 (0)