Skip to content

Commit ca0da18

Browse files
committed
Indenter preview
1 parent 3e4e561 commit ca0da18

File tree

2 files changed

+92
-30
lines changed

2 files changed

+92
-30
lines changed

RetailCoder.VBE/UI/Settings/IndenterSettings.xaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,16 @@
178178
</StackPanel>
179179
</ScrollViewer>
180180

181-
<TextBlock Grid.Row="1"
182-
Background="White"
183-
Height="100"
184-
xml:space="preserve"
185-
Margin="5,0"
186-
FontFamily="Consolas"
187-
VerticalAlignment="Bottom"
188-
Text="{Binding PreviewSampleCode}"/>
181+
<ScrollViewer Grid.Row="1"
182+
VerticalScrollBarVisibility="Auto"
183+
HorizontalScrollBarVisibility="Auto">
184+
<TextBlock Background="White"
185+
xml:space="preserve"
186+
Margin="5,0"
187+
FontFamily="Consolas"
188+
VerticalAlignment="Top"
189+
Text="{Binding PreviewSampleCode}"
190+
ScrollViewer.VerticalScrollBarVisibility="Visible"/>
191+
</ScrollViewer>
189192
</Grid>
190193
</UserControl>

RetailCoder.VBE/UI/Settings/IndenterSettingsViewModel.cs

Lines changed: 81 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Rubberduck.Settings;
1+
using System;
2+
using Rubberduck.Settings;
23
using Rubberduck.SmartIndenter;
34

45
namespace Rubberduck.UI.Settings
@@ -7,22 +8,22 @@ public class IndenterSettingsViewModel : ViewModelBase, ISettingsViewModel
78
{
89
public IndenterSettingsViewModel(Configuration config)
910
{
10-
AlignCommentsWithCode = config.UserSettings.IndenterSettings.AlignCommentsWithCode;
11-
AlignContinuations = config.UserSettings.IndenterSettings.AlignContinuations;
12-
AlignDimColumn = config.UserSettings.IndenterSettings.AlignDimColumn;
13-
AlignDims = config.UserSettings.IndenterSettings.AlignDims;
14-
EnableUndo = config.UserSettings.IndenterSettings.EnableUndo;
15-
EndOfLineCommentColumnSpaceAlignment = config.UserSettings.IndenterSettings.EndOfLineCommentColumnSpaceAlignment;
16-
EndOfLineCommentStyle = config.UserSettings.IndenterSettings.EndOfLineCommentStyle;
17-
ForceCompilerDirectivesInColumn1 = config.UserSettings.IndenterSettings.ForceCompilerDirectivesInColumn1;
18-
ForceDebugStatementsInColumn1 = config.UserSettings.IndenterSettings.ForceDebugStatementsInColumn1;
19-
IgnoreOperatorsInContinuations = config.UserSettings.IndenterSettings.IgnoreOperatorsInContinuations;
20-
IndentCase = config.UserSettings.IndenterSettings.IndentCase;
21-
IndentCompilerDirectives = config.UserSettings.IndenterSettings.IndentCompilerDirectives;
22-
IndentEntireProcedureBody = config.UserSettings.IndenterSettings.IndentEntireProcedureBody;
23-
IndentFirstCommentBlock = config.UserSettings.IndenterSettings.IndentFirstCommentBlock;
24-
IndentFirstDeclarationBlock = config.UserSettings.IndenterSettings.IndentFirstDeclarationBlock;
25-
IndentSpaces = config.UserSettings.IndenterSettings.IndentSpaces;
11+
_alignCommentsWithCode = config.UserSettings.IndenterSettings.AlignCommentsWithCode;
12+
_alignContinuations = config.UserSettings.IndenterSettings.AlignContinuations;
13+
_alignDimColumn = config.UserSettings.IndenterSettings.AlignDimColumn;
14+
_alignDims = config.UserSettings.IndenterSettings.AlignDims;
15+
_enableUndo = config.UserSettings.IndenterSettings.EnableUndo;
16+
_endOfLineCommentColumnSpaceAlignment = config.UserSettings.IndenterSettings.EndOfLineCommentColumnSpaceAlignment;
17+
_endOfLineCommentStyle = config.UserSettings.IndenterSettings.EndOfLineCommentStyle;
18+
_forceCompilerDirectivesInColumn1 = config.UserSettings.IndenterSettings.ForceCompilerDirectivesInColumn1;
19+
_forceDebugStatementsInColumn1 = config.UserSettings.IndenterSettings.ForceDebugStatementsInColumn1;
20+
_ignoreOperatorsInContinuations = config.UserSettings.IndenterSettings.IgnoreOperatorsInContinuations;
21+
_indentCase = config.UserSettings.IndenterSettings.IndentCase;
22+
_indentCompilerDirectives = config.UserSettings.IndenterSettings.IndentCompilerDirectives;
23+
_indentEntireProcedureBody = config.UserSettings.IndenterSettings.IndentEntireProcedureBody;
24+
_indentFirstCommentBlock = config.UserSettings.IndenterSettings.IndentFirstCommentBlock;
25+
_indentFirstDeclarationBlock = config.UserSettings.IndenterSettings.IndentFirstDeclarationBlock;
26+
_indentSpaces = config.UserSettings.IndenterSettings.IndentSpaces;
2627

2728
PropertyChanged += IndenterSettingsViewModel_PropertyChanged;
2829
}
@@ -262,14 +263,72 @@ public int IndentSpaces
262263
}
263264

264265
// ReSharper disable once InconsistentNaming
265-
private const string _previewSampleCode = @"Sub Foo()
266-
' Do something here
267-
' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ' comment here
268-
End Sub";
266+
private const string _previewSampleCode =
267+
@"' Example Procedure
268+
Sub ExampleProc()
269+
270+
' SMART INDENTER
271+
'@ 2016 by Rubberduck VBA.
272+
273+
Dim iCount As Integer
274+
Static sName As String
275+
276+
If YouWantMoreExamplesAndTools Then
277+
' Visit http://rubberduckvba.com/
278+
279+
Select Case X
280+
Case ""A""
281+
' If you have any comments or suggestions, _
282+
or find valid VBA code that isn't indented correctly,
283+
284+
#If VBA6 Then
285+
MsgBox ""Contact contact@rubberduck-vba.com""
286+
#End If
287+
288+
Case ""Continued strings and parameters can be"" _
289+
& ""lined up for easier reading, optionally ignoring"" _
290+
, ""any operatirs (&+, etc) at the start of the line.""
291+
292+
Debug.Print ""X<>1""
293+
End Select 'Case X
294+
End If 'More Tools?
295+
296+
End Sub
297+
";
269298

270299
public string PreviewSampleCode
271300
{
272-
get { return _previewSampleCode; /* SmartIndenter.Indent(_indenterData); */ }
301+
get
302+
{
303+
var indenter = new Indenter(null, GetCurrentSettings);
304+
305+
var lines = _previewSampleCode.Split(new[] {Environment.NewLine}, StringSplitOptions.None);
306+
indenter.Indent(lines, "TestModule", false);
307+
return string.Join(Environment.NewLine, lines);
308+
}
309+
}
310+
311+
private IIndenterSettings GetCurrentSettings()
312+
{
313+
return new SmartIndenter.IndenterSettings
314+
{
315+
AlignCommentsWithCode = AlignCommentsWithCode,
316+
AlignContinuations = AlignContinuations,
317+
AlignDimColumn = AlignDimColumn,
318+
AlignDims = AlignDims,
319+
EnableUndo = EnableUndo,
320+
EndOfLineCommentColumnSpaceAlignment = EndOfLineCommentColumnSpaceAlignment,
321+
EndOfLineCommentStyle = EndOfLineCommentStyle,
322+
ForceCompilerDirectivesInColumn1 = ForceCompilerDirectivesInColumn1,
323+
ForceDebugStatementsInColumn1 = ForceDebugStatementsInColumn1,
324+
IgnoreOperatorsInContinuations = IgnoreOperatorsInContinuations,
325+
IndentCase = IndentCase,
326+
IndentCompilerDirectives = IndentCompilerDirectives,
327+
IndentEntireProcedureBody = IndentEntireProcedureBody,
328+
IndentFirstCommentBlock = IndentFirstCommentBlock,
329+
IndentFirstDeclarationBlock = IndentFirstDeclarationBlock,
330+
IndentSpaces = IndentSpaces
331+
};
273332
}
274333

275334
#endregion

0 commit comments

Comments
 (0)