Skip to content

Commit c805a76

Browse files
committed
Implement #49
1 parent 876ba18 commit c805a76

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

Interop/OptionsControl.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace Spedit //leave this here instead of .Interop because of reasons...
99
[Serializable]
1010
public class OptionsControl
1111
{
12-
public static int SVersion = 7;
13-
public int Version = 7;
12+
public static int SVersion = 8;
13+
public int Version = 8;
1414

1515
public byte[] Program_CryptoKey = null;
1616

@@ -38,6 +38,7 @@ public class OptionsControl
3838
public bool Editor_AgressiveIndentation = true;
3939
public bool Editor_ReformatLineAfterSemicolon = true;
4040
public bool Editor_ReplaceTabsToWhitespace = false;
41+
public bool Editor_AutoCloseBrackets = true;
4142

4243
public string[] LastOpenFiles = new string[0];
4344

@@ -81,6 +82,7 @@ public void FillNullToDefaults()
8182
this.Program_AccentColor = "Red";
8283
this.Program_Theme = "BaseDark";
8384
NormalizeSHColors();
85+
Editor_AutoCloseBrackets = true;
8486
break;
8587
}
8688
case 1:
@@ -94,6 +96,7 @@ public void FillNullToDefaults()
9496
this.Program_AccentColor = "Red";
9597
this.Program_Theme = "BaseDark";
9698
NormalizeSHColors();
99+
Editor_AutoCloseBrackets = true;
97100
break;
98101
}
99102
case 2:
@@ -106,6 +109,7 @@ public void FillNullToDefaults()
106109
this.Program_AccentColor = "Red";
107110
this.Program_Theme = "BaseDark";
108111
NormalizeSHColors();
112+
Editor_AutoCloseBrackets = true;
109113
break;
110114
}
111115
case 3:
@@ -115,6 +119,7 @@ public void FillNullToDefaults()
115119
this.Program_AccentColor = "Red";
116120
this.Program_Theme = "BaseDark";
117121
NormalizeSHColors();
122+
Editor_AutoCloseBrackets = true;
118123
break;
119124
}
120125
case 4:
@@ -123,20 +128,28 @@ public void FillNullToDefaults()
123128
this.Program_AccentColor = "Red";
124129
this.Program_Theme = "BaseDark";
125130
NormalizeSHColors();
131+
Editor_AutoCloseBrackets = true;
126132
break;
127133
}
128134
case 5:
129135
{
130136
this.Program_AccentColor = "Red";
131137
this.Program_Theme = "BaseDark";
132138
NormalizeSHColors();
139+
Editor_AutoCloseBrackets = true;
133140
break;
134141
}
135142
case 6:
136143
{
137144
this.Program_AccentColor = "Red";
138145
this.Program_Theme = "BaseDark";
139146
NormalizeSHColors();
147+
Editor_AutoCloseBrackets = true;
148+
break;
149+
}
150+
case 7:
151+
{
152+
Editor_AutoCloseBrackets = true;
140153
break;
141154
}
142155
}

UI/Components/EditorElement.xaml.cs

+21-3
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,28 @@ private void TextArea_TextEntered(object sender, TextCompositionEventArgs e)
446446
foldingStrategy.UpdateFoldings(foldingManager, editor.Document);
447447
}
448448
else if (e.Text == "{")
449-
{
450-
foldingStrategy.UpdateFoldings(foldingManager, editor.Document);
449+
{
450+
if (Program.OptionsObject.Editor_AutoCloseBrackets)
451+
{
452+
editor.Document.Insert(editor.CaretOffset, "}");
453+
editor.CaretOffset -= 1;
454+
}
455+
foldingStrategy.UpdateFoldings(foldingManager, editor.Document);
451456
}
452-
}
457+
else if (Program.OptionsObject.Editor_AutoCloseBrackets)
458+
{
459+
if (e.Text == "(")
460+
{
461+
editor.Document.Insert(editor.CaretOffset, ")");
462+
editor.CaretOffset -= 1;
463+
}
464+
else if (e.Text == "[")
465+
{
466+
editor.Document.Insert(editor.CaretOffset, "]");
467+
editor.CaretOffset -= 1;
468+
}
469+
}
470+
}
453471

454472
private void TextArea_SelectionChanged(object sender, EventArgs e)
455473
{

UI/Windows/OptionsWindow.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<CheckBox Name="AgressiveIndentation" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="350,55,0,0" Content="Agressive Indentation" Checked="AIndentation_Changed" Unchecked="AIndentation_Changed" />
5454
<CheckBox Name="LineReformatting" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="350,75,0,0" Content="Reformatting Line after semicolon" Checked="LineReformat_Changed" Unchecked="LineReformat_Changed" />
5555
<CheckBox Name="TabToSpace" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="350,95,0,0" Content="Replace tabs with spaces" Checked="TabToSpace_Changed" Unchecked="TabToSpace_Changed" />
56+
<CheckBox Name="AutoCloseBrackets" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="350,115,0,0" Content="Auto close Brackets [,{,(" Checked="AutoCloseBrackets_Changed" Unchecked="AutoCloseBrackets_Changed" />
5657
<TextBlock Name="FontFamilyTB" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,80,5,5" Text="Font (Consolas):" IsHitTestVisible="False" />
5758
<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">
5859
<ComboBox.Resources>

UI/Windows/OptionsWindow.xaml.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,14 @@ private void TabToSpace_Changed(object sender, RoutedEventArgs e)
173173
}
174174
}
175175

176-
private void FontFamily_Changed(object sender, RoutedEventArgs e)
176+
private void AutoCloseBrackets_Changed(object sender, RoutedEventArgs e)
177+
{
178+
if (!AllowChanging) { return; }
179+
Program.OptionsObject.Editor_AutoCloseBrackets = AutoCloseBrackets.IsChecked.Value;
180+
}
181+
182+
183+
private void FontFamily_Changed(object sender, RoutedEventArgs e)
177184
{
178185
if (!AllowChanging) { return; }
179186
FontFamily family = (FontFamily)FontFamilyCB.SelectedItem;
@@ -230,7 +237,8 @@ private void LoadSettings()
230237
AgressiveIndentation.IsChecked = Program.OptionsObject.Editor_AgressiveIndentation;
231238
LineReformatting.IsChecked = Program.OptionsObject.Editor_ReformatLineAfterSemicolon;
232239
TabToSpace.IsChecked = Program.OptionsObject.Editor_ReplaceTabsToWhitespace;
233-
FontFamilyTB.Text = "Font(" + Program.OptionsObject.Editor_FontFamily + "):";
240+
AutoCloseBrackets.IsChecked = Program.OptionsObject.Editor_AutoCloseBrackets;
241+
FontFamilyTB.Text = "Font(" + Program.OptionsObject.Editor_FontFamily + "):";
234242
FontFamilyCB.SelectedValue = new FontFamily(Program.OptionsObject.Editor_FontFamily);
235243
LoadSH();
236244
}

0 commit comments

Comments
 (0)