Skip to content

Commit 1b691e6

Browse files
authored
Merge pull request #6106 from awb95/next
Respect @NoIndent-Annotaions for Indent current project and module
2 parents fe006d8 + 4650727 commit 1b691e6

File tree

6 files changed

+336
-240
lines changed

6 files changed

+336
-240
lines changed

Rubberduck.Core/UI/Command/ComCommands/IndentCurrentModuleCommand.cs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
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;
26
using Rubberduck.Parsing.VBA;
37
using Rubberduck.SmartIndenter;
48
using Rubberduck.VBEditor.Events;
@@ -12,17 +16,20 @@ public class IndentCurrentModuleCommand : ComCommandBase
1216
private readonly IVBE _vbe;
1317
private readonly IIndenter _indenter;
1418
private readonly RubberduckParserState _state;
19+
private readonly IMessageBox _messageBox;
1520

1621
public IndentCurrentModuleCommand(
1722
IVBE vbe,
1823
IIndenter indenter,
1924
RubberduckParserState state,
20-
IVbeEvents vbeEvents)
25+
IVbeEvents vbeEvents,
26+
IMessageBox messageBox)
2127
: base(vbeEvents)
2228
{
2329
_vbe = vbe;
2430
_indenter = indenter;
2531
_state = state;
32+
_messageBox = messageBox;
2633

2734
AddToCanExecuteEvaluation(SpecialEvaluateCanExecute);
2835
}
@@ -36,8 +43,32 @@ private bool SpecialEvaluateCanExecute(object parameter)
3643
}
3744

3845
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+
4172
if (_state.Status >= ParserState.Ready || _state.Status == ParserState.Pending)
4273
{
4374
_state.OnParseRequested(this);

Rubberduck.Core/UI/Command/ComCommands/IndentCurrentProjectCommand.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
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;
26
using Rubberduck.Parsing.VBA;
37
using Rubberduck.SmartIndenter;
48
using Rubberduck.VBEditor.Events;
@@ -13,17 +17,20 @@ public class IndentCurrentProjectCommand : ComCommandBase
1317
private readonly IVBE _vbe;
1418
private readonly IIndenter _indenter;
1519
private readonly RubberduckParserState _state;
20+
private readonly IMessageBox _messageBox;
1621

1722
public IndentCurrentProjectCommand(
1823
IVBE vbe,
1924
IIndenter indenter,
2025
RubberduckParserState state,
21-
IVbeEvents vbeEvents)
26+
IVbeEvents vbeEvents,
27+
IMessageBox messageBox)
2228
: base(vbeEvents)
2329
{
2430
_vbe = vbe;
2531
_indenter = indenter;
2632
_state = state;
33+
_messageBox = messageBox;
2734

2835
AddToCanExecuteEvaluation(SpecialEvaluateCanExecute);
2936
}
@@ -39,7 +46,29 @@ private bool SpecialEvaluateCanExecute(object parameter)
3946

4047
protected override void OnExecute(object parameter)
4148
{
42-
_indenter.IndentCurrentProject();
49+
if (_state.IsDirty())
50+
{
51+
if (!_messageBox.ConfirmYesNo(
52+
Resources.RubberduckUI.Indenter_ContinueIndentWithoutAnnotations,
53+
Resources.RubberduckUI.Indenter_ContinueIndentWithoutAnnotations_DialogCaption,
54+
false))
55+
return;
56+
57+
_indenter.IndentCurrentProject();
58+
}
59+
else
60+
{
61+
var componentDeclarations = _state.AllUserDeclarations.Where(c =>
62+
c.DeclarationType.HasFlag(DeclarationType.Module) &&
63+
!c.Annotations.Any(pta => pta.Annotation is NoIndentAnnotation) &&
64+
c.ProjectId == _vbe.ActiveVBProject.ProjectId);
65+
66+
foreach (var componentDeclaration in componentDeclarations)
67+
{
68+
_indenter.Indent(_state.ProjectsProvider.Component(componentDeclaration.QualifiedName.QualifiedModuleName));
69+
}
70+
}
71+
4372
if (_state.Status >= ParserState.Ready || _state.Status == ParserState.Pending)
4473
{
4574
_state.OnParseRequested(this);

0 commit comments

Comments
 (0)