5
5
using Rubberduck . Parsing . VBA ;
6
6
using Rubberduck . Refactorings . MoveCloserToUsage ;
7
7
using Rubberduck . VBEditor . SafeComWrappers . Abstract ;
8
+ using Rubberduck . VBEditor . Utility ;
8
9
9
10
namespace Rubberduck . UI . Command . Refactorings
10
11
{
@@ -13,41 +14,46 @@ public class RefactorMoveCloserToUsageCommand : RefactorCommandBase
13
14
private readonly RubberduckParserState _state ;
14
15
private readonly IRewritingManager _rewritingManager ;
15
16
private readonly IMessageBox _msgbox ;
17
+ private readonly ISelectionService _selectionService ;
16
18
17
- public RefactorMoveCloserToUsageCommand ( IVBE vbe , RubberduckParserState state , IMessageBox msgbox , IRewritingManager rewritingManager )
19
+ public RefactorMoveCloserToUsageCommand ( IVBE vbe , RubberduckParserState state , IMessageBox msgbox , IRewritingManager rewritingManager , ISelectionService selectionService )
18
20
: base ( vbe )
19
21
{
20
22
_state = state ;
21
23
_rewritingManager = rewritingManager ;
22
24
_msgbox = msgbox ;
25
+ _selectionService = selectionService ;
23
26
}
24
27
25
28
protected override bool EvaluateCanExecute ( object parameter )
26
29
{
27
- using ( var activePane = Vbe . ActiveCodePane )
30
+ if ( _state . Status != ParserState . Ready )
28
31
{
29
- if ( activePane == null || activePane . IsWrappingNullReference || _state . Status != ParserState . Ready )
30
- {
31
- return false ;
32
- }
32
+ return false ;
33
+ }
33
34
34
- var target = _state . FindSelectedDeclaration ( activePane ) ;
35
- return target != null
36
- && ! _state . IsNewOrModified ( target . QualifiedModuleName )
37
- && ( target . DeclarationType == DeclarationType . Variable ||
38
- target . DeclarationType == DeclarationType . Constant )
39
- && target . References . Any ( ) ;
35
+ var activeSelection = _selectionService . ActiveSelection ( ) ;
36
+ if ( ! activeSelection . HasValue )
37
+ {
38
+ return false ;
40
39
}
40
+
41
+ var target = _state . DeclarationFinder . FindSelectedDeclaration ( activeSelection . Value ) ;
42
+ return target != null
43
+ && ! _state . IsNewOrModified ( target . QualifiedModuleName )
44
+ && ( target . DeclarationType == DeclarationType . Variable
45
+ || target . DeclarationType == DeclarationType . Constant )
46
+ && target . References . Any ( ) ;
41
47
}
42
48
43
49
protected override void OnExecute ( object parameter )
44
50
{
45
- var selection = Vbe . GetActiveSelection ( ) ;
51
+ var activeSelection = _selectionService . ActiveSelection ( ) ;
46
52
47
- if ( selection . HasValue )
53
+ if ( activeSelection . HasValue )
48
54
{
49
- var refactoring = new MoveCloserToUsageRefactoring ( Vbe , _state , _msgbox , _rewritingManager ) ;
50
- refactoring . Refactor ( selection . Value ) ;
55
+ var refactoring = new MoveCloserToUsageRefactoring ( _state , _msgbox , _rewritingManager , _selectionService ) ;
56
+ refactoring . Refactor ( activeSelection . Value ) ;
51
57
}
52
58
}
53
59
}
0 commit comments