Skip to content

Commit d702a22

Browse files
Hosch250retailcoder
authored andcommitted
Indenter preview (#1587)
* Indenter preview * Fix setting header indentation * Add citation line * Preview text tweaks.
1 parent 3e4e561 commit d702a22

File tree

3 files changed

+100
-40
lines changed

3 files changed

+100
-40
lines changed

RetailCoder.VBE/UI/Settings/GeneralSettings.xaml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@
6969
<Grid>
7070
<ScrollViewer>
7171
<Grid>
72-
<Grid.RowDefinitions>
73-
<RowDefinition Height="Auto"/>
74-
<RowDefinition Height="Auto"/>
75-
<RowDefinition Height="*"/>
76-
</Grid.RowDefinitions>
77-
7872
<StackPanel Grid.Row="0" Margin="5,5,5,0">
7973
<Label DockPanel.Dock="Top"
8074
Background="DarkGray"
@@ -134,11 +128,10 @@
134128
IsChecked="{Binding DetailedLoggingEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
135129
HorizontalAlignment="Left" />
136130
</StackPanel>
137-
</StackPanel>
138131

139-
<Label Grid.Row="1" Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=GeneralSettings_HotkeysLabel}" FontWeight="SemiBold" />
132+
<Label Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=GeneralSettings_HotkeysLabel}" FontWeight="SemiBold" />
140133

141-
<DataGrid Grid.Row="2" ItemsSource="{Binding Hotkeys}"
134+
<DataGrid ItemsSource="{Binding Hotkeys}"
142135
HorizontalAlignment="Stretch"
143136
AutoGenerateColumns="False"
144137
CanUserDeleteRows="False"
@@ -154,6 +147,7 @@
154147
HorizontalScrollBarVisibility="Hidden"
155148
ItemContainerStyle="{StaticResource PrettifyRow}"
156149
ColumnHeaderHeight="22"
150+
Height="100"
157151
BorderThickness="0">
158152
<DataGrid.CellStyle>
159153
<Style TargetType="{x:Type DataGridCell}">
@@ -206,7 +200,8 @@
206200
</DataGridTemplateColumn.CellTemplate>
207201
</DataGridTemplateColumn>
208202
</DataGrid.Columns>
209-
</DataGrid>
203+
</DataGrid>
204+
</StackPanel>
210205
</Grid>
211206
</ScrollViewer>
212207
</Grid>

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: 84 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,75 @@ 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+
' Original VB6 code graciously offered to Rubberduck by Stephen Bullen & Rob Bovey
272+
'@ 2016 by Rubberduck VBA.
273+
274+
Dim iCount As Integer
275+
Static sName As String
276+
277+
If YouLikeRubberduck Then
278+
' Star us on GitHub http://github.com/rubberduck-vba/Rubberduck
279+
' Follow us on Twitter @rubberduck-vba/contributors
280+
' Visit http://rubberduckvba.com for news and updates
281+
282+
Select Case X
283+
Case ""A""
284+
' If you have any comments or suggestions, _
285+
or find valid VBA code that isn't indented correctly,
286+
287+
#If VBA6 Then
288+
MsgBox ""Contact contact@rubberduck-vba.com""
289+
#End If
290+
291+
Case ""Continued strings and parameters can be"" _
292+
& ""lined up for easier reading, optionally ignoring"" _
293+
, ""any operators (&+, etc) at the start of the line.""
294+
295+
Debug.Print ""X<>1""
296+
End Select 'Case X
297+
End If 'More Tools?
298+
299+
End Sub
300+
";
269301

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

275337
#endregion

0 commit comments

Comments
 (0)