mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
enhance: supports user overrides the default color schema
This commit is contained in:
parent
9aca84533c
commit
62e5ed8a42
9 changed files with 91 additions and 22 deletions
|
@ -1,10 +1,12 @@
|
||||||
using System.Text.Json.Serialization;
|
using System.Collections.Generic;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace SourceGit
|
namespace SourceGit
|
||||||
{
|
{
|
||||||
[JsonSourceGenerationOptions(WriteIndented = true, IgnoreReadOnlyFields = true, IgnoreReadOnlyProperties = true)]
|
[JsonSourceGenerationOptions(WriteIndented = true, IgnoreReadOnlyFields = true, IgnoreReadOnlyProperties = true)]
|
||||||
[JsonSerializable(typeof(Models.Version))]
|
[JsonSerializable(typeof(Models.Version))]
|
||||||
[JsonSerializable(typeof(Models.JetBrainsState))]
|
[JsonSerializable(typeof(Models.JetBrainsState))]
|
||||||
|
[JsonSerializable(typeof(Dictionary<string, string>))]
|
||||||
[JsonSerializable(typeof(ViewModels.Preference))]
|
[JsonSerializable(typeof(ViewModels.Preference))]
|
||||||
internal partial class JsonCodeGen : JsonSerializerContext { }
|
internal partial class JsonCodeGen : JsonSerializerContext { }
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,19 +145,44 @@ namespace SourceGit
|
||||||
app._activeLocale = targetLocale;
|
app._activeLocale = targetLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetTheme(string theme)
|
public static void SetTheme(string theme, string colorsFile)
|
||||||
{
|
{
|
||||||
|
var app = Current as App;
|
||||||
|
|
||||||
if (theme.Equals("Light", StringComparison.OrdinalIgnoreCase))
|
if (theme.Equals("Light", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
Current.RequestedThemeVariant = ThemeVariant.Light;
|
app.RequestedThemeVariant = ThemeVariant.Light;
|
||||||
}
|
}
|
||||||
else if (theme.Equals("Dark", StringComparison.OrdinalIgnoreCase))
|
else if (theme.Equals("Dark", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
Current.RequestedThemeVariant = ThemeVariant.Dark;
|
app.RequestedThemeVariant = ThemeVariant.Dark;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Current.RequestedThemeVariant = ThemeVariant.Default;
|
app.RequestedThemeVariant = ThemeVariant.Default;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (app._colorOverrides != null)
|
||||||
|
{
|
||||||
|
app.Resources.MergedDictionaries.Remove(app._colorOverrides);
|
||||||
|
app._colorOverrides = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(colorsFile) && File.Exists(colorsFile))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var resDic = new ResourceDictionary();
|
||||||
|
var schema = JsonSerializer.Deserialize(File.ReadAllText(colorsFile), JsonCodeGen.Default.DictionaryStringString);
|
||||||
|
foreach (var kv in schema)
|
||||||
|
resDic[kv.Key] = Color.Parse(kv.Value);
|
||||||
|
|
||||||
|
app.Resources.MergedDictionaries.Add(resDic);
|
||||||
|
app._colorOverrides = resDic;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +281,7 @@ namespace SourceGit
|
||||||
var pref = ViewModels.Preference.Instance;
|
var pref = ViewModels.Preference.Instance;
|
||||||
|
|
||||||
SetLocale(pref.Locale);
|
SetLocale(pref.Locale);
|
||||||
SetTheme(pref.Theme);
|
SetTheme(pref.Theme, pref.ColorOverrides);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnFrameworkInitializationCompleted()
|
public override void OnFrameworkInitializationCompleted()
|
||||||
|
@ -300,6 +325,7 @@ namespace SourceGit
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResourceDictionary _activeLocale = null;
|
private ResourceDictionary _activeLocale = null;
|
||||||
|
private ResourceDictionary _colorOverrides = null;
|
||||||
private Models.INotificationReceiver _notificationReceiver = null;
|
private Models.INotificationReceiver _notificationReceiver = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,6 +286,7 @@
|
||||||
<x:String x:Key="Text.Paste" xml:space="preserve">Paste</x:String>
|
<x:String x:Key="Text.Paste" xml:space="preserve">Paste</x:String>
|
||||||
<x:String x:Key="Text.Preference" xml:space="preserve">Preference</x:String>
|
<x:String x:Key="Text.Preference" xml:space="preserve">Preference</x:String>
|
||||||
<x:String x:Key="Text.Preference.Appearance" xml:space="preserve">APPEARANCE</x:String>
|
<x:String x:Key="Text.Preference.Appearance" xml:space="preserve">APPEARANCE</x:String>
|
||||||
|
<x:String x:Key="Text.Preference.Appearance.ColorOverrides" xml:space="preserve">Custom Color Schema</x:String>
|
||||||
<x:String x:Key="Text.Preference.Appearance.DefaultFont" xml:space="preserve">Default Font</x:String>
|
<x:String x:Key="Text.Preference.Appearance.DefaultFont" xml:space="preserve">Default Font</x:String>
|
||||||
<x:String x:Key="Text.Preference.Appearance.DefaultFontSize" xml:space="preserve">Default Font Size</x:String>
|
<x:String x:Key="Text.Preference.Appearance.DefaultFontSize" xml:space="preserve">Default Font Size</x:String>
|
||||||
<x:String x:Key="Text.Preference.Appearance.MonospaceFont" xml:space="preserve">Monospace Font</x:String>
|
<x:String x:Key="Text.Preference.Appearance.MonospaceFont" xml:space="preserve">Monospace Font</x:String>
|
||||||
|
|
|
@ -289,6 +289,7 @@
|
||||||
<x:String x:Key="Text.Paste" xml:space="preserve">粘贴</x:String>
|
<x:String x:Key="Text.Paste" xml:space="preserve">粘贴</x:String>
|
||||||
<x:String x:Key="Text.Preference" xml:space="preserve">偏好设置</x:String>
|
<x:String x:Key="Text.Preference" xml:space="preserve">偏好设置</x:String>
|
||||||
<x:String x:Key="Text.Preference.Appearance" xml:space="preserve">外观配置</x:String>
|
<x:String x:Key="Text.Preference.Appearance" xml:space="preserve">外观配置</x:String>
|
||||||
|
<x:String x:Key="Text.Preference.Appearance.ColorOverrides" xml:space="preserve">自定义配色文件</x:String>
|
||||||
<x:String x:Key="Text.Preference.Appearance.DefaultFont" xml:space="preserve">缺省字体</x:String>
|
<x:String x:Key="Text.Preference.Appearance.DefaultFont" xml:space="preserve">缺省字体</x:String>
|
||||||
<x:String x:Key="Text.Preference.Appearance.DefaultFontSize" xml:space="preserve">默认字体大小</x:String>
|
<x:String x:Key="Text.Preference.Appearance.DefaultFontSize" xml:space="preserve">默认字体大小</x:String>
|
||||||
<x:String x:Key="Text.Preference.Appearance.MonospaceFont" xml:space="preserve">等宽字体</x:String>
|
<x:String x:Key="Text.Preference.Appearance.MonospaceFont" xml:space="preserve">等宽字体</x:String>
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
<Color x:Key="Color.TitleBar">#FF1F1F1F</Color>
|
<Color x:Key="Color.TitleBar">#FF1F1F1F</Color>
|
||||||
<Color x:Key="Color.ToolBar">#FF2C2C2C</Color>
|
<Color x:Key="Color.ToolBar">#FF2C2C2C</Color>
|
||||||
<Color x:Key="Color.Popup">#FF2B2B2B</Color>
|
<Color x:Key="Color.Popup">#FF2B2B2B</Color>
|
||||||
<Color x:Key="Color.Contents">#FF181818</Color>
|
<Color x:Key="Color.Contents">#FF1B1B1B</Color>
|
||||||
<Color x:Key="Color.Badge">#FF8F8F8F</Color>
|
<Color x:Key="Color.Badge">#FF8F8F8F</Color>
|
||||||
<Color x:Key="Color.Decorator">#FF505050</Color>
|
<Color x:Key="Color.Decorator">#FF505050</Color>
|
||||||
<Color x:Key="Color.DecoratorIcon">#FFF8F8F8</Color>
|
<Color x:Key="Color.DecoratorIcon">#FFF8F8F8</Color>
|
||||||
|
|
|
@ -65,11 +65,9 @@ namespace SourceGit.ViewModels
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (SetProperty(ref _locale, value))
|
if (SetProperty(ref _locale, value))
|
||||||
{
|
|
||||||
App.SetLocale(value);
|
App.SetLocale(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public string Theme
|
public string Theme
|
||||||
{
|
{
|
||||||
|
@ -77,10 +75,18 @@ namespace SourceGit.ViewModels
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (SetProperty(ref _theme, value))
|
if (SetProperty(ref _theme, value))
|
||||||
{
|
App.SetTheme(_theme, _colorOverrides);
|
||||||
App.SetTheme(value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ColorOverrides
|
||||||
|
{
|
||||||
|
get => _colorOverrides;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (SetProperty(ref _colorOverrides, value))
|
||||||
|
App.SetTheme(_theme, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonConverter(typeof(FontFamilyConverter))]
|
[JsonConverter(typeof(FontFamilyConverter))]
|
||||||
|
@ -521,6 +527,7 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
private string _locale = "en_US";
|
private string _locale = "en_US";
|
||||||
private string _theme = "Default";
|
private string _theme = "Default";
|
||||||
|
private string _colorOverrides = string.Empty;
|
||||||
private FontFamily _defaultFont = null;
|
private FontFamily _defaultFont = null;
|
||||||
private FontFamily _monospaceFont = null;
|
private FontFamily _monospaceFont = null;
|
||||||
private double _defaultFontSize = 13;
|
private double _defaultFontSize = 13;
|
||||||
|
|
|
@ -144,7 +144,7 @@
|
||||||
<TabItem.Header>
|
<TabItem.Header>
|
||||||
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Preference.Appearance}"/>
|
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Preference.Appearance}"/>
|
||||||
</TabItem.Header>
|
</TabItem.Header>
|
||||||
<Grid Margin="8" RowDefinitions="32,32,32,32" ColumnDefinitions="Auto,*">
|
<Grid Margin="8" RowDefinitions="32,32,32,32,32" ColumnDefinitions="Auto,*">
|
||||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||||
Text="{DynamicResource Text.Preference.Appearance.Theme}"
|
Text="{DynamicResource Text.Preference.Appearance.Theme}"
|
||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
|
@ -163,10 +163,25 @@
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
|
|
||||||
<TextBlock Grid.Row="1" Grid.Column="0"
|
<TextBlock Grid.Row="1" Grid.Column="0"
|
||||||
|
Text="{DynamicResource Text.Preference.Appearance.ColorOverrides}"
|
||||||
|
HorizontalAlignment="Right"
|
||||||
|
Margin="0,0,16,0"/>
|
||||||
|
<TextBox Grid.Row="1" Grid.Column="1"
|
||||||
|
Height="28"
|
||||||
|
CornerRadius="3"
|
||||||
|
Text="{Binding ColorOverrides, Mode=TwoWay}">
|
||||||
|
<TextBox.InnerRightContent>
|
||||||
|
<Button Classes="icon_button" Width="30" Height="30" Click="SelectColorSchemaFile">
|
||||||
|
<Path Data="{StaticResource Icons.Folder.Open}" Fill="{DynamicResource Brush.FG1}"/>
|
||||||
|
</Button>
|
||||||
|
</TextBox.InnerRightContent>
|
||||||
|
</TextBox>
|
||||||
|
|
||||||
|
<TextBlock Grid.Row="2" Grid.Column="0"
|
||||||
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"
|
<ComboBox Grid.Row="2" Grid.Column="1"
|
||||||
MinHeight="28"
|
MinHeight="28"
|
||||||
Padding="8,0"
|
Padding="8,0"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
|
@ -181,11 +196,11 @@
|
||||||
</ComboBox.ItemTemplate>
|
</ComboBox.ItemTemplate>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
|
|
||||||
<TextBlock Grid.Row="2" Grid.Column="0"
|
<TextBlock Grid.Row="3" 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"
|
<ComboBox Grid.Row="3" Grid.Column="1"
|
||||||
MinHeight="28"
|
MinHeight="28"
|
||||||
Padding="8,0"
|
Padding="8,0"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
|
@ -200,11 +215,11 @@
|
||||||
</ComboBox.ItemTemplate>
|
</ComboBox.ItemTemplate>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
|
|
||||||
<TextBlock Grid.Row="3" Grid.Column="0"
|
<TextBlock Grid.Row="4" Grid.Column="0"
|
||||||
Text="{DynamicResource Text.Preference.Appearance.DefaultFontSize}"
|
Text="{DynamicResource Text.Preference.Appearance.DefaultFontSize}"
|
||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
Margin="0,0,16,0"/>
|
Margin="0,0,16,0"/>
|
||||||
<NumericUpDown Grid.Row="3" Grid.Column="1"
|
<NumericUpDown Grid.Row="4" Grid.Column="1"
|
||||||
Minimum="10" Maximum="16" Increment="0.5"
|
Minimum="10" Maximum="16" Increment="0.5"
|
||||||
Height="28"
|
Height="28"
|
||||||
Padding="4"
|
Padding="4"
|
||||||
|
|
|
@ -214,6 +214,23 @@ namespace SourceGit.Views
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void SelectColorSchemaFile(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var options = new FilePickerOpenOptions()
|
||||||
|
{
|
||||||
|
FileTypeFilter = [new FilePickerFileType("Theme Color Schema File") { Patterns = ["*.json"] }],
|
||||||
|
AllowMultiple = false,
|
||||||
|
};
|
||||||
|
|
||||||
|
var selected = await StorageProvider.OpenFilePickerAsync(options);
|
||||||
|
if (selected.Count == 1)
|
||||||
|
{
|
||||||
|
ViewModels.Preference.Instance.ColorOverrides = selected[0].Path.LocalPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
private async void SelectGitExecutable(object sender, RoutedEventArgs e)
|
private async void SelectGitExecutable(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var pattern = OperatingSystem.IsWindows() ? "git.exe" : "git";
|
var pattern = OperatingSystem.IsWindows() ? "git.exe" : "git";
|
||||||
|
|
|
@ -119,8 +119,8 @@ namespace SourceGit.Views
|
||||||
public class LineBackgroundRenderer : IBackgroundRenderer
|
public class LineBackgroundRenderer : IBackgroundRenderer
|
||||||
{
|
{
|
||||||
private static readonly Brush BG_EMPTY = new SolidColorBrush(Color.FromArgb(60, 0, 0, 0));
|
private static readonly Brush BG_EMPTY = new SolidColorBrush(Color.FromArgb(60, 0, 0, 0));
|
||||||
private static readonly Brush BG_ADDED = new SolidColorBrush(Color.FromArgb(60, 0, 255, 0));
|
private static readonly Brush BG_ADDED = new SolidColorBrush(Color.FromArgb(50, 0, 255, 0));
|
||||||
private static readonly Brush BG_DELETED = new SolidColorBrush(Color.FromArgb(60, 255, 0, 0));
|
private static readonly Brush BG_DELETED = new SolidColorBrush(Color.FromArgb(50, 255, 0, 0));
|
||||||
|
|
||||||
public KnownLayer Layer => KnownLayer.Background;
|
public KnownLayer Layer => KnownLayer.Background;
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
public class LineStyleTransformer : DocumentColorizingTransformer
|
public class LineStyleTransformer : DocumentColorizingTransformer
|
||||||
{
|
{
|
||||||
private static readonly Brush HL_ADDED = new SolidColorBrush(Color.FromArgb(90, 0, 255, 0));
|
private static readonly Brush HL_ADDED = new SolidColorBrush(Color.FromArgb(128, 0, 190, 0));
|
||||||
private static readonly Brush HL_DELETED = new SolidColorBrush(Color.FromArgb(80, 255, 0, 0));
|
private static readonly Brush HL_DELETED = new SolidColorBrush(Color.FromArgb(80, 255, 0, 0));
|
||||||
|
|
||||||
public LineStyleTransformer(CombinedTextDiffPresenter editor)
|
public LineStyleTransformer(CombinedTextDiffPresenter editor)
|
||||||
|
|
Loading…
Reference in a new issue