Skip to content

Commit 6960e6b

Browse files
committed
Implement #36 "Indentation"
Add ability to replace incoming tabs with default (4)-spaces
1 parent 8cb4956 commit 6960e6b

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

Interop/OptionsControl.cs

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class OptionsControl
3333
public double Editor_ScrollLines = 4.0;
3434
public bool Editor_AgressiveIndentation = true;
3535
public bool Editor_ReformatLineAfterSemicolon = true;
36+
public bool Editor_ReplaceTabsToWhitespace = false;
3637

3738
public string[] LastOpenFiles = new string[0];
3839

@@ -71,6 +72,7 @@ public void FillNullToDefaults()
7172
this.Editor_ReformatLineAfterSemicolon = true;
7273
this.Editor_ScrollLines = 4.0;
7374
this.Program_CheckForUpdates = true;
75+
this.Editor_ReplaceTabsToWhitespace = false;
7476
break;
7577
}
7678
case 1:
@@ -79,17 +81,20 @@ public void FillNullToDefaults()
7981
this.Editor_ReformatLineAfterSemicolon = true;
8082
this.Editor_ScrollLines = 4.0;
8183
this.Program_CheckForUpdates = true;
84+
this.Editor_ReplaceTabsToWhitespace = false;
8285
break;
8386
}
8487
case 2:
8588
{
8689
this.Editor_ReformatLineAfterSemicolon = true;
8790
this.Editor_ScrollLines = 4.0;
8891
this.Program_CheckForUpdates = true;
92+
this.Editor_ReplaceTabsToWhitespace = false;
8993
break;
9094
}
9195
case 3:
9296
{
97+
this.Editor_ReplaceTabsToWhitespace = false;
9398
break;
9499
}
95100
}

UI/Components/EditorElement.xaml.cs

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public EditorElement(string filePath)
129129
editor.Options.HighlightCurrentLine = true;
130130
editor.Options.AllowScrollBelowDocument = true;
131131
editor.TextArea.SelectionCornerRadius = 0.0;
132+
editor.Options.ConvertTabsToSpaces = Program.OptionsObject.Editor_ReplaceTabsToWhitespace;
132133

133134
editor.FontFamily = new FontFamily(Program.OptionsObject.Editor_FontFamily);
134135
editor.WordWrap = Program.OptionsObject.Editor_WordWrap;

UI/Windows/OptionsWindow.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<CheckBox Name="WordWrap" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,55,0,0" Content="Word Wrap" Checked="WordWrap_Changed" Unchecked="WordWrap_Changed" />
4949
<CheckBox Name="AgressiveIndentation" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="350,55,0,0" Content="Agressive Indentation" Checked="AIndentation_Changed" Unchecked="AIndentation_Changed" />
5050
<CheckBox Name="LineReformatting" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="350,75,0,0" Content="Reformatting Line after semicolon" Checked="LineReformat_Changed" Unchecked="LineReformat_Changed" />
51+
<CheckBox Name="TabToSpace" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="350,95,0,0" Content="Replace tabs with spaces" Checked="TabToSpace_Changed" Unchecked="TabToSpace_Changed" />
5152
<TextBlock Name="FontFamilyTB" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,80,5,5" Text="Font (Consolas):" IsHitTestVisible="False" />
5253
<ComboBox Name="FontFamilyCB" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,100,5,5" Width="250" xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase" ItemTemplate="{DynamicResource FontTemplate}" SelectionChanged="FontFamily_Changed">
5354
<ComboBox.Resources>

UI/Windows/OptionsWindow.xaml.cs

+16
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,21 @@ private void LineReformat_Changed(object sender, RoutedEventArgs e)
127127
Program.OptionsObject.Editor_ReformatLineAfterSemicolon = LineReformatting.IsChecked.Value;
128128
}
129129

130+
private void TabToSpace_Changed(object sender, RoutedEventArgs e)
131+
{
132+
if (!AllowChanging) { return; }
133+
bool replaceTabs = TabToSpace.IsChecked.Value;
134+
Program.OptionsObject.Editor_ReplaceTabsToWhitespace = replaceTabs;
135+
EditorElement[] editors = Program.MainWindow.GetAllEditorElements();
136+
if (editors != null)
137+
{
138+
for (int i = 0; i < editors.Length; ++i)
139+
{
140+
editors[i].editor.Options.ConvertTabsToSpaces = replaceTabs;
141+
}
142+
}
143+
}
144+
130145
private void FontFamily_Changed(object sender, RoutedEventArgs e)
131146
{
132147
if (!AllowChanging) { return; }
@@ -169,6 +184,7 @@ private void LoadSettings()
169184
WordWrap.IsChecked = Program.OptionsObject.Editor_WordWrap;
170185
AgressiveIndentation.IsChecked = Program.OptionsObject.Editor_AgressiveIndentation;
171186
LineReformatting.IsChecked = Program.OptionsObject.Editor_ReformatLineAfterSemicolon;
187+
TabToSpace.IsChecked = Program.OptionsObject.Editor_ReplaceTabsToWhitespace;
172188
FontFamilyTB.Text = "Font(" + Program.OptionsObject.Editor_FontFamily + "):";
173189
FontFamilyCB.SelectedValue = new FontFamily(Program.OptionsObject.Editor_FontFamily);
174190
LoadSH();

0 commit comments

Comments
 (0)