@@ -7,8 +7,11 @@ namespace Rubberduck.SmartIndenter
77    [ XmlType ( AnonymousType  =  true ) ] 
88    public  class  IndenterSettings  :  IIndenterSettings ,  IEquatable < IndenterSettings > 
99    { 
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 ;      
1215
1316        public  virtual  bool  IndentEntireProcedureBody  {  get ;  set ;  } 
1417        public  virtual  bool  IndentFirstCommentBlock  {  get ;  set ;  } 
@@ -22,31 +25,45 @@ public class IndenterSettings : IIndenterSettings, IEquatable<IndenterSettings>
2225        public  virtual  bool  ForceCompilerDirectivesInColumn1  {  get ;  set ;  } 
2326        public  virtual  bool  IndentCompilerDirectives  {  get ;  set ;  } 
2427        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+ 
2639        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+ 
2960        public  virtual  bool  VerticallySpaceProcedures  {  get ;  set ;  } 
3061
3162        private  int  _procedureSpacing ; 
3263        public  virtual  int  LinesBetweenProcedures 
3364        { 
3465            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 ) ;  } 
5067        } 
5168
5269        public  IndenterSettings ( ) 
@@ -120,8 +137,7 @@ public bool LegacySettingsExist()
120137            catch  
121138            { 
122139                return  false ; 
123-             } 
124-             
140+             }            
125141        } 
126142
127143        public  void  LoadLegacyFromRegistry ( ) 
@@ -135,15 +151,13 @@ public void LoadLegacyFromRegistry()
135151                IndentFirstDeclarationBlock  =  GetSmartIndenterBoolean ( reg ,  "IndentDim" ,  IndentFirstDeclarationBlock ) ; 
136152                AlignCommentsWithCode  =  GetSmartIndenterBoolean ( reg ,  "IndentCmt" ,  AlignCommentsWithCode ) ; 
137153                AlignContinuations  =  GetSmartIndenterBoolean ( reg ,  "AlignContinued" ,  AlignContinuations ) ; 
138-                 IgnoreOperatorsInContinuations  =  GetSmartIndenterBoolean ( reg ,  "AlignIgnoreOps" , 
139-                     IgnoreOperatorsInContinuations ) ; 
154+                 IgnoreOperatorsInContinuations  =  GetSmartIndenterBoolean ( reg ,  "AlignIgnoreOps" ,  IgnoreOperatorsInContinuations ) ; 
140155                IndentCase  =  GetSmartIndenterBoolean ( reg ,  "IndentCase" ,  IndentCase ) ; 
141156                ForceDebugStatementsInColumn1  =  GetSmartIndenterBoolean ( reg ,  "DebugCol1" ,  ForceDebugStatementsInColumn1 ) ; 
142-                 ForceCompilerDirectivesInColumn1  =  GetSmartIndenterBoolean ( reg ,  "CompilerCol1" , 
143-                     ForceCompilerDirectivesInColumn1 ) ; 
157+                 ForceCompilerDirectivesInColumn1  =  GetSmartIndenterBoolean ( reg ,  "CompilerCol1" ,  ForceCompilerDirectivesInColumn1 ) ; 
144158                IndentCompilerDirectives  =  GetSmartIndenterBoolean ( reg ,  "IndentCompiler" ,  IndentCompilerDirectives ) ; 
145159                AlignDims  =  GetSmartIndenterBoolean ( reg ,  "AlignDim" ,  AlignDims ) ; 
146-                 AlignDimColumn  =  Convert . ToInt32 ( reg . GetValue ( "AlignDimCol" )   ??   AlignDimColumn ) ; 
160+                 AlignDimColumn  =  GetSmartIndenterNumeric ( reg ,   "AlignDimCol" ,   AlignDimColumn ,   MaximumAlignDimColumn ) ; 
147161
148162                var  eolSytle  =  reg . GetValue ( "EOLComments" )  as  string ; 
149163                if  ( ! string . IsNullOrEmpty ( eolSytle ) ) 
@@ -164,8 +178,8 @@ public void LoadLegacyFromRegistry()
164178                            break ; 
165179                    } 
166180                } 
167-                 EndOfLineCommentColumnSpaceAlignment  = 
168-                     Convert . ToInt32 ( reg . GetValue ( "EOLAlignCol" )   ??   EndOfLineCommentColumnSpaceAlignment ) ; 
181+                 EndOfLineCommentColumnSpaceAlignment  =   GetSmartIndenterNumeric ( reg ,   "EOLAlignCol" , 
182+                     EndOfLineCommentColumnSpaceAlignment ,   MaximumEndOfLineCommentColumnSpaceAlignment ) ; 
169183            } 
170184            // ReSharper disable once EmptyGeneralCatchClause 
171185            catch  {  } 
@@ -176,5 +190,17 @@ private static bool GetSmartIndenterBoolean(RegistryKey key, string name, bool c
176190            var  value  =  key . GetValue ( name )  as  string ; 
177191            return  string . IsNullOrEmpty ( value )  ?  current  :  value . Trim ( ) . Equals ( "Y" ) ; 
178192        } 
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+         } 
179205    } 
180206} 
0 commit comments