mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 12:15:00 +00:00
enhance: allow to configure editor tab width in preferences window (#1048)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
11af5d9b29
commit
2137ad9ec9
11 changed files with 98 additions and 19 deletions
|
@ -464,6 +464,7 @@
|
|||
<x:String x:Key="Text.Preferences.AI.Streaming" xml:space="preserve">Enable Streaming</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance" xml:space="preserve">APPEARANCE</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance.DefaultFont" xml:space="preserve">Default Font</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance.EditorTabWidth" xml:space="preserve">Editor Tab Width</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance.FontSize" xml:space="preserve">Font Size</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance.FontSize.Default" xml:space="preserve">Default</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance.FontSize.Editor" xml:space="preserve">Editor</x:String>
|
||||
|
|
|
@ -467,6 +467,7 @@
|
|||
<x:String x:Key="Text.Preferences.AI.Streaming" xml:space="preserve">启用流式输出</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance" xml:space="preserve">外观配置</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance.DefaultFont" xml:space="preserve">缺省字体</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance.EditorTabWidth" xml:space="preserve">编辑器制表符宽度</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance.FontSize" xml:space="preserve">字体大小</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance.FontSize.Default" xml:space="preserve">默认</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance.FontSize.Editor" xml:space="preserve">代码编辑器</x:String>
|
||||
|
|
|
@ -467,6 +467,7 @@
|
|||
<x:String x:Key="Text.Preferences.AI.Streaming" xml:space="preserve">啟用串流輸出</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance" xml:space="preserve">外觀設定</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance.DefaultFont" xml:space="preserve">預設字型</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance.EditorTabWidth" xml:space="preserve">編輯器制表符寬度</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance.FontSize" xml:space="preserve">字型大小</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance.FontSize.Default" xml:space="preserve">預設</x:String>
|
||||
<x:String x:Key="Text.Preferences.Appearance.FontSize.Editor" xml:space="preserve">程式碼</x:String>
|
||||
|
|
|
@ -111,6 +111,12 @@ namespace SourceGit.ViewModels
|
|||
set => SetProperty(ref _editorFontSize, value);
|
||||
}
|
||||
|
||||
public int EditorTabWidth
|
||||
{
|
||||
get => _editorTabWidth;
|
||||
set => SetProperty(ref _editorTabWidth, value);
|
||||
}
|
||||
|
||||
public LayoutInfo Layout
|
||||
{
|
||||
get => _layout;
|
||||
|
@ -649,6 +655,7 @@ namespace SourceGit.ViewModels
|
|||
private bool _useSystemWindowFrame = false;
|
||||
private double _defaultFontSize = 13;
|
||||
private double _editorFontSize = 13;
|
||||
private int _editorTabWidth = 4;
|
||||
private LayoutInfo _layout = new LayoutInfo();
|
||||
|
||||
private int _maxHistoryCommits = 20000;
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
Foreground="{DynamicResource Brush.FG1}"
|
||||
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
|
||||
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
|
||||
BlameData="{Binding Data}"/>
|
||||
|
||||
<!-- Not supported mask (for binary files) -->
|
||||
|
|
|
@ -260,6 +260,15 @@ namespace SourceGit.Views
|
|||
set => SetValue(BlameDataProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<int> TabWidthProperty =
|
||||
AvaloniaProperty.Register<BlameTextEditor, int>(nameof(TabWidth), 4);
|
||||
|
||||
public int TabWidth
|
||||
{
|
||||
get => GetValue(TabWidthProperty);
|
||||
set => SetValue(TabWidthProperty, value);
|
||||
}
|
||||
|
||||
protected override Type StyleKeyOverride => typeof(TextEditor);
|
||||
|
||||
public BlameTextEditor() : base(new TextArea(), new TextDocument())
|
||||
|
@ -268,6 +277,10 @@ namespace SourceGit.Views
|
|||
ShowLineNumbers = false;
|
||||
WordWrap = false;
|
||||
|
||||
Options.IndentationSize = TabWidth;
|
||||
Options.EnableHyperlinks = false;
|
||||
Options.EnableEmailHyperlinks = false;
|
||||
|
||||
_textMate = Models.TextMateHelper.CreateForEditor(this);
|
||||
|
||||
TextArea.LeftMargins.Add(new LineNumberMargin() { Margin = new Thickness(8, 0) });
|
||||
|
@ -280,8 +293,6 @@ namespace SourceGit.Views
|
|||
TextArea.TextView.ContextRequested += OnTextViewContextRequested;
|
||||
TextArea.TextView.VisualLinesChanged += OnTextViewVisualLinesChanged;
|
||||
TextArea.TextView.Margin = new Thickness(4, 0);
|
||||
TextArea.TextView.Options.EnableHyperlinks = false;
|
||||
TextArea.TextView.Options.EnableEmailHyperlinks = false;
|
||||
}
|
||||
|
||||
public override void Render(DrawingContext context)
|
||||
|
@ -350,6 +361,10 @@ namespace SourceGit.Views
|
|||
Text = string.Empty;
|
||||
}
|
||||
}
|
||||
else if (change.Property == TabWidthProperty)
|
||||
{
|
||||
Options.IndentationSize = TabWidth;
|
||||
}
|
||||
else if (change.Property.Name == "ActualThemeVariant" && change.NewValue != null)
|
||||
{
|
||||
Models.TextMateHelper.SetThemeByApp(_textMate);
|
||||
|
|
|
@ -148,7 +148,7 @@
|
|||
<TabItem.Header>
|
||||
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Preferences.Appearance}"/>
|
||||
</TabItem.Header>
|
||||
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
|
||||
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
|
||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preferences.Appearance.Theme}"
|
||||
HorizontalAlignment="Right"
|
||||
|
@ -190,12 +190,12 @@
|
|||
Margin="0,0,16,0"/>
|
||||
<Grid Grid.Row="3" Grid.Column="1" ColumnDefinitions="*,8,*">
|
||||
<NumericUpDown Grid.Column="0"
|
||||
Minimum="10" Maximum="18" Increment="0.5"
|
||||
Height="28"
|
||||
Padding="4"
|
||||
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
|
||||
CornerRadius="3"
|
||||
Value="{Binding DefaultFontSize, Mode=TwoWay}">
|
||||
Minimum="10" Maximum="18" Increment="0.5"
|
||||
Height="28"
|
||||
Padding="4"
|
||||
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
|
||||
CornerRadius="3"
|
||||
Value="{Binding DefaultFontSize, Mode=TwoWay}">
|
||||
<NumericUpDown.InnerLeftContent>
|
||||
<Border BorderThickness="0,0,1,0" BorderBrush="{DynamicResource Brush.Border1}">
|
||||
<TextBlock Margin="4,0" Text="{DynamicResource Text.Preferences.Appearance.FontSize.Default}"/>
|
||||
|
@ -218,10 +218,23 @@
|
|||
</Grid>
|
||||
|
||||
<TextBlock Grid.Row="4" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preferences.Appearance.EditorTabWidth}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,16,0"/>
|
||||
<Grid Grid.Row="4" Grid.Column="1">
|
||||
<NumericUpDown Minimum="1" Maximum="16" Increment="1"
|
||||
Height="28"
|
||||
Padding="4"
|
||||
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
|
||||
CornerRadius="3"
|
||||
Value="{Binding EditorTabWidth, Mode=TwoWay}"/>
|
||||
</Grid>
|
||||
|
||||
<TextBlock Grid.Row="5" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preferences.Appearance.ThemeOverrides}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,16,0"/>
|
||||
<TextBox Grid.Row="4" Grid.Column="1"
|
||||
<TextBox Grid.Row="5" Grid.Column="1"
|
||||
Height="28"
|
||||
CornerRadius="3"
|
||||
Text="{Binding ThemeOverrides, Mode=TwoWay}">
|
||||
|
@ -232,16 +245,16 @@
|
|||
</TextBox.InnerRightContent>
|
||||
</TextBox>
|
||||
|
||||
<CheckBox Grid.Row="5" Grid.Column="1"
|
||||
<CheckBox Grid.Row="6" Grid.Column="1"
|
||||
Content="{DynamicResource Text.Preferences.Appearance.OnlyUseMonoFontInEditor}"
|
||||
IsChecked="{Binding OnlyUseMonoFontInEditor, Mode=TwoWay}"/>
|
||||
|
||||
<CheckBox Grid.Row="6" Grid.Column="1"
|
||||
<CheckBox Grid.Row="7" Grid.Column="1"
|
||||
Height="32"
|
||||
Content="{DynamicResource Text.Preferences.Appearance.UseFixedTabWidth}"
|
||||
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseFixedTabWidth, Mode=TwoWay}"/>
|
||||
|
||||
<CheckBox Grid.Row="7" Grid.Column="1"
|
||||
<CheckBox Grid.Row="8" Grid.Column="1"
|
||||
Height="32"
|
||||
Content="{DynamicResource Text.Preferences.Appearance.UseNativeWindowFrame}"
|
||||
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseSystemWindowFrame, Mode=OneTime}"
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
<DataTemplate DataType="m:RevisionTextFile">
|
||||
<v:RevisionTextFileView FontFamily="{DynamicResource Fonts.Monospace}"
|
||||
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
|
||||
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
|
||||
Background="{DynamicResource Brush.Contents}"/>
|
||||
</DataTemplate>
|
||||
|
||||
|
|
|
@ -15,6 +15,15 @@ namespace SourceGit.Views
|
|||
{
|
||||
public class RevisionTextFileView : TextEditor
|
||||
{
|
||||
public static readonly StyledProperty<int> TabWidthProperty =
|
||||
AvaloniaProperty.Register<RevisionTextFileView, int>(nameof(TabWidth), 4);
|
||||
|
||||
public int TabWidth
|
||||
{
|
||||
get => GetValue(TabWidthProperty);
|
||||
set => SetValue(TabWidthProperty, value);
|
||||
}
|
||||
|
||||
protected override Type StyleKeyOverride => typeof(TextEditor);
|
||||
|
||||
public RevisionTextFileView() : base(new TextArea(), new TextDocument())
|
||||
|
@ -22,13 +31,16 @@ namespace SourceGit.Views
|
|||
IsReadOnly = true;
|
||||
ShowLineNumbers = true;
|
||||
WordWrap = false;
|
||||
|
||||
Options.IndentationSize = TabWidth;
|
||||
Options.EnableHyperlinks = false;
|
||||
Options.EnableEmailHyperlinks = false;
|
||||
|
||||
HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
|
||||
VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
|
||||
|
||||
TextArea.LeftMargins[0].Margin = new Thickness(8, 0);
|
||||
TextArea.TextView.Margin = new Thickness(4, 0);
|
||||
TextArea.TextView.Options.EnableHyperlinks = false;
|
||||
TextArea.TextView.Options.EnableEmailHyperlinks = false;
|
||||
}
|
||||
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
|
@ -69,6 +81,16 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
|
||||
if (change.Property == TabWidthProperty)
|
||||
{
|
||||
Options.IndentationSize = TabWidth;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
|
||||
{
|
||||
var selected = SelectedText;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
IndicatorForeground="{DynamicResource Brush.FG2}"
|
||||
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
|
||||
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
|
||||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseSyntaxHighlighting}"
|
||||
WordWrap="{Binding Source={x:Static vm:Preferences.Instance}, Path=EnableDiffViewWordWrap}"
|
||||
ShowHiddenSymbols="{Binding Source={x:Static vm:Preferences.Instance}, Path=ShowHiddenSymbolsInDiffView}"
|
||||
|
@ -59,6 +60,7 @@
|
|||
IndicatorForeground="{DynamicResource Brush.FG2}"
|
||||
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
|
||||
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
|
||||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseSyntaxHighlighting}"
|
||||
WordWrap="False"
|
||||
ShowHiddenSymbols="{Binding Source={x:Static vm:Preferences.Instance}, Path=ShowHiddenSymbolsInDiffView}"
|
||||
|
@ -81,6 +83,7 @@
|
|||
IndicatorForeground="{DynamicResource Brush.FG2}"
|
||||
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
|
||||
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
|
||||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseSyntaxHighlighting}"
|
||||
WordWrap="False"
|
||||
ShowHiddenSymbols="{Binding Source={x:Static vm:Preferences.Instance}, Path=ShowHiddenSymbolsInDiffView}"
|
||||
|
|
|
@ -475,6 +475,15 @@ namespace SourceGit.Views
|
|||
set => SetValue(ShowHiddenSymbolsProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<int> TabWidthProperty =
|
||||
AvaloniaProperty.Register<ThemedTextDiffPresenter, int>(nameof(TabWidth), 4);
|
||||
|
||||
public int TabWidth
|
||||
{
|
||||
get => GetValue(TabWidthProperty);
|
||||
set => SetValue(TabWidthProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<bool> EnableChunkSelectionProperty =
|
||||
AvaloniaProperty.Register<ThemedTextDiffPresenter, bool>(nameof(EnableChunkSelection));
|
||||
|
||||
|
@ -519,12 +528,13 @@ namespace SourceGit.Views
|
|||
ShowLineNumbers = false;
|
||||
BorderThickness = new Thickness(0);
|
||||
|
||||
Options.IndentationSize = TabWidth;
|
||||
Options.EnableHyperlinks = false;
|
||||
Options.EnableEmailHyperlinks = false;
|
||||
|
||||
_lineStyleTransformer = new LineStyleTransformer(this);
|
||||
|
||||
TextArea.TextView.Margin = new Thickness(2, 0);
|
||||
TextArea.TextView.Options.EnableHyperlinks = false;
|
||||
TextArea.TextView.Options.EnableEmailHyperlinks = false;
|
||||
|
||||
TextArea.TextView.BackgroundRenderers.Add(new LineBackgroundRenderer(this));
|
||||
TextArea.TextView.LineTransformers.Add(_lineStyleTransformer);
|
||||
}
|
||||
|
@ -734,10 +744,14 @@ namespace SourceGit.Views
|
|||
}
|
||||
else if (change.Property == ShowHiddenSymbolsProperty)
|
||||
{
|
||||
var val = change.NewValue is true;
|
||||
var val = ShowHiddenSymbols;
|
||||
Options.ShowTabs = val;
|
||||
Options.ShowSpaces = val;
|
||||
}
|
||||
else if (change.Property == TabWidthProperty)
|
||||
{
|
||||
Options.IndentationSize = TabWidth;
|
||||
}
|
||||
else if (change.Property == FileNameProperty)
|
||||
{
|
||||
Models.TextMateHelper.SetGrammarByFileName(_textMate, FileName);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue