File tree Expand file tree Collapse file tree 4 files changed +42
-5
lines changed
UI/Command/MenuItems/ParentMenus
RubberduckTests/SmartIndenter Expand file tree Collapse file tree 4 files changed +42
-5
lines changed Original file line number Diff line number Diff line change @@ -188,6 +188,12 @@ public void Detach()
188
188
189
189
private void hook_MessageReceived ( object sender , HookEventArgs e )
190
190
{
191
+ var active = User32 . GetForegroundWindow ( ) ;
192
+ if ( active != _mainWindowHandle )
193
+ {
194
+ return ;
195
+ }
196
+
191
197
var hotkey = sender as IHotkey ;
192
198
if ( hotkey != null )
193
199
{
Original file line number Diff line number Diff line change @@ -86,15 +86,13 @@ public void RemoveChildren()
86
86
{
87
87
foreach ( var child in _items . Keys . Select ( item => item as IParentMenuItem ) . Where ( child => child != null ) )
88
88
{
89
- Debug . WriteLine ( "Deleting menu item {0}." , child . Caption ) ;
90
89
child . RemoveChildren ( ) ;
91
90
Debug . Assert ( _items [ child ] is CommandBarPopup ) ;
92
91
( _items [ child ] as CommandBarPopup ) . Delete ( ) ;
93
92
}
94
93
foreach ( var child in _items . Values . Select ( item => item as CommandBarButton ) . Where ( child => child != null ) )
95
94
{
96
95
child . Click -= child_Click ;
97
- Debug . WriteLine ( "Deleting child menu item {0}." , child . Caption ) ;
98
96
child . Delete ( ) ;
99
97
}
100
98
}
Original file line number Diff line number Diff line change @@ -19,11 +19,11 @@ internal class AbsoluteCodeLine
19
19
private static readonly Regex ProcedureEndRegex = new Regex ( @"^End\s(Sub|Function|Property)" ) ;
20
20
private static readonly Regex TypeEnumStartRegex = new Regex ( @"^(Public\s|Private\s)?(Enum\s|Type\s)" ) ;
21
21
private static readonly Regex TypeEnumEndRegex = new Regex ( @"^End\s(Enum|Type)" ) ;
22
- private static readonly Regex InProcedureInRegex = new Regex ( @"^If\s.*\sThen|^ElseIf\s.+\sThen$ |^Else$|^Case\s|^With|^For\s|^Do$|^Do\s|^While$|^While\s|^Select Case" ) ;
23
- private static readonly Regex InProcedureOutRegex = new Regex ( @"^(Else)? If\s.*\sThen\s|^Else$|^Case\s|^End With|^Next\s|^Next$|^Loop$|^Loop\s|^Wend$|^End If$|^End Select" ) ;
22
+ private static readonly Regex InProcedureInRegex = new Regex ( @"^(Else)? If\s.*\sThen|^Else$|^Case\s|^With|^For\s|^Do$|^Do\s|^While$|^While\s|^Select Case" ) ;
23
+ private static readonly Regex InProcedureOutRegex = new Regex ( @"^If\s.*\sThen\s|^Else$|^ElseIf\s.*\sThen |^Case\s|^End With|^Next\s|^Next$|^Loop$|^Loop\s|^Wend$|^End If$|^End Select" ) ;
24
24
private static readonly Regex DeclarationRegex = new Regex ( @"^(Dim|Const|Static|Public|Private)\s.*\sAs\s" ) ;
25
25
private static readonly Regex PrecompilerInRegex = new Regex ( @"^#(Else)?If\s.+Then$|^#Else$" ) ;
26
- private static readonly Regex PrecompilerOutRegex = new Regex ( @"^#ElseIf\s.+Then$ |^#Else$|#End\sIf$" ) ;
26
+ private static readonly Regex PrecompilerOutRegex = new Regex ( @"^#ElseIf\s.+Then|^#Else$|#End\sIf$" ) ;
27
27
private static readonly Regex SingleLineIfRegex = new Regex ( @"^If\s.*\sThen\s.*$" ) ;
28
28
29
29
private readonly IIndenterSettings _settings ;
Original file line number Diff line number Diff line change @@ -48,6 +48,39 @@ public void SingleLineIfStatementWorks()
48
48
Assert . IsTrue ( expected . SequenceEqual ( actual ) ) ;
49
49
}
50
50
51
+ [ TestMethod ]
52
+ [ TestCategory ( "Indenter" ) ]
53
+ public void ElseIfStatementWorks ( )
54
+ {
55
+ var code = new [ ]
56
+ {
57
+ "Public Function Test() As Integer" ,
58
+ "If Foo = 1 Then" ,
59
+ "Bar = 3" ,
60
+ "ElseIf Foo = 3 Then" ,
61
+ "Bar = 1" ,
62
+ "End If" ,
63
+ "Test = Bar" ,
64
+ "End Function"
65
+ } ;
66
+
67
+ var expected = new [ ]
68
+ {
69
+ "Public Function Test() As Integer" ,
70
+ " If Foo = 1 Then" ,
71
+ " Bar = 3" ,
72
+ " ElseIf Foo = 3 Then" ,
73
+ " Bar = 1" ,
74
+ " End If" ,
75
+ " Test = Bar" ,
76
+ "End Function"
77
+ } ;
78
+
79
+ var indenter = new Indenter ( null , ( ) => IndenterSettingsTests . GetMockIndenterSettings ( ) ) ;
80
+ var actual = indenter . Indent ( code , string . Empty ) ;
81
+ Assert . IsTrue ( expected . SequenceEqual ( actual ) ) ;
82
+ }
83
+
51
84
[ TestMethod ]
52
85
[ TestCategory ( "Indenter" ) ]
53
86
public void SingleLineElseIfStatementWorks ( )
You can’t perform that action at this time.
0 commit comments