mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37: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
|
||||
{
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, IgnoreReadOnlyFields = true, IgnoreReadOnlyProperties = true)]
|
||||
[JsonSerializable(typeof(Models.Version))]
|
||||
[JsonSerializable(typeof(Models.JetBrainsState))]
|
||||
[JsonSerializable(typeof(Dictionary<string, string>))]
|
||||
[JsonSerializable(typeof(ViewModels.Preference))]
|
||||
internal partial class JsonCodeGen : JsonSerializerContext { }
|
||||
}
|
||||
|
|
|
@ -145,19 +145,44 @@ namespace SourceGit
|
|||
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))
|
||||
{
|
||||
Current.RequestedThemeVariant = ThemeVariant.Light;
|
||||
app.RequestedThemeVariant = ThemeVariant.Light;
|
||||
}
|
||||
else if (theme.Equals("Dark", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Current.RequestedThemeVariant = ThemeVariant.Dark;
|
||||
app.RequestedThemeVariant = ThemeVariant.Dark;
|
||||
}
|
||||
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;
|
||||
|
||||
SetLocale(pref.Locale);
|
||||
SetTheme(pref.Theme);
|
||||
SetTheme(pref.Theme, pref.ColorOverrides);
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
|
@ -300,6 +325,7 @@ namespace SourceGit
|
|||
}
|
||||
|
||||
private ResourceDictionary _activeLocale = null;
|
||||
private ResourceDictionary _colorOverrides = 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.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.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.DefaultFontSize" xml:space="preserve">Default Font Size</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.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.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.DefaultFontSize" 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.ToolBar">#FF2C2C2C</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.Decorator">#FF505050</Color>
|
||||
<Color x:Key="Color.DecoratorIcon">#FFF8F8F8</Color>
|
||||
|
|
|
@ -65,9 +65,7 @@ namespace SourceGit.ViewModels
|
|||
set
|
||||
{
|
||||
if (SetProperty(ref _locale, value))
|
||||
{
|
||||
App.SetLocale(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,9 +75,17 @@ namespace SourceGit.ViewModels
|
|||
set
|
||||
{
|
||||
if (SetProperty(ref _theme, value))
|
||||
{
|
||||
App.SetTheme(value);
|
||||
}
|
||||
App.SetTheme(_theme, _colorOverrides);
|
||||
}
|
||||
}
|
||||
|
||||
public string ColorOverrides
|
||||
{
|
||||
get => _colorOverrides;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _colorOverrides, value))
|
||||
App.SetTheme(_theme, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -521,6 +527,7 @@ namespace SourceGit.ViewModels
|
|||
|
||||
private string _locale = "en_US";
|
||||
private string _theme = "Default";
|
||||
private string _colorOverrides = string.Empty;
|
||||
private FontFamily _defaultFont = null;
|
||||
private FontFamily _monospaceFont = null;
|
||||
private double _defaultFontSize = 13;
|
||||
|
|
|
@ -144,7 +144,7 @@
|
|||
<TabItem.Header>
|
||||
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Preference.Appearance}"/>
|
||||
</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"
|
||||
Text="{DynamicResource Text.Preference.Appearance.Theme}"
|
||||
HorizontalAlignment="Right"
|
||||
|
@ -161,12 +161,27 @@
|
|||
<ThemeVariant>Light</ThemeVariant>
|
||||
</ComboBox.Items>
|
||||
</ComboBox>
|
||||
|
||||
|
||||
<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}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,16,0"/>
|
||||
<ComboBox Grid.Row="1" Grid.Column="1"
|
||||
<ComboBox Grid.Row="2" Grid.Column="1"
|
||||
MinHeight="28"
|
||||
Padding="8,0"
|
||||
HorizontalAlignment="Stretch"
|
||||
|
@ -181,11 +196,11 @@
|
|||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0"
|
||||
<TextBlock Grid.Row="3" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.Appearance.MonospaceFont}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,16,0"/>
|
||||
<ComboBox Grid.Row="2" Grid.Column="1"
|
||||
<ComboBox Grid.Row="3" Grid.Column="1"
|
||||
MinHeight="28"
|
||||
Padding="8,0"
|
||||
HorizontalAlignment="Stretch"
|
||||
|
@ -200,11 +215,11 @@
|
|||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock Grid.Row="3" Grid.Column="0"
|
||||
<TextBlock Grid.Row="4" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.Appearance.DefaultFontSize}"
|
||||
HorizontalAlignment="Right"
|
||||
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"
|
||||
Height="28"
|
||||
Padding="4"
|
||||
|
|
|
@ -214,6 +214,23 @@ namespace SourceGit.Views
|
|||
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)
|
||||
{
|
||||
var pattern = OperatingSystem.IsWindows() ? "git.exe" : "git";
|
||||
|
|
|
@ -119,8 +119,8 @@ namespace SourceGit.Views
|
|||
public class LineBackgroundRenderer : IBackgroundRenderer
|
||||
{
|
||||
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_DELETED = new SolidColorBrush(Color.FromArgb(60, 255, 0, 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(50, 255, 0, 0));
|
||||
|
||||
public KnownLayer Layer => KnownLayer.Background;
|
||||
|
||||
|
@ -174,7 +174,7 @@ namespace SourceGit.Views
|
|||
|
||||
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));
|
||||
|
||||
public LineStyleTransformer(CombinedTextDiffPresenter editor)
|
||||
|
|
Loading…
Reference in a new issue