1
- using System . Runtime . InteropServices ;
1
+ using System . Linq ;
2
+ using System . Runtime . InteropServices ;
3
+ using Rubberduck . Interaction ;
4
+ using Rubberduck . Parsing . Annotations . Concrete ;
5
+ using Rubberduck . Parsing . Symbols ;
2
6
using Rubberduck . Parsing . VBA ;
3
7
using Rubberduck . SmartIndenter ;
4
8
using Rubberduck . VBEditor . Events ;
@@ -12,17 +16,20 @@ public class IndentCurrentModuleCommand : ComCommandBase
12
16
private readonly IVBE _vbe ;
13
17
private readonly IIndenter _indenter ;
14
18
private readonly RubberduckParserState _state ;
19
+ private readonly IMessageBox _messageBox ;
15
20
16
21
public IndentCurrentModuleCommand (
17
22
IVBE vbe ,
18
23
IIndenter indenter ,
19
24
RubberduckParserState state ,
20
- IVbeEvents vbeEvents )
25
+ IVbeEvents vbeEvents ,
26
+ IMessageBox messageBox )
21
27
: base ( vbeEvents )
22
28
{
23
29
_vbe = vbe ;
24
30
_indenter = indenter ;
25
31
_state = state ;
32
+ _messageBox = messageBox ;
26
33
27
34
AddToCanExecuteEvaluation ( SpecialEvaluateCanExecute ) ;
28
35
}
@@ -36,8 +43,32 @@ private bool SpecialEvaluateCanExecute(object parameter)
36
43
}
37
44
38
45
protected override void OnExecute ( object parameter )
39
- {
40
- _indenter . IndentCurrentModule ( ) ;
46
+ {
47
+ if ( _state . IsDirty ( ) )
48
+ {
49
+ if ( ! _messageBox . ConfirmYesNo (
50
+ Resources . RubberduckUI . Indenter_ContinueIndentWithoutAnnotations ,
51
+ Resources . RubberduckUI . Indenter_ContinueIndentWithoutAnnotations_DialogCaption ,
52
+ false ) )
53
+ return ;
54
+
55
+ _indenter . IndentCurrentModule ( ) ;
56
+ }
57
+ else
58
+ {
59
+ var componentDeclarations = _state . AllUserDeclarations . Where ( c =>
60
+ c . DeclarationType . HasFlag ( DeclarationType . Module ) &&
61
+ ! c . Annotations . Any ( pta => pta . Annotation is NoIndentAnnotation ) &&
62
+ c . ProjectId == _vbe . ActiveVBProject . ProjectId &&
63
+ c . QualifiedModuleName == _vbe . ActiveCodePane . QualifiedModuleName
64
+ ) ;
65
+
66
+ foreach ( var componentDeclaration in componentDeclarations )
67
+ {
68
+ _indenter . Indent ( _state . ProjectsProvider . Component ( componentDeclaration . QualifiedName . QualifiedModuleName ) ) ;
69
+ }
70
+ }
71
+
41
72
if ( _state . Status >= ParserState . Ready || _state . Status == ParserState . Pending )
42
73
{
43
74
_state . OnParseRequested ( this ) ;
0 commit comments