@@ -7,8 +7,11 @@ namespace Rubberduck.SmartIndenter
7
7
[ XmlType ( AnonymousType = true ) ]
8
8
public class IndenterSettings : IIndenterSettings , IEquatable < IndenterSettings >
9
9
{
10
- public const int MinimumVerticalSpacing = 0 ;
11
- public const int MaximumVerticalSpacing = 2 ;
10
+ // These have to be int to allow the settings UI to bind them.
11
+ public const int MaximumAlignDimColumn = 100 ;
12
+ public const int MaximumEndOfLineCommentColumnSpaceAlignment = 100 ;
13
+ public const int MaximumIndentSpaces = 32 ;
14
+ public const int MaximumVerticalSpacing = 2 ;
12
15
13
16
public virtual bool IndentEntireProcedureBody { get ; set ; }
14
17
public virtual bool IndentFirstCommentBlock { get ; set ; }
@@ -22,31 +25,45 @@ public class IndenterSettings : IIndenterSettings, IEquatable<IndenterSettings>
22
25
public virtual bool ForceCompilerDirectivesInColumn1 { get ; set ; }
23
26
public virtual bool IndentCompilerDirectives { get ; set ; }
24
27
public virtual bool AlignDims { get ; set ; }
25
- public virtual int AlignDimColumn { get ; set ; }
28
+
29
+ private int _dimAlignment ;
30
+ public virtual int AlignDimColumn
31
+ {
32
+ get { return _dimAlignment ; }
33
+ set
34
+ {
35
+ _dimAlignment = value > MaximumAlignDimColumn ? MaximumAlignDimColumn : Math . Max ( value , 0 ) ;
36
+ }
37
+ }
38
+
26
39
public virtual EndOfLineCommentStyle EndOfLineCommentStyle { get ; set ; }
27
- public virtual int EndOfLineCommentColumnSpaceAlignment { get ; set ; }
28
- public virtual int IndentSpaces { get ; set ; }
40
+
41
+ private int _commentAlignment ;
42
+ public virtual int EndOfLineCommentColumnSpaceAlignment
43
+ {
44
+ get { return _commentAlignment ; }
45
+ set
46
+ {
47
+ _commentAlignment = value > MaximumEndOfLineCommentColumnSpaceAlignment
48
+ ? MaximumEndOfLineCommentColumnSpaceAlignment
49
+ : value ;
50
+ }
51
+ }
52
+
53
+ private int _indentSpaces ;
54
+ public virtual int IndentSpaces
55
+ {
56
+ get { return _indentSpaces ; }
57
+ set { _indentSpaces = value > MaximumIndentSpaces ? MaximumIndentSpaces : Math . Max ( value , 0 ) ; }
58
+ }
59
+
29
60
public virtual bool VerticallySpaceProcedures { get ; set ; }
30
61
31
62
private int _procedureSpacing ;
32
63
public virtual int LinesBetweenProcedures
33
64
{
34
65
get { return _procedureSpacing ; }
35
- set
36
- {
37
- if ( value < MinimumVerticalSpacing )
38
- {
39
- _procedureSpacing = MinimumVerticalSpacing ;
40
- }
41
- else if ( value > MaximumVerticalSpacing )
42
- {
43
- _procedureSpacing = MaximumVerticalSpacing ;
44
- }
45
- else
46
- {
47
- _procedureSpacing = value ;
48
- }
49
- }
66
+ set { _procedureSpacing = value > MaximumVerticalSpacing ? MaximumVerticalSpacing : Math . Max ( value , 0 ) ; }
50
67
}
51
68
52
69
public IndenterSettings ( )
@@ -120,8 +137,7 @@ public bool LegacySettingsExist()
120
137
catch
121
138
{
122
139
return false ;
123
- }
124
-
140
+ }
125
141
}
126
142
127
143
public void LoadLegacyFromRegistry ( )
@@ -135,15 +151,13 @@ public void LoadLegacyFromRegistry()
135
151
IndentFirstDeclarationBlock = GetSmartIndenterBoolean ( reg , "IndentDim" , IndentFirstDeclarationBlock ) ;
136
152
AlignCommentsWithCode = GetSmartIndenterBoolean ( reg , "IndentCmt" , AlignCommentsWithCode ) ;
137
153
AlignContinuations = GetSmartIndenterBoolean ( reg , "AlignContinued" , AlignContinuations ) ;
138
- IgnoreOperatorsInContinuations = GetSmartIndenterBoolean ( reg , "AlignIgnoreOps" ,
139
- IgnoreOperatorsInContinuations ) ;
154
+ IgnoreOperatorsInContinuations = GetSmartIndenterBoolean ( reg , "AlignIgnoreOps" , IgnoreOperatorsInContinuations ) ;
140
155
IndentCase = GetSmartIndenterBoolean ( reg , "IndentCase" , IndentCase ) ;
141
156
ForceDebugStatementsInColumn1 = GetSmartIndenterBoolean ( reg , "DebugCol1" , ForceDebugStatementsInColumn1 ) ;
142
- ForceCompilerDirectivesInColumn1 = GetSmartIndenterBoolean ( reg , "CompilerCol1" ,
143
- ForceCompilerDirectivesInColumn1 ) ;
157
+ ForceCompilerDirectivesInColumn1 = GetSmartIndenterBoolean ( reg , "CompilerCol1" , ForceCompilerDirectivesInColumn1 ) ;
144
158
IndentCompilerDirectives = GetSmartIndenterBoolean ( reg , "IndentCompiler" , IndentCompilerDirectives ) ;
145
159
AlignDims = GetSmartIndenterBoolean ( reg , "AlignDim" , AlignDims ) ;
146
- AlignDimColumn = Convert . ToInt32 ( reg . GetValue ( "AlignDimCol" ) ?? AlignDimColumn ) ;
160
+ AlignDimColumn = GetSmartIndenterNumeric ( reg , "AlignDimCol" , AlignDimColumn , MaximumAlignDimColumn ) ;
147
161
148
162
var eolSytle = reg . GetValue ( "EOLComments" ) as string ;
149
163
if ( ! string . IsNullOrEmpty ( eolSytle ) )
@@ -164,8 +178,8 @@ public void LoadLegacyFromRegistry()
164
178
break ;
165
179
}
166
180
}
167
- EndOfLineCommentColumnSpaceAlignment =
168
- Convert . ToInt32 ( reg . GetValue ( "EOLAlignCol" ) ?? EndOfLineCommentColumnSpaceAlignment ) ;
181
+ EndOfLineCommentColumnSpaceAlignment = GetSmartIndenterNumeric ( reg , "EOLAlignCol" ,
182
+ EndOfLineCommentColumnSpaceAlignment , MaximumEndOfLineCommentColumnSpaceAlignment ) ;
169
183
}
170
184
// ReSharper disable once EmptyGeneralCatchClause
171
185
catch { }
@@ -176,5 +190,17 @@ private static bool GetSmartIndenterBoolean(RegistryKey key, string name, bool c
176
190
var value = key . GetValue ( name ) as string ;
177
191
return string . IsNullOrEmpty ( value ) ? current : value . Trim ( ) . Equals ( "Y" ) ;
178
192
}
193
+
194
+ private static int GetSmartIndenterNumeric ( RegistryKey key , string name , int current , int max )
195
+ {
196
+ try
197
+ {
198
+ var value = ( int ) key . GetValue ( name ) ;
199
+ return value < 0 ? current : Math . Min ( value , max ) ;
200
+ }
201
+ // ReSharper disable once EmptyGeneralCatchClause
202
+ catch { }
203
+ return current ;
204
+ }
179
205
}
180
206
}
0 commit comments