Skip to content

Commit 2137ad9

Browse files
committed
enhance: allow to configure editor tab width in preferences window (#1048)
Signed-off-by: leo <[email protected]>
1 parent 11af5d9 commit 2137ad9

11 files changed

+98
-19
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@
464464
<x:String x:Key="Text.Preferences.AI.Streaming" xml:space="preserve">Enable Streaming</x:String>
465465
<x:String x:Key="Text.Preferences.Appearance" xml:space="preserve">APPEARANCE</x:String>
466466
<x:String x:Key="Text.Preferences.Appearance.DefaultFont" xml:space="preserve">Default Font</x:String>
467+
<x:String x:Key="Text.Preferences.Appearance.EditorTabWidth" xml:space="preserve">Editor Tab Width</x:String>
467468
<x:String x:Key="Text.Preferences.Appearance.FontSize" xml:space="preserve">Font Size</x:String>
468469
<x:String x:Key="Text.Preferences.Appearance.FontSize.Default" xml:space="preserve">Default</x:String>
469470
<x:String x:Key="Text.Preferences.Appearance.FontSize.Editor" xml:space="preserve">Editor</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@
467467
<x:String x:Key="Text.Preferences.AI.Streaming" xml:space="preserve">启用流式输出</x:String>
468468
<x:String x:Key="Text.Preferences.Appearance" xml:space="preserve">外观配置</x:String>
469469
<x:String x:Key="Text.Preferences.Appearance.DefaultFont" xml:space="preserve">缺省字体</x:String>
470+
<x:String x:Key="Text.Preferences.Appearance.EditorTabWidth" xml:space="preserve">编辑器制表符宽度</x:String>
470471
<x:String x:Key="Text.Preferences.Appearance.FontSize" xml:space="preserve">字体大小</x:String>
471472
<x:String x:Key="Text.Preferences.Appearance.FontSize.Default" xml:space="preserve">默认</x:String>
472473
<x:String x:Key="Text.Preferences.Appearance.FontSize.Editor" xml:space="preserve">代码编辑器</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@
467467
<x:String x:Key="Text.Preferences.AI.Streaming" xml:space="preserve">啟用串流輸出</x:String>
468468
<x:String x:Key="Text.Preferences.Appearance" xml:space="preserve">外觀設定</x:String>
469469
<x:String x:Key="Text.Preferences.Appearance.DefaultFont" xml:space="preserve">預設字型</x:String>
470+
<x:String x:Key="Text.Preferences.Appearance.EditorTabWidth" xml:space="preserve">編輯器制表符寬度</x:String>
470471
<x:String x:Key="Text.Preferences.Appearance.FontSize" xml:space="preserve">字型大小</x:String>
471472
<x:String x:Key="Text.Preferences.Appearance.FontSize.Default" xml:space="preserve">預設</x:String>
472473
<x:String x:Key="Text.Preferences.Appearance.FontSize.Editor" xml:space="preserve">程式碼</x:String>

src/ViewModels/Preferences.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ public double EditorFontSize
111111
set => SetProperty(ref _editorFontSize, value);
112112
}
113113

114+
public int EditorTabWidth
115+
{
116+
get => _editorTabWidth;
117+
set => SetProperty(ref _editorTabWidth, value);
118+
}
119+
114120
public LayoutInfo Layout
115121
{
116122
get => _layout;
@@ -649,6 +655,7 @@ private string FixFontFamilyName(string name)
649655
private bool _useSystemWindowFrame = false;
650656
private double _defaultFontSize = 13;
651657
private double _editorFontSize = 13;
658+
private int _editorTabWidth = 4;
652659
private LayoutInfo _layout = new LayoutInfo();
653660

654661
private int _maxHistoryCommits = 20000;

src/Views/Blame.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
Foreground="{DynamicResource Brush.FG1}"
5959
FontFamily="{DynamicResource Fonts.Monospace}"
6060
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
61+
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
6162
BlameData="{Binding Data}"/>
6263

6364
<!-- Not supported mask (for binary files) -->

src/Views/Blame.axaml.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,15 @@ public Models.BlameData BlameData
260260
set => SetValue(BlameDataProperty, value);
261261
}
262262

263+
public static readonly StyledProperty<int> TabWidthProperty =
264+
AvaloniaProperty.Register<BlameTextEditor, int>(nameof(TabWidth), 4);
265+
266+
public int TabWidth
267+
{
268+
get => GetValue(TabWidthProperty);
269+
set => SetValue(TabWidthProperty, value);
270+
}
271+
263272
protected override Type StyleKeyOverride => typeof(TextEditor);
264273

265274
public BlameTextEditor() : base(new TextArea(), new TextDocument())
@@ -268,6 +277,10 @@ public Models.BlameData BlameData
268277
ShowLineNumbers = false;
269278
WordWrap = false;
270279

280+
Options.IndentationSize = TabWidth;
281+
Options.EnableHyperlinks = false;
282+
Options.EnableEmailHyperlinks = false;
283+
271284
_textMate = Models.TextMateHelper.CreateForEditor(this);
272285

273286
TextArea.LeftMargins.Add(new LineNumberMargin() { Margin = new Thickness(8, 0) });
@@ -280,8 +293,6 @@ public Models.BlameData BlameData
280293
TextArea.TextView.ContextRequested += OnTextViewContextRequested;
281294
TextArea.TextView.VisualLinesChanged += OnTextViewVisualLinesChanged;
282295
TextArea.TextView.Margin = new Thickness(4, 0);
283-
TextArea.TextView.Options.EnableHyperlinks = false;
284-
TextArea.TextView.Options.EnableEmailHyperlinks = false;
285296
}
286297

287298
public override void Render(DrawingContext context)
@@ -350,6 +361,10 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
350361
Text = string.Empty;
351362
}
352363
}
364+
else if (change.Property == TabWidthProperty)
365+
{
366+
Options.IndentationSize = TabWidth;
367+
}
353368
else if (change.Property.Name == "ActualThemeVariant" && change.NewValue != null)
354369
{
355370
Models.TextMateHelper.SetThemeByApp(_textMate);

src/Views/Preferences.axaml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
<TabItem.Header>
149149
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Preferences.Appearance}"/>
150150
</TabItem.Header>
151-
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
151+
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
152152
<TextBlock Grid.Row="0" Grid.Column="0"
153153
Text="{DynamicResource Text.Preferences.Appearance.Theme}"
154154
HorizontalAlignment="Right"
@@ -190,12 +190,12 @@
190190
Margin="0,0,16,0"/>
191191
<Grid Grid.Row="3" Grid.Column="1" ColumnDefinitions="*,8,*">
192192
<NumericUpDown Grid.Column="0"
193-
Minimum="10" Maximum="18" Increment="0.5"
194-
Height="28"
195-
Padding="4"
196-
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
197-
CornerRadius="3"
198-
Value="{Binding DefaultFontSize, Mode=TwoWay}">
193+
Minimum="10" Maximum="18" Increment="0.5"
194+
Height="28"
195+
Padding="4"
196+
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
197+
CornerRadius="3"
198+
Value="{Binding DefaultFontSize, Mode=TwoWay}">
199199
<NumericUpDown.InnerLeftContent>
200200
<Border BorderThickness="0,0,1,0" BorderBrush="{DynamicResource Brush.Border1}">
201201
<TextBlock Margin="4,0" Text="{DynamicResource Text.Preferences.Appearance.FontSize.Default}"/>
@@ -218,10 +218,23 @@
218218
</Grid>
219219

220220
<TextBlock Grid.Row="4" Grid.Column="0"
221+
Text="{DynamicResource Text.Preferences.Appearance.EditorTabWidth}"
222+
HorizontalAlignment="Right"
223+
Margin="0,0,16,0"/>
224+
<Grid Grid.Row="4" Grid.Column="1">
225+
<NumericUpDown Minimum="1" Maximum="16" Increment="1"
226+
Height="28"
227+
Padding="4"
228+
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
229+
CornerRadius="3"
230+
Value="{Binding EditorTabWidth, Mode=TwoWay}"/>
231+
</Grid>
232+
233+
<TextBlock Grid.Row="5" Grid.Column="0"
221234
Text="{DynamicResource Text.Preferences.Appearance.ThemeOverrides}"
222235
HorizontalAlignment="Right"
223236
Margin="0,0,16,0"/>
224-
<TextBox Grid.Row="4" Grid.Column="1"
237+
<TextBox Grid.Row="5" Grid.Column="1"
225238
Height="28"
226239
CornerRadius="3"
227240
Text="{Binding ThemeOverrides, Mode=TwoWay}">
@@ -232,16 +245,16 @@
232245
</TextBox.InnerRightContent>
233246
</TextBox>
234247

235-
<CheckBox Grid.Row="5" Grid.Column="1"
248+
<CheckBox Grid.Row="6" Grid.Column="1"
236249
Content="{DynamicResource Text.Preferences.Appearance.OnlyUseMonoFontInEditor}"
237250
IsChecked="{Binding OnlyUseMonoFontInEditor, Mode=TwoWay}"/>
238251

239-
<CheckBox Grid.Row="6" Grid.Column="1"
252+
<CheckBox Grid.Row="7" Grid.Column="1"
240253
Height="32"
241254
Content="{DynamicResource Text.Preferences.Appearance.UseFixedTabWidth}"
242255
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseFixedTabWidth, Mode=TwoWay}"/>
243256

244-
<CheckBox Grid.Row="7" Grid.Column="1"
257+
<CheckBox Grid.Row="8" Grid.Column="1"
245258
Height="32"
246259
Content="{DynamicResource Text.Preferences.Appearance.UseNativeWindowFrame}"
247260
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseSystemWindowFrame, Mode=OneTime}"

src/Views/RevisionFileContentViewer.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<DataTemplate DataType="m:RevisionTextFile">
2323
<v:RevisionTextFileView FontFamily="{DynamicResource Fonts.Monospace}"
2424
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
25+
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
2526
Background="{DynamicResource Brush.Contents}"/>
2627
</DataTemplate>
2728

src/Views/RevisionFileContentViewer.axaml.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,32 @@ namespace SourceGit.Views
1515
{
1616
public class RevisionTextFileView : TextEditor
1717
{
18+
public static readonly StyledProperty<int> TabWidthProperty =
19+
AvaloniaProperty.Register<RevisionTextFileView, int>(nameof(TabWidth), 4);
20+
21+
public int TabWidth
22+
{
23+
get => GetValue(TabWidthProperty);
24+
set => SetValue(TabWidthProperty, value);
25+
}
26+
1827
protected override Type StyleKeyOverride => typeof(TextEditor);
1928

2029
public RevisionTextFileView() : base(new TextArea(), new TextDocument())
2130
{
2231
IsReadOnly = true;
2332
ShowLineNumbers = true;
2433
WordWrap = false;
34+
35+
Options.IndentationSize = TabWidth;
36+
Options.EnableHyperlinks = false;
37+
Options.EnableEmailHyperlinks = false;
38+
2539
HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
2640
VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
2741

2842
TextArea.LeftMargins[0].Margin = new Thickness(8, 0);
2943
TextArea.TextView.Margin = new Thickness(4, 0);
30-
TextArea.TextView.Options.EnableHyperlinks = false;
31-
TextArea.TextView.Options.EnableEmailHyperlinks = false;
3244
}
3345

3446
protected override void OnLoaded(RoutedEventArgs e)
@@ -69,6 +81,16 @@ protected override void OnDataContextChanged(EventArgs e)
6981
}
7082
}
7183

84+
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
85+
{
86+
base.OnPropertyChanged(change);
87+
88+
if (change.Property == TabWidthProperty)
89+
{
90+
Options.IndentationSize = TabWidth;
91+
}
92+
}
93+
7294
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
7395
{
7496
var selected = SelectedText;

src/Views/TextDiffView.axaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
IndicatorForeground="{DynamicResource Brush.FG2}"
2828
FontFamily="{DynamicResource Fonts.Monospace}"
2929
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
30+
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
3031
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseSyntaxHighlighting}"
3132
WordWrap="{Binding Source={x:Static vm:Preferences.Instance}, Path=EnableDiffViewWordWrap}"
3233
ShowHiddenSymbols="{Binding Source={x:Static vm:Preferences.Instance}, Path=ShowHiddenSymbolsInDiffView}"
@@ -59,6 +60,7 @@
5960
IndicatorForeground="{DynamicResource Brush.FG2}"
6061
FontFamily="{DynamicResource Fonts.Monospace}"
6162
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
63+
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
6264
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseSyntaxHighlighting}"
6365
WordWrap="False"
6466
ShowHiddenSymbols="{Binding Source={x:Static vm:Preferences.Instance}, Path=ShowHiddenSymbolsInDiffView}"
@@ -81,6 +83,7 @@
8183
IndicatorForeground="{DynamicResource Brush.FG2}"
8284
FontFamily="{DynamicResource Fonts.Monospace}"
8385
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
86+
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
8487
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseSyntaxHighlighting}"
8588
WordWrap="False"
8689
ShowHiddenSymbols="{Binding Source={x:Static vm:Preferences.Instance}, Path=ShowHiddenSymbolsInDiffView}"

0 commit comments

Comments
 (0)