mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
refactor: rewrite the font configuration (#366)
* input font name directly instead of a font picker because localized font family name is not supported by Avalonia * fallback monospace font to default font * remove unused code
This commit is contained in:
parent
24dde77548
commit
9057b71f2d
20 changed files with 96 additions and 169 deletions
|
@ -20,20 +20,6 @@ namespace SourceGit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FontFamilyConverter : JsonConverter<FontFamily>
|
|
||||||
{
|
|
||||||
public override FontFamily Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
||||||
{
|
|
||||||
var name = reader.GetString();
|
|
||||||
return new FontFamily(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Write(Utf8JsonWriter writer, FontFamily value, JsonSerializerOptions options)
|
|
||||||
{
|
|
||||||
writer.WriteStringValue(value.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GridLengthConverter : JsonConverter<GridLength>
|
public class GridLengthConverter : JsonConverter<GridLength>
|
||||||
{
|
{
|
||||||
public override GridLength Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
public override GridLength Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
|
@ -54,7 +40,6 @@ namespace SourceGit
|
||||||
IgnoreReadOnlyProperties = true,
|
IgnoreReadOnlyProperties = true,
|
||||||
Converters = [
|
Converters = [
|
||||||
typeof(ColorConverter),
|
typeof(ColorConverter),
|
||||||
typeof(FontFamilyConverter),
|
|
||||||
typeof(GridLengthConverter),
|
typeof(GridLengthConverter),
|
||||||
]
|
]
|
||||||
)]
|
)]
|
||||||
|
|
|
@ -104,6 +104,7 @@ namespace SourceGit
|
||||||
var pref = ViewModels.Preference.Instance;
|
var pref = ViewModels.Preference.Instance;
|
||||||
SetLocale(pref.Locale);
|
SetLocale(pref.Locale);
|
||||||
SetTheme(pref.Theme, pref.ThemeOverrides);
|
SetTheme(pref.Theme, pref.ThemeOverrides);
|
||||||
|
SetFonts(pref.DefaultFontFamily, pref.MonospaceFontFamily, pref.OnlyUseMonoFontInEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnFrameworkInitializationCompleted()
|
public override void OnFrameworkInitializationCompleted()
|
||||||
|
@ -143,7 +144,10 @@ namespace SourceGit
|
||||||
public static void SetLocale(string localeKey)
|
public static void SetLocale(string localeKey)
|
||||||
{
|
{
|
||||||
var app = Current as App;
|
var app = Current as App;
|
||||||
var targetLocale = app?.Resources[localeKey] as ResourceDictionary;
|
if (app == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var targetLocale = app.Resources[localeKey] as ResourceDictionary;
|
||||||
if (targetLocale == null || targetLocale == app._activeLocale)
|
if (targetLocale == null || targetLocale == app._activeLocale)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -208,6 +212,46 @@ namespace SourceGit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SetFonts(string defaultFont, string monospaceFont, bool onlyUseMonospaceFontInEditor)
|
||||||
|
{
|
||||||
|
var app = Current as App;
|
||||||
|
if (app == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (app._fontsOverrides != null)
|
||||||
|
{
|
||||||
|
app.Resources.MergedDictionaries.Remove(app._fontsOverrides);
|
||||||
|
app._fontsOverrides = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var resDic = new ResourceDictionary();
|
||||||
|
if (!string.IsNullOrEmpty(defaultFont))
|
||||||
|
resDic.Add("Fonts.Default", new FontFamily(defaultFont));
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(monospaceFont))
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(defaultFont))
|
||||||
|
monospaceFont = $"fonts:SourceGit#JetBrains Mono,{defaultFont}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(defaultFont) && !monospaceFont.Contains(defaultFont, StringComparison.Ordinal))
|
||||||
|
monospaceFont = $"{monospaceFont},{defaultFont}";
|
||||||
|
|
||||||
|
resDic.Add("Fonts.Monospace", new FontFamily(monospaceFont));
|
||||||
|
}
|
||||||
|
|
||||||
|
var primary = onlyUseMonospaceFontInEditor ? defaultFont : monospaceFont;
|
||||||
|
if (!string.IsNullOrEmpty(primary))
|
||||||
|
resDic.Add("Fonts.Primary", new FontFamily(primary));
|
||||||
|
|
||||||
|
if (resDic.Count > 0)
|
||||||
|
{
|
||||||
|
app.Resources.MergedDictionaries.Add(resDic);
|
||||||
|
app._fontsOverrides = resDic;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static async void CopyText(string data)
|
public static async void CopyText(string data)
|
||||||
{
|
{
|
||||||
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
|
@ -510,5 +554,6 @@ namespace SourceGit
|
||||||
private ViewModels.Launcher _launcher = null;
|
private ViewModels.Launcher _launcher = null;
|
||||||
private ResourceDictionary _activeLocale = null;
|
private ResourceDictionary _activeLocale = null;
|
||||||
private ResourceDictionary _themeOverrides = null;
|
private ResourceDictionary _themeOverrides = null;
|
||||||
|
private ResourceDictionary _fontsOverrides = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ using System.IO;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Media;
|
|
||||||
|
|
||||||
namespace SourceGit.Native
|
namespace SourceGit.Native
|
||||||
{
|
{
|
||||||
|
@ -37,11 +36,6 @@ namespace SourceGit.Native
|
||||||
|
|
||||||
public void SetupApp(AppBuilder builder)
|
public void SetupApp(AppBuilder builder)
|
||||||
{
|
{
|
||||||
builder.With(new FontManagerOptions()
|
|
||||||
{
|
|
||||||
DefaultFamilyName = "fonts:SourceGit#JetBrains Mono",
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.With(new X11PlatformOptions()
|
builder.With(new X11PlatformOptions()
|
||||||
{
|
{
|
||||||
EnableIme = true,
|
EnableIme = true,
|
||||||
|
|
|
@ -6,7 +6,6 @@ using System.Runtime.Versioning;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Media;
|
|
||||||
|
|
||||||
namespace SourceGit.Native
|
namespace SourceGit.Native
|
||||||
{
|
{
|
||||||
|
@ -15,11 +14,6 @@ namespace SourceGit.Native
|
||||||
{
|
{
|
||||||
public void SetupApp(AppBuilder builder)
|
public void SetupApp(AppBuilder builder)
|
||||||
{
|
{
|
||||||
builder.With(new FontManagerOptions()
|
|
||||||
{
|
|
||||||
DefaultFamilyName = "PingFang SC",
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.With(new MacOSPlatformOptions()
|
builder.With(new MacOSPlatformOptions()
|
||||||
{
|
{
|
||||||
DisableDefaultApplicationMenuItems = true,
|
DisableDefaultApplicationMenuItems = true,
|
||||||
|
|
|
@ -8,7 +8,6 @@ using System.Text;
|
||||||
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Media;
|
|
||||||
|
|
||||||
namespace SourceGit.Native
|
namespace SourceGit.Native
|
||||||
{
|
{
|
||||||
|
@ -62,12 +61,6 @@ namespace SourceGit.Native
|
||||||
|
|
||||||
public void SetupApp(AppBuilder builder)
|
public void SetupApp(AppBuilder builder)
|
||||||
{
|
{
|
||||||
builder.With(new FontManagerOptions()
|
|
||||||
{
|
|
||||||
DefaultFamilyName = "Microsoft YaHei UI",
|
|
||||||
FontFallbacks = [new FontFallback { FontFamily = "Microsoft YaHei" }],
|
|
||||||
});
|
|
||||||
|
|
||||||
// Fix drop shadow issue on Windows 10
|
// Fix drop shadow issue on Windows 10
|
||||||
RTL_OSVERSIONINFOEX v = new RTL_OSVERSIONINFOEX();
|
RTL_OSVERSIONINFOEX v = new RTL_OSVERSIONINFOEX();
|
||||||
v.dwOSVersionInfoSize = (uint)Marshal.SizeOf<RTL_OSVERSIONINFOEX>();
|
v.dwOSVersionInfoSize = (uint)Marshal.SizeOf<RTL_OSVERSIONINFOEX>();
|
||||||
|
|
|
@ -156,7 +156,7 @@
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
<Style Selector="ContentPresenter">
|
<Style Selector="ContentPresenter">
|
||||||
<Setter Property="FontFamily" Value="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFont}"/>
|
<Setter Property="FontFamily" Value="{DynamicResource Fonts.Default}"/>
|
||||||
<Setter Property="FontSize" Value="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize}"/>
|
<Setter Property="FontSize" Value="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize}"/>
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@
|
||||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||||
<Setter Property="Foreground" Value="{DynamicResource Brush.FG1}"/>
|
<Setter Property="Foreground" Value="{DynamicResource Brush.FG1}"/>
|
||||||
<Setter Property="FontFamily" Value="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFont}"/>
|
<Setter Property="FontFamily" Value="{DynamicResource Fonts.Default}"/>
|
||||||
<Setter Property="FontSize" Value="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize}"/>
|
<Setter Property="FontSize" Value="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize}"/>
|
||||||
</Style>
|
</Style>
|
||||||
<Style Selector="TextBlock.small">
|
<Style Selector="TextBlock.small">
|
||||||
|
@ -264,7 +264,7 @@
|
||||||
<Setter Property="FontStyle" Value="Italic"/>
|
<Setter Property="FontStyle" Value="Italic"/>
|
||||||
</Style>
|
</Style>
|
||||||
<Style Selector="TextBlock.primary, SelectableTextBlock.primary">
|
<Style Selector="TextBlock.primary, SelectableTextBlock.primary">
|
||||||
<Setter Property="FontFamily" Value="{Binding Source={x:Static vm:Preference.Instance}, Path=PrimaryFont}"/>
|
<Setter Property="FontFamily" Value="{DynamicResource Fonts.Primary}"/>
|
||||||
</Style>
|
</Style>
|
||||||
<Style Selector="TextBlock.group_header_label">
|
<Style Selector="TextBlock.group_header_label">
|
||||||
<Setter Property="Foreground" Value="{DynamicResource Brush.FG2}"/>
|
<Setter Property="Foreground" Value="{DynamicResource Brush.FG2}"/>
|
||||||
|
|
|
@ -103,4 +103,8 @@
|
||||||
<SolidColorBrush x:Key="Brush.Diff.AddedHighlight" Color="{DynamicResource Color.Diff.AddedHighlight}"/>
|
<SolidColorBrush x:Key="Brush.Diff.AddedHighlight" Color="{DynamicResource Color.Diff.AddedHighlight}"/>
|
||||||
<SolidColorBrush x:Key="Brush.Diff.DeletedHighlight" Color="{DynamicResource Color.Diff.DeletedHighlight}"/>
|
<SolidColorBrush x:Key="Brush.Diff.DeletedHighlight" Color="{DynamicResource Color.Diff.DeletedHighlight}"/>
|
||||||
<SolidColorBrush x:Key="Brush.Link" Color="{DynamicResource Color.Link}"/>
|
<SolidColorBrush x:Key="Brush.Link" Color="{DynamicResource Color.Link}"/>
|
||||||
|
|
||||||
|
<FontFamily x:Key="Fonts.Default">$Default</FontFamily>
|
||||||
|
<FontFamily x:Key="Fonts.Monospace">fonts:SourceGit#JetBrains Mono,$Default</FontFamily>
|
||||||
|
<FontFamily x:Key="Fonts.Primary">fonts:SourceGit#JetBrains Mono,$Default</FontFamily>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
|
|
|
@ -5,7 +5,6 @@ using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
using Avalonia.Collections;
|
using Avalonia.Collections;
|
||||||
using Avalonia.Media;
|
|
||||||
|
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
|
@ -20,6 +19,7 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
if (_instance == null)
|
if (_instance == null)
|
||||||
{
|
{
|
||||||
|
_isLoading = true;
|
||||||
if (!File.Exists(_savePath))
|
if (!File.Exists(_savePath))
|
||||||
{
|
{
|
||||||
_instance = new Preference();
|
_instance = new Preference();
|
||||||
|
@ -35,14 +35,9 @@ namespace SourceGit.ViewModels
|
||||||
_instance = new Preference();
|
_instance = new Preference();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_isLoading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_instance.DefaultFont == null)
|
|
||||||
_instance.DefaultFont = FontManager.Current.DefaultFontFamily;
|
|
||||||
|
|
||||||
if (_instance.MonospaceFont == null)
|
|
||||||
_instance.MonospaceFont = new FontFamily("fonts:SourceGit#JetBrains Mono");
|
|
||||||
|
|
||||||
if (!_instance.IsGitConfigured())
|
if (!_instance.IsGitConfigured())
|
||||||
_instance.GitInstallPath = Native.OS.FindGitExecutable();
|
_instance.GitInstallPath = Native.OS.FindGitExecutable();
|
||||||
|
|
||||||
|
@ -55,7 +50,7 @@ namespace SourceGit.ViewModels
|
||||||
get => _locale;
|
get => _locale;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (SetProperty(ref _locale, value))
|
if (SetProperty(ref _locale, value) && !_isLoading)
|
||||||
App.SetLocale(value);
|
App.SetLocale(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +60,7 @@ namespace SourceGit.ViewModels
|
||||||
get => _theme;
|
get => _theme;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (SetProperty(ref _theme, value))
|
if (SetProperty(ref _theme, value) && !_isLoading)
|
||||||
App.SetTheme(_theme, _themeOverrides);
|
App.SetTheme(_theme, _themeOverrides);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,44 +70,37 @@ namespace SourceGit.ViewModels
|
||||||
get => _themeOverrides;
|
get => _themeOverrides;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (SetProperty(ref _themeOverrides, value))
|
if (SetProperty(ref _themeOverrides, value) && !_isLoading)
|
||||||
App.SetTheme(_theme, value);
|
App.SetTheme(_theme, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FontFamily DefaultFont
|
public string DefaultFontFamily
|
||||||
{
|
{
|
||||||
get => _defaultFont;
|
get => _defaultFontFamily;
|
||||||
set
|
set {
|
||||||
{
|
if (SetProperty(ref _defaultFontFamily, value) && !_isLoading)
|
||||||
if (SetProperty(ref _defaultFont, value) && _onlyUseMonoFontInEditor)
|
App.SetFonts(_defaultFontFamily, _monospaceFontFamily, _onlyUseMonoFontInEditor);
|
||||||
OnPropertyChanged(nameof(PrimaryFont));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FontFamily MonospaceFont
|
public string MonospaceFontFamily
|
||||||
{
|
{
|
||||||
get => _monospaceFont;
|
get => _monospaceFontFamily;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (SetProperty(ref _monospaceFont, value) && !_onlyUseMonoFontInEditor)
|
if (SetProperty(ref _monospaceFontFamily, value) && !_isLoading)
|
||||||
OnPropertyChanged(nameof(PrimaryFont));
|
App.SetFonts(_defaultFontFamily, _monospaceFontFamily, _onlyUseMonoFontInEditor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
public FontFamily PrimaryFont
|
|
||||||
{
|
|
||||||
get => _onlyUseMonoFontInEditor ? _defaultFont : _monospaceFont;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool OnlyUseMonoFontInEditor
|
public bool OnlyUseMonoFontInEditor
|
||||||
{
|
{
|
||||||
get => _onlyUseMonoFontInEditor;
|
get => _onlyUseMonoFontInEditor;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (SetProperty(ref _onlyUseMonoFontInEditor, value))
|
if (SetProperty(ref _onlyUseMonoFontInEditor, value) && !_isLoading)
|
||||||
OnPropertyChanged(nameof(PrimaryFont));
|
App.SetFonts(_defaultFontFamily, _monospaceFontFamily, _onlyUseMonoFontInEditor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,13 +482,14 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Preference _instance = null;
|
private static Preference _instance = null;
|
||||||
|
private static bool _isLoading = false;
|
||||||
private static readonly string _savePath = Path.Combine(Native.OS.DataDir, "preference.json");
|
private static readonly string _savePath = Path.Combine(Native.OS.DataDir, "preference.json");
|
||||||
|
|
||||||
private string _locale = "en_US";
|
private string _locale = "en_US";
|
||||||
private string _theme = "Default";
|
private string _theme = "Default";
|
||||||
private string _themeOverrides = string.Empty;
|
private string _themeOverrides = string.Empty;
|
||||||
private FontFamily _defaultFont = null;
|
private string _defaultFontFamily = string.Empty;
|
||||||
private FontFamily _monospaceFont = null;
|
private string _monospaceFontFamily = string.Empty;
|
||||||
private bool _onlyUseMonoFontInEditor = false;
|
private bool _onlyUseMonoFontInEditor = false;
|
||||||
private double _defaultFontSize = 13;
|
private double _defaultFontSize = 13;
|
||||||
private LayoutInfo _layout = new LayoutInfo();
|
private LayoutInfo _layout = new LayoutInfo();
|
||||||
|
|
|
@ -105,7 +105,8 @@ namespace SourceGit.Views
|
||||||
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
|
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
|
||||||
};
|
};
|
||||||
|
|
||||||
var typeface = new Typeface("fonts:SourceGit#JetBrains Mono");
|
var fontFamily = avatar.FindResource("Fonts.Monospace") as FontFamily;
|
||||||
|
var typeface = new Typeface(fontFamily);
|
||||||
|
|
||||||
avatar._fallbackLabel = new FormattedText(
|
avatar._fallbackLabel = new FormattedText(
|
||||||
placeholder,
|
placeholder,
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
BorderThickness="1"
|
BorderThickness="1"
|
||||||
Background="{DynamicResource Brush.Contents}"
|
Background="{DynamicResource Brush.Contents}"
|
||||||
Foreground="{DynamicResource Brush.FG1}"
|
Foreground="{DynamicResource Brush.FG1}"
|
||||||
FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}"
|
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||||
BlameData="{Binding Data}"/>
|
BlameData="{Binding Data}"/>
|
||||||
|
|
||||||
<!-- Not supported mask (for binary files) -->
|
<!-- Not supported mask (for binary files) -->
|
||||||
|
|
|
@ -86,7 +86,7 @@
|
||||||
<v:BranchTreeNodeTrackStatusPresenter Grid.Column="2"
|
<v:BranchTreeNodeTrackStatusPresenter Grid.Column="2"
|
||||||
Margin="8,0"
|
Margin="8,0"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}"
|
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||||
FontSize="10"
|
FontSize="10"
|
||||||
Foreground="{DynamicResource Brush.BadgeFG}"
|
Foreground="{DynamicResource Brush.BadgeFG}"
|
||||||
Background="{DynamicResource Brush.Badge}"/>
|
Background="{DynamicResource Brush.Badge}"/>
|
||||||
|
|
|
@ -91,7 +91,8 @@ namespace SourceGit.Views
|
||||||
if (Change == null || Bounds.Width <= 0)
|
if (Change == null || Bounds.Width <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var typeface = new Typeface("fonts:SourceGit#JetBrains Mono");
|
var fontFamily = this.FindResource("Fonts.Monospace") as FontFamily;
|
||||||
|
var typeface = new Typeface(fontFamily);
|
||||||
|
|
||||||
IBrush background;
|
IBrush background;
|
||||||
string indicator;
|
string indicator;
|
||||||
|
|
|
@ -96,7 +96,7 @@
|
||||||
BranchNameBackground="{DynamicResource Brush.DecoratorBranch}"
|
BranchNameBackground="{DynamicResource Brush.DecoratorBranch}"
|
||||||
TagNameBackground="{DynamicResource Brush.DecoratorTag}"
|
TagNameBackground="{DynamicResource Brush.DecoratorTag}"
|
||||||
LabelForeground="{DynamicResource Brush.DecoratorFG}"
|
LabelForeground="{DynamicResource Brush.DecoratorFG}"
|
||||||
FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}"
|
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||||
FontSize="10"
|
FontSize="10"
|
||||||
VerticalAlignment="Center"/>
|
VerticalAlignment="Center"/>
|
||||||
</Border>
|
</Border>
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
BranchNameBackground="{DynamicResource Brush.DecoratorBranch}"
|
BranchNameBackground="{DynamicResource Brush.DecoratorBranch}"
|
||||||
TagNameBackground="{DynamicResource Brush.DecoratorTag}"
|
TagNameBackground="{DynamicResource Brush.DecoratorTag}"
|
||||||
LabelForeground="{DynamicResource Brush.DecoratorFG}"
|
LabelForeground="{DynamicResource Brush.DecoratorFG}"
|
||||||
FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}"
|
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||||
FontSize="10"
|
FontSize="10"
|
||||||
VerticalAlignment="Center"/>
|
VerticalAlignment="Center"/>
|
||||||
|
|
||||||
|
|
|
@ -157,39 +157,19 @@
|
||||||
Text="{DynamicResource Text.Preference.Appearance.DefaultFont}"
|
Text="{DynamicResource Text.Preference.Appearance.DefaultFont}"
|
||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
Margin="0,0,16,0"/>
|
Margin="0,0,16,0"/>
|
||||||
<ComboBox Grid.Row="1" Grid.Column="1"
|
<TextBox Grid.Row="1" Grid.Column="1"
|
||||||
MinHeight="28"
|
Height="28"
|
||||||
Padding="8,0"
|
CornerRadius="3"
|
||||||
HorizontalAlignment="Stretch"
|
Text="{Binding DefaultFontFamily, Mode=TwoWay}"/>
|
||||||
ItemsSource="{Binding #ThisControl.InstalledFonts}"
|
|
||||||
SelectedItem="{Binding DefaultFont, Mode=TwoWay}">
|
|
||||||
<ComboBox.ItemTemplate>
|
|
||||||
<DataTemplate DataType="FontFamily">
|
|
||||||
<Border Height="24">
|
|
||||||
<TextBlock VerticalAlignment="Center" Text="{Binding Name}" FontFamily="{Binding}"/>
|
|
||||||
</Border>
|
|
||||||
</DataTemplate>
|
|
||||||
</ComboBox.ItemTemplate>
|
|
||||||
</ComboBox>
|
|
||||||
|
|
||||||
<TextBlock Grid.Row="2" Grid.Column="0"
|
<TextBlock Grid.Row="2" Grid.Column="0"
|
||||||
Text="{DynamicResource Text.Preference.Appearance.MonospaceFont}"
|
Text="{DynamicResource Text.Preference.Appearance.MonospaceFont}"
|
||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
Margin="0,0,16,0"/>
|
Margin="0,0,16,0"/>
|
||||||
<ComboBox Grid.Row="2" Grid.Column="1"
|
<TextBox Grid.Row="2" Grid.Column="1"
|
||||||
MinHeight="28"
|
Height="28"
|
||||||
Padding="8,0"
|
CornerRadius="3"
|
||||||
HorizontalAlignment="Stretch"
|
Text="{Binding MonospaceFontFamily, Mode=TwoWay}"/>
|
||||||
ItemsSource="{Binding #ThisControl.InstalledMonospaceFonts}"
|
|
||||||
SelectedItem="{Binding MonospaceFont, Mode=TwoWay}">
|
|
||||||
<ComboBox.ItemTemplate>
|
|
||||||
<DataTemplate DataType="FontFamily">
|
|
||||||
<Border Height="24">
|
|
||||||
<TextBlock VerticalAlignment="Center" Text="{Binding Name}" FontFamily="{Binding}"/>
|
|
||||||
</Border>
|
|
||||||
</DataTemplate>
|
|
||||||
</ComboBox.ItemTemplate>
|
|
||||||
</ComboBox>
|
|
||||||
|
|
||||||
<TextBlock Grid.Row="3" Grid.Column="0"
|
<TextBlock Grid.Row="3" Grid.Column="0"
|
||||||
Text="{DynamicResource Text.Preference.Appearance.DefaultFontSize}"
|
Text="{DynamicResource Text.Preference.Appearance.DefaultFontSize}"
|
||||||
|
|
|
@ -1,30 +1,15 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Collections;
|
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Media;
|
|
||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
using Avalonia.Threading;
|
|
||||||
|
|
||||||
namespace SourceGit.Views
|
namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
public partial class Preference : ChromelessWindow
|
public partial class Preference : ChromelessWindow
|
||||||
{
|
{
|
||||||
public AvaloniaList<FontFamily> InstalledFonts
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AvaloniaList<FontFamily> InstalledMonospaceFonts
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string DefaultUser
|
public string DefaultUser
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
@ -93,51 +78,6 @@ namespace SourceGit.Views
|
||||||
var pref = ViewModels.Preference.Instance;
|
var pref = ViewModels.Preference.Instance;
|
||||||
DataContext = pref;
|
DataContext = pref;
|
||||||
|
|
||||||
var builtInMono = new FontFamily("fonts:SourceGit#JetBrains Mono");
|
|
||||||
|
|
||||||
InstalledFonts = new AvaloniaList<FontFamily>();
|
|
||||||
InstalledFonts.Add(builtInMono);
|
|
||||||
InstalledFonts.AddRange(FontManager.Current.SystemFonts);
|
|
||||||
|
|
||||||
InstalledMonospaceFonts = new AvaloniaList<FontFamily>();
|
|
||||||
InstalledMonospaceFonts.Add(builtInMono);
|
|
||||||
|
|
||||||
var curMonoFont = pref.MonospaceFont;
|
|
||||||
if (curMonoFont != builtInMono)
|
|
||||||
{
|
|
||||||
InstalledMonospaceFonts.Add(curMonoFont);
|
|
||||||
}
|
|
||||||
|
|
||||||
Task.Run(() =>
|
|
||||||
{
|
|
||||||
var sysMonoFonts = new List<FontFamily>();
|
|
||||||
foreach (var font in FontManager.Current.SystemFonts)
|
|
||||||
{
|
|
||||||
if (font == curMonoFont)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var typeface = new Typeface(font);
|
|
||||||
var testI = new FormattedText(
|
|
||||||
"i",
|
|
||||||
CultureInfo.CurrentCulture,
|
|
||||||
FlowDirection.LeftToRight,
|
|
||||||
typeface,
|
|
||||||
12,
|
|
||||||
Brushes.White);
|
|
||||||
var testW = new FormattedText(
|
|
||||||
"W",
|
|
||||||
CultureInfo.CurrentCulture,
|
|
||||||
FlowDirection.LeftToRight,
|
|
||||||
typeface,
|
|
||||||
12,
|
|
||||||
Brushes.White);
|
|
||||||
if (Math.Abs(testI.Width - testW.Width) < 0.0001)
|
|
||||||
sysMonoFonts.Add(font);
|
|
||||||
}
|
|
||||||
|
|
||||||
Dispatcher.UIThread.Post(() => InstalledMonospaceFonts.AddRange(sysMonoFonts));
|
|
||||||
});
|
|
||||||
|
|
||||||
var ver = string.Empty;
|
var ver = string.Empty;
|
||||||
if (pref.IsGitConfigured())
|
if (pref.IsGitConfigured())
|
||||||
{
|
{
|
||||||
|
|
|
@ -95,7 +95,7 @@
|
||||||
Margin="6,0"
|
Margin="6,0"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Count="{Binding LocalChangesCount}"
|
Count="{Binding LocalChangesCount}"
|
||||||
FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}"
|
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||||
FontSize="10"
|
FontSize="10"
|
||||||
Foreground="{DynamicResource Brush.BadgeFG}"
|
Foreground="{DynamicResource Brush.BadgeFG}"
|
||||||
Background="{DynamicResource Brush.Badge}"/>
|
Background="{DynamicResource Brush.Badge}"/>
|
||||||
|
@ -110,7 +110,7 @@
|
||||||
Margin="6,0"
|
Margin="6,0"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Count="{Binding StashesCount}"
|
Count="{Binding StashesCount}"
|
||||||
FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}"
|
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||||
FontSize="10"
|
FontSize="10"
|
||||||
Foreground="{DynamicResource Brush.BadgeFG}"
|
Foreground="{DynamicResource Brush.BadgeFG}"
|
||||||
Background="{DynamicResource Brush.Badge}"/>
|
Background="{DynamicResource Brush.Badge}"/>
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate DataType="m:RevisionTextFile">
|
<DataTemplate DataType="m:RevisionTextFile">
|
||||||
<v:RevisionTextFileView FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}" Background="{DynamicResource Brush.Contents}"/>
|
<v:RevisionTextFileView FontFamily="{DynamicResource Fonts.Monospace}" Background="{DynamicResource Brush.Contents}"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate DataType="m:RevisionImageFile">
|
<DataTemplate DataType="m:RevisionImageFile">
|
||||||
|
|
|
@ -86,7 +86,8 @@ namespace SourceGit.Views
|
||||||
else
|
else
|
||||||
maxV = (int)Math.Ceiling(maxV / 500.0) * 500;
|
maxV = (int)Math.Ceiling(maxV / 500.0) * 500;
|
||||||
|
|
||||||
var typeface = new Typeface("fonts:SourceGit#JetBrains Mono");
|
var fontFamily = this.FindResource("Fonts.Monospace") as FontFamily;
|
||||||
|
var typeface = new Typeface(fontFamily);
|
||||||
var pen = new Pen(LineBrush);
|
var pen = new Pen(LineBrush);
|
||||||
var width = Bounds.Width;
|
var width = Bounds.Width;
|
||||||
var height = Bounds.Height;
|
var height = Bounds.Height;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
AddedHighlightBrush="{DynamicResource Brush.Diff.AddedHighlight}"
|
AddedHighlightBrush="{DynamicResource Brush.Diff.AddedHighlight}"
|
||||||
DeletedHighlightBrush="{DynamicResource Brush.Diff.DeletedHighlight}"
|
DeletedHighlightBrush="{DynamicResource Brush.Diff.DeletedHighlight}"
|
||||||
IndicatorForeground="{DynamicResource Brush.FG2}"
|
IndicatorForeground="{DynamicResource Brush.FG2}"
|
||||||
FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}"
|
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
|
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
|
||||||
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
|
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
|
||||||
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
|
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
AddedHighlightBrush="{DynamicResource Brush.Diff.AddedHighlight}"
|
AddedHighlightBrush="{DynamicResource Brush.Diff.AddedHighlight}"
|
||||||
DeletedHighlightBrush="{DynamicResource Brush.Diff.DeletedHighlight}"
|
DeletedHighlightBrush="{DynamicResource Brush.Diff.DeletedHighlight}"
|
||||||
IndicatorForeground="{DynamicResource Brush.FG2}"
|
IndicatorForeground="{DynamicResource Brush.FG2}"
|
||||||
FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}"
|
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
|
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
|
||||||
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
|
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
|
||||||
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
|
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
AddedHighlightBrush="{DynamicResource Brush.Diff.AddedHighlight}"
|
AddedHighlightBrush="{DynamicResource Brush.Diff.AddedHighlight}"
|
||||||
DeletedHighlightBrush="{DynamicResource Brush.Diff.DeletedHighlight}"
|
DeletedHighlightBrush="{DynamicResource Brush.Diff.DeletedHighlight}"
|
||||||
IndicatorForeground="{DynamicResource Brush.FG2}"
|
IndicatorForeground="{DynamicResource Brush.FG2}"
|
||||||
FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}"
|
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
|
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
|
||||||
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
|
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
|
||||||
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
|
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
|
||||||
|
|
Loading…
Reference in a new issue