Skip to content

Commit 029eb5b

Browse files
committed
Add support for different debug and stop statements to force to column one. Closes #4005
1 parent 8e102f7 commit 029eb5b

File tree

8 files changed

+424
-81
lines changed

8 files changed

+424
-81
lines changed

Rubberduck.Core/UI/Settings/IndenterSettings.xaml

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
4-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5-
xmlns:settings="clr-namespace:Rubberduck.UI.Settings"
63
xmlns:converters="clr-namespace:Rubberduck.UI.Settings.Converters"
74
xmlns:controls="clr-namespace:Rubberduck.UI.Controls"
85
xmlns:core="clr-namespace:System;assembly=mscorlib"
96
xmlns:smartIndenter="clr-namespace:Rubberduck.SmartIndenter;assembly=Rubberduck.SmartIndenter"
10-
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
11-
x:Class="Rubberduck.UI.Settings.IndenterSettings">
7+
x:Class="Rubberduck.UI.Settings.IndenterSettings">
128
<UserControl.Resources>
139
<converters:EndOfLineCommentStyleToVisibilityConverter x:Key="EndOfLineCommentStyleToVisibility"/>
1410
<converters:EndOfLineCommentStyleToTextConverter x:Key="LocalizedEndOfLineCommentStyles"/>
@@ -30,7 +26,7 @@
3026
<Style>
3127
<Style.Resources>
3228
<Style TargetType="{x:Type Border}">
33-
<Setter Property="Border.CornerRadius" Value="5"/>
29+
<Setter Property="CornerRadius" Value="5"/>
3430
</Style>
3531
</Style.Resources>
3632
</Style>
@@ -248,6 +244,7 @@
248244
</Expander.Header>
249245
<StackPanel Margin="75,5,0,5">
250246
<CheckBox Margin="5,0,0,5"
247+
Name="ForceDebugStatementsInColumn1"
251248
HorizontalAlignment="Left"
252249
IsChecked="{Binding ForceDebugStatementsInColumn1,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
253250
<AccessText TextWrapping="WrapWithOverflow">
@@ -256,6 +253,30 @@
256253
</AccessText.Text>
257254
</AccessText>
258255
</CheckBox>
256+
<CheckBox Margin="25,0,0,5"
257+
HorizontalAlignment="Left"
258+
IsChecked="{Binding ForceDebugPrintInColumn1,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
259+
IsEnabled="{Binding ElementName=ForceDebugStatementsInColumn1,Path=IsChecked}">
260+
<AccessText TextWrapping="WrapWithOverflow">
261+
<AccessText.Text>Debug.Print</AccessText.Text>
262+
</AccessText>
263+
</CheckBox>
264+
<CheckBox Margin="25,0,0,5"
265+
HorizontalAlignment="Left"
266+
IsChecked="{Binding ForceDebugAssertInColumn1,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
267+
IsEnabled="{Binding ElementName=ForceDebugStatementsInColumn1,Path=IsChecked}">
268+
<AccessText TextWrapping="WrapWithOverflow">
269+
<AccessText.Text>Debug.Assert</AccessText.Text>
270+
</AccessText>
271+
</CheckBox>
272+
<CheckBox Margin="25,0,0,5"
273+
HorizontalAlignment="Left"
274+
IsChecked="{Binding ForceStopInColumn1,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
275+
IsEnabled="{Binding ElementName=ForceDebugStatementsInColumn1,Path=IsChecked}">
276+
<AccessText TextWrapping="WrapWithOverflow">
277+
<AccessText.Text>Stop</AccessText.Text>
278+
</AccessText>
279+
</CheckBox>
259280
<CheckBox Margin="5,0,0,5"
260281
HorizontalAlignment="Left"
261282
IsChecked="{Binding ForceCompilerDirectivesInColumn1,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">

Rubberduck.Core/UI/Settings/IndenterSettingsViewModel.cs

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public IndenterSettingsViewModel(Configuration config)
2121
_endOfLineCommentStyle = config.UserSettings.IndenterSettings.EndOfLineCommentStyle;
2222
_forceCompilerDirectivesInColumn1 = config.UserSettings.IndenterSettings.ForceCompilerDirectivesInColumn1;
2323
_forceDebugStatementsInColumn1 = config.UserSettings.IndenterSettings.ForceDebugStatementsInColumn1;
24+
_forceDebugPrintInColumn1 = config.UserSettings.IndenterSettings.ForceDebugPrintInColumn1;
25+
_forceDebugAssertInColumn1 = config.UserSettings.IndenterSettings.ForceDebugAssertInColumn1;
26+
_forceStopInColumn1 = config.UserSettings.IndenterSettings.ForceStopInColumn1;
2427
_ignoreOperatorsInContinuations = config.UserSettings.IndenterSettings.IgnoreOperatorsInContinuations;
2528
_indentCase = config.UserSettings.IndenterSettings.IndentCase;
2629
_indentCompilerDirectives = config.UserSettings.IndenterSettings.IndentCompilerDirectives;
@@ -169,11 +172,69 @@ public bool ForceDebugStatementsInColumn1
169172
{
170173
if (_forceDebugStatementsInColumn1 != value)
171174
{
172-
_forceDebugStatementsInColumn1 = value;OnPropertyChanged();
175+
_forceDebugStatementsInColumn1 = value;
176+
ForceDebugPrintInColumn1 = _forceDebugStatementsInColumn1;
177+
ForceDebugAssertInColumn1 = _forceDebugStatementsInColumn1;
178+
ForceStopInColumn1 = _forceDebugStatementsInColumn1;
179+
OnPropertyChanged();
173180
}
174181
}
175182
}
176183

184+
private bool _forceDebugPrintInColumn1;
185+
public bool ForceDebugPrintInColumn1
186+
{
187+
get => _forceDebugPrintInColumn1;
188+
set
189+
{
190+
if (_forceDebugPrintInColumn1 != value)
191+
{
192+
_forceDebugPrintInColumn1 = value;
193+
if (!_forceDebugPrintInColumn1 && !_forceDebugAssertInColumn1 && !_forceStopInColumn1)
194+
{
195+
ForceDebugStatementsInColumn1 = false;
196+
}
197+
OnPropertyChanged();
198+
}
199+
}
200+
}
201+
202+
private bool _forceDebugAssertInColumn1;
203+
public bool ForceDebugAssertInColumn1
204+
{
205+
get => _forceDebugAssertInColumn1;
206+
set
207+
{
208+
if (_forceDebugAssertInColumn1 != value)
209+
{
210+
_forceDebugAssertInColumn1 = value;
211+
if (!_forceDebugPrintInColumn1 && !_forceDebugAssertInColumn1 && !_forceStopInColumn1)
212+
{
213+
ForceDebugStatementsInColumn1 = false;
214+
}
215+
OnPropertyChanged();
216+
}
217+
}
218+
}
219+
220+
private bool _forceStopInColumn1;
221+
public bool ForceStopInColumn1
222+
{
223+
get => _forceStopInColumn1;
224+
set
225+
{
226+
if (_forceStopInColumn1 != value)
227+
{
228+
_forceStopInColumn1 = value;
229+
if (!_forceDebugPrintInColumn1 && !_forceDebugAssertInColumn1 && !_forceStopInColumn1)
230+
{
231+
ForceDebugStatementsInColumn1 = false;
232+
}
233+
OnPropertyChanged();
234+
}
235+
}
236+
}
237+
177238
private bool _ignoreOperatorsInContinuations;
178239
public bool IgnoreOperatorsInContinuations
179240
{
@@ -300,21 +361,9 @@ public int LinesBetweenProcedures
300361
}
301362
}
302363

303-
public string PreviewSampleCode
304-
{
305-
get
306-
{
307-
var indenter = new Indenter(null, GetCurrentSettings);
308-
309-
var lines = RubberduckUI.IndenterSettings_PreviewCode.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
310-
lines = indenter.Indent(lines).ToArray();
311-
return string.Join(Environment.NewLine, lines);
312-
}
313-
}
314-
315364
private IIndenterSettings GetCurrentSettings()
316365
{
317-
return new SmartIndenter.IndenterSettings
366+
return new SmartIndenter.IndenterSettings(false)
318367
{
319368
AlignCommentsWithCode = AlignCommentsWithCode,
320369
AlignContinuations = AlignContinuations,
@@ -324,6 +373,9 @@ private IIndenterSettings GetCurrentSettings()
324373
EndOfLineCommentStyle = EndOfLineCommentStyle,
325374
ForceCompilerDirectivesInColumn1 = ForceCompilerDirectivesInColumn1,
326375
ForceDebugStatementsInColumn1 = ForceDebugStatementsInColumn1,
376+
ForceDebugPrintInColumn1 = ForceDebugPrintInColumn1,
377+
ForceDebugAssertInColumn1 = ForceDebugAssertInColumn1,
378+
ForceStopInColumn1 = ForceStopInColumn1,
327379
IgnoreOperatorsInContinuations = IgnoreOperatorsInContinuations,
328380
IndentCase = IndentCase,
329381
IndentCompilerDirectives = IndentCompilerDirectives,
@@ -349,6 +401,9 @@ public void UpdateConfig(Configuration config)
349401
config.UserSettings.IndenterSettings.EndOfLineCommentStyle = EndOfLineCommentStyle;
350402
config.UserSettings.IndenterSettings.ForceCompilerDirectivesInColumn1 = ForceCompilerDirectivesInColumn1;
351403
config.UserSettings.IndenterSettings.ForceDebugStatementsInColumn1 = ForceDebugStatementsInColumn1;
404+
config.UserSettings.IndenterSettings.ForceDebugPrintInColumn1 = ForceDebugPrintInColumn1;
405+
config.UserSettings.IndenterSettings.ForceDebugAssertInColumn1 = ForceDebugAssertInColumn1;
406+
config.UserSettings.IndenterSettings.ForceStopInColumn1 = ForceStopInColumn1;
352407
config.UserSettings.IndenterSettings.IgnoreOperatorsInContinuations = IgnoreOperatorsInContinuations;
353408
config.UserSettings.IndenterSettings.IndentCase = IndentCase;
354409
config.UserSettings.IndenterSettings.IndentEnumTypeAsProcedure = IndentEnumTypeAsProcedure;
@@ -376,6 +431,9 @@ private void TransferSettingsToView(IIndenterSettings toLoad)
376431
EndOfLineCommentStyle = toLoad.EndOfLineCommentStyle;
377432
ForceCompilerDirectivesInColumn1 = toLoad.ForceCompilerDirectivesInColumn1;
378433
ForceDebugStatementsInColumn1 = toLoad.ForceDebugStatementsInColumn1;
434+
ForceDebugPrintInColumn1 = toLoad.ForceDebugPrintInColumn1;
435+
ForceDebugAssertInColumn1 = toLoad.ForceDebugAssertInColumn1;
436+
ForceStopInColumn1 = toLoad.ForceStopInColumn1;
379437
IgnoreOperatorsInContinuations = toLoad.IgnoreOperatorsInContinuations;
380438
IndentCase = toLoad.IndentCase;
381439
IndentEnumTypeAsProcedure = toLoad.IndentEnumTypeAsProcedure;
@@ -399,7 +457,7 @@ private void ImportSettings()
399457
dialog.ShowDialog();
400458
if (string.IsNullOrEmpty(dialog.FileName)) return;
401459
var service = new XmlPersistanceService<SmartIndenter.IndenterSettings> { FilePath = dialog.FileName };
402-
var loaded = service.Load(new SmartIndenter.IndenterSettings());
460+
var loaded = service.Load(new SmartIndenter.IndenterSettings(false));
403461
TransferSettingsToView(loaded);
404462
}
405463
}

Rubberduck.SmartIndenter/AbsoluteCodeLine.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ public bool HasDeclarationContinuation
159159

160160
public bool IsPrecompilerDirective => _code.TrimStart().StartsWith("#");
161161

162-
public bool IsBareDebugStatement => _code.StartsWith("Debug.") || _code.Equals("Stop");
162+
public bool IsBareDebugPrintStatement => _code.StartsWith("Debug.Print");
163+
public bool IsBareDebugAssertStatement => _code.StartsWith("Debug.Assert");
164+
public bool IsBareStopStatement => _code.Equals("Stop");
163165

164166
public int EnumOrTypeStarts
165167
{
@@ -232,7 +234,9 @@ public string Indent(int indents, bool atProcStart, bool absolute = false)
232234
}
233235

234236
if ((IsPrecompilerDirective && _settings.ForceCompilerDirectivesInColumn1) ||
235-
(IsBareDebugStatement && _settings.ForceDebugStatementsInColumn1) ||
237+
(IsBareDebugPrintStatement && _settings.ForceDebugPrintInColumn1) ||
238+
(IsBareDebugAssertStatement && _settings.ForceDebugAssertInColumn1) ||
239+
(IsBareStopStatement && _settings.ForceStopInColumn1) ||
236240
(atProcStart && !_settings.IndentFirstCommentBlock && ContainsOnlyComment) ||
237241
(atProcStart && !_settings.IndentFirstDeclarationBlock && (IsDeclaration || IsDeclarationContinuation)))
238242
{

Rubberduck.SmartIndenter/IIndenterSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public interface IIndenterSettings
1111
bool IgnoreOperatorsInContinuations { get; set; }
1212
bool IndentCase { get; set; }
1313
bool ForceDebugStatementsInColumn1 { get; set; }
14+
bool ForceDebugPrintInColumn1 { get; set; }
15+
bool ForceDebugAssertInColumn1 { get; set; }
16+
bool ForceStopInColumn1 { get; set; }
1417
bool ForceCompilerDirectivesInColumn1 { get; set; }
1518
bool IndentCompilerDirectives { get; set; }
1619
bool AlignDims { get; set; }

Rubberduck.SmartIndenter/IndenterConfigProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public IndenterConfigProvider(IPersistanceService<IndenterSettings> persister)
1313

1414
public IndenterSettings Create()
1515
{
16-
var prototype = new IndenterSettings();
16+
var prototype = new IndenterSettings(false);
1717
return _persister.Load(prototype) ?? prototype;
1818
}
1919

2020
public IndenterSettings CreateDefaults()
2121
{
22-
return new IndenterSettings();
22+
return new IndenterSettings(false);
2323
}
2424

2525
public void Save(IndenterSettings settings)

Rubberduck.SmartIndenter/IndenterSettings.cs

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,62 @@ public class IndenterSettings : IIndenterSettings, IEquatable<IndenterSettings>
2121
public virtual bool AlignContinuations { get; set; }
2222
public virtual bool IgnoreOperatorsInContinuations { get; set; }
2323
public virtual bool IndentCase { get; set; }
24-
public virtual bool ForceDebugStatementsInColumn1 { get; set; }
24+
25+
private bool _forceDebugs;
26+
public virtual bool ForceDebugStatementsInColumn1
27+
{
28+
get => _forceDebugs;
29+
set
30+
{
31+
_forceDebugs = value;
32+
_forceDebugPrint = _forceDebugs;
33+
_forceDebugAssert = _forceDebugs;
34+
_forceStop = _forceDebugs;
35+
}
36+
}
37+
38+
private bool _forceDebugPrint;
39+
public virtual bool ForceDebugPrintInColumn1
40+
{
41+
get => _forceDebugPrint;
42+
set
43+
{
44+
_forceDebugPrint = value;
45+
if (!_forceDebugPrint && !_forceDebugAssert && !_forceStop)
46+
{
47+
_forceDebugs = false;
48+
}
49+
}
50+
}
51+
52+
private bool _forceDebugAssert;
53+
public virtual bool ForceDebugAssertInColumn1
54+
{
55+
get => _forceDebugAssert;
56+
set
57+
{
58+
_forceDebugAssert = value;
59+
if (!_forceDebugPrint && !_forceDebugAssert && !_forceStop)
60+
{
61+
_forceDebugs = false;
62+
}
63+
}
64+
}
65+
66+
private bool _forceStop;
67+
public virtual bool ForceStopInColumn1
68+
{
69+
get => _forceStop;
70+
set
71+
{
72+
_forceStop = value;
73+
if (!_forceDebugPrint && !_forceDebugAssert && !_forceStop)
74+
{
75+
_forceDebugs = false;
76+
}
77+
}
78+
}
79+
2580
public virtual bool ForceCompilerDirectivesInColumn1 { get; set; }
2681
public virtual bool IndentCompilerDirectives { get; set; }
2782
public virtual bool AlignDims { get; set; }
@@ -60,20 +115,33 @@ public virtual int LinesBetweenProcedures
60115
set => _procedureSpacing = value > MaximumVerticalSpacing ? MaximumVerticalSpacing : Math.Max(value, 0);
61116
}
62117

63-
public IndenterSettings()
118+
/// <summary>
119+
/// Use this ctor for unit testing.
120+
/// </summary>
121+
public IndenterSettings() :this(true) { }
122+
123+
/// <summary>
124+
/// Creates an IndenterSettings.
125+
/// </summary>
126+
/// <param name="skipRegistry">If false, the ctor will attempt to load the current tab width from the registry.</param>
127+
public IndenterSettings(bool skipRegistry)
64128
{
65129
var tabWidth = 4;
66-
try
130+
if (!skipRegistry)
67131
{
68-
var reg = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\VBA\6.0\Common", false) ??
69-
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\VBA\7.0\Common", false);
70-
if (reg != null)
132+
try
71133
{
72-
tabWidth = Convert.ToInt32(reg.GetValue("TabWidth") ?? tabWidth);
134+
var reg = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\VBA\6.0\Common", false) ??
135+
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\VBA\7.0\Common", false);
136+
if (reg != null)
137+
{
138+
tabWidth = Convert.ToInt32(reg.GetValue("TabWidth") ?? tabWidth);
139+
}
73140
}
141+
// ReSharper disable once EmptyGeneralCatchClause
142+
catch
143+
{ }
74144
}
75-
// ReSharper disable once EmptyGeneralCatchClause
76-
catch { }
77145

78146
// Mocking requires these to be virtual.
79147
// ReSharper disable DoNotCallOverridableMethodsInConstructor
@@ -86,6 +154,9 @@ public IndenterSettings()
86154
IgnoreOperatorsInContinuations = true;
87155
IndentCase = false;
88156
ForceDebugStatementsInColumn1 = false;
157+
ForceDebugPrintInColumn1 = false;
158+
ForceDebugAssertInColumn1 = false;
159+
ForceStopInColumn1 = false;
89160
ForceCompilerDirectivesInColumn1 = false;
90161
IndentCompilerDirectives = true;
91162
AlignDims = false;
@@ -110,6 +181,9 @@ public bool Equals(IndenterSettings other)
110181
IgnoreOperatorsInContinuations == other.IgnoreOperatorsInContinuations &&
111182
IndentCase == other.IndentCase &&
112183
ForceDebugStatementsInColumn1 == other.ForceDebugStatementsInColumn1 &&
184+
ForceDebugPrintInColumn1 == other.ForceDebugPrintInColumn1 &&
185+
ForceDebugAssertInColumn1 == other.ForceDebugAssertInColumn1 &&
186+
ForceStopInColumn1 == other.ForceStopInColumn1 &&
113187
ForceCompilerDirectivesInColumn1 == other.ForceCompilerDirectivesInColumn1 &&
114188
IndentCompilerDirectives == other.IndentCompilerDirectives &&
115189
AlignDims == other.AlignDims &&
@@ -148,6 +222,9 @@ public void LoadLegacyFromRegistry()
148222
IgnoreOperatorsInContinuations = GetSmartIndenterBoolean(reg, "AlignIgnoreOps", IgnoreOperatorsInContinuations);
149223
IndentCase = GetSmartIndenterBoolean(reg, "IndentCase", IndentCase);
150224
ForceDebugStatementsInColumn1 = GetSmartIndenterBoolean(reg, "DebugCol1", ForceDebugStatementsInColumn1);
225+
ForceDebugPrintInColumn1 = ForceDebugStatementsInColumn1;
226+
ForceDebugAssertInColumn1 = ForceDebugStatementsInColumn1;
227+
ForceStopInColumn1 = ForceDebugStatementsInColumn1;
151228
ForceCompilerDirectivesInColumn1 = GetSmartIndenterBoolean(reg, "CompilerCol1", ForceCompilerDirectivesInColumn1);
152229
IndentCompilerDirectives = GetSmartIndenterBoolean(reg, "IndentCompiler", IndentCompilerDirectives);
153230
AlignDims = GetSmartIndenterBoolean(reg, "AlignDim", AlignDims);

0 commit comments

Comments
 (0)