diff --git a/src/App.JsonCodeGen.cs b/src/App.JsonCodeGen.cs index 901a9b5b..ba6bd96c 100644 --- a/src/App.JsonCodeGen.cs +++ b/src/App.JsonCodeGen.cs @@ -6,8 +6,8 @@ namespace SourceGit [JsonSourceGenerationOptions(WriteIndented = true, IgnoreReadOnlyFields = true, IgnoreReadOnlyProperties = true)] [JsonSerializable(typeof(List))] [JsonSerializable(typeof(Models.JetBrainsState))] + [JsonSerializable(typeof(Models.ThemeOverrides))] [JsonSerializable(typeof(Models.Version))] - [JsonSerializable(typeof(Models.CustomColorSchema))] [JsonSerializable(typeof(ViewModels.Preference))] [JsonSerializable(typeof(ViewModels.RepositorySettings))] internal partial class JsonCodeGen : JsonSerializerContext { } diff --git a/src/App.axaml.cs b/src/App.axaml.cs index 785b511c..8c9738fa 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.IO; using System.Net.Http; using System.Reflection; @@ -144,7 +143,7 @@ namespace SourceGit app._activeLocale = targetLocale; } - public static void SetTheme(string theme, string colorsFile) + public static void SetTheme(string theme, string themeOverridesFile) { var app = Current as App; @@ -155,63 +154,50 @@ namespace SourceGit else app.RequestedThemeVariant = ThemeVariant.Default; - if (app._colorOverrides != null) + if (app._themeOverrides != null) { - app.Resources.MergedDictionaries.Remove(app._colorOverrides); - app._colorOverrides = null; + app.Resources.MergedDictionaries.Remove(app._themeOverrides); + app._themeOverrides = null; } - Models.CommitGraph.SetDefaultPens(); - - if (!string.IsNullOrEmpty(colorsFile) && File.Exists(colorsFile)) + if (!string.IsNullOrEmpty(themeOverridesFile) && File.Exists(themeOverridesFile)) { try { var resDic = new ResourceDictionary(); - - var schema = JsonSerializer.Deserialize(File.ReadAllText(colorsFile), JsonCodeGen.Default.CustomColorSchema); - foreach (var kv in schema.Basic) + var overrides = JsonSerializer.Deserialize(File.ReadAllText(themeOverridesFile), JsonCodeGen.Default.ThemeOverrides); + foreach (var kv in overrides.BasicColors) { if (kv.Key.Equals("SystemAccentColor", StringComparison.Ordinal)) resDic["SystemAccentColor"] = Color.Parse(kv.Value); else resDic[$"Color.{kv.Key}"] = Color.Parse(kv.Value); } - - if (schema.Graph.Count > 0) + if (overrides.GraphColors.Count > 0) { var penColors = new List(); - - foreach (var c in schema.Graph) + foreach (var c in overrides.GraphColors) penColors.Add(Color.Parse(c)); - Models.CommitGraph.SetPenColors(penColors); + Models.CommitGraph.SetPens(penColors, overrides.GraphPenThickness); } - - foreach (var kv in schema.General) + else { - if (kv.Key.Equals("Pen.Thickness", StringComparison.Ordinal)) - { - double thick = Models.CommitGraph.GetPenThickness(); - try - { - thick = double.Parse(kv.Value, CultureInfo.InvariantCulture); - } - catch - { - } - Models.CommitGraph.SetPenThickness(thick); - } + Models.CommitGraph.SetDefaultPens(overrides.GraphPenThickness); } app.Resources.MergedDictionaries.Add(resDic); - app._colorOverrides = resDic; + app._themeOverrides = resDic; } catch { } } + else + { + Models.CommitGraph.SetDefaultPens(); + } } public static async void CopyText(string data) @@ -338,7 +324,7 @@ namespace SourceGit var pref = ViewModels.Preference.Instance; SetLocale(pref.Locale); - SetTheme(pref.Theme, pref.ColorOverrides); + SetTheme(pref.Theme, pref.ThemeOverrides); } public override void OnFrameworkInitializationCompleted() @@ -383,6 +369,6 @@ namespace SourceGit private ViewModels.Launcher _launcher = null; private ResourceDictionary _activeLocale = null; - private ResourceDictionary _colorOverrides = null; + private ResourceDictionary _themeOverrides = null; } } diff --git a/src/Models/CommitGraph.cs b/src/Models/CommitGraph.cs index c0ffe820..9ed99904 100644 --- a/src/Models/CommitGraph.cs +++ b/src/Models/CommitGraph.cs @@ -108,30 +108,21 @@ namespace SourceGit.Models private set; } = new List(); - public static void SetDefaultPens() + public static void SetDefaultPens(double thickness = 1.5) { - SetPenColors(_defaultPenColors); + SetPens(_defaultPenColors, thickness); } - public static void SetPenColors(List colors) + public static void SetPens(List colors, double thickness) { Pens.Clear(); foreach (var c in colors) - Pens.Add(new Pen(c.ToUInt32(), 2)); + Pens.Add(new Pen(c.ToUInt32(), thickness)); _penCount = colors.Count; } - public static void SetPenThickness(double value) - { - _penThickness = value; - } - public static double GetPenThickness() - { - return _penThickness; - } - public static CommitGraph Parse(List commits) { double UNIT_WIDTH = 12; @@ -277,7 +268,6 @@ namespace SourceGit.Models return temp; } - private static double _penThickness = 1; private static int _penCount = 0; private static readonly List _defaultPenColors = [ Colors.Orange, diff --git a/src/Models/CustomColorSchema.cs b/src/Models/CustomColorSchema.cs deleted file mode 100644 index 943b916e..00000000 --- a/src/Models/CustomColorSchema.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; - -namespace SourceGit.Models -{ - public class CustomColorSchema - { - public Dictionary Basic { get; set; } = new Dictionary(); - public List Graph { get; set; } = new List(); - public Dictionary General { get; set; } = new Dictionary(); - } -} diff --git a/src/Models/ThemeOverrides.cs b/src/Models/ThemeOverrides.cs new file mode 100644 index 00000000..96e48f82 --- /dev/null +++ b/src/Models/ThemeOverrides.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace SourceGit.Models +{ + public class ThemeOverrides + { + public Dictionary BasicColors { get; set; } = new Dictionary(); + public double GraphPenThickness { get; set; } = 1.5; + public List GraphColors { get; set; } = new List(); + } +} diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 55b05a01..271a52dd 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -337,11 +337,11 @@ Paste Preference APPEARANCE - Custom Color Schema Default Font Default Font Size Monospace Font Theme + Theme Overrides GENERAL Avatar Server Check for updates on startup diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 58a72d47..adf03079 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -340,11 +340,11 @@ 粘贴 偏好设置 外观配置 - 自定义配色文件 缺省字体 默认字体大小 等宽字体 主题 + 主题自定义 通用配置 头像服务 启动时检测软件更新 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 73176126..d8d22032 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -340,11 +340,11 @@ 貼上 偏好設定 外觀配置 - 自訂配色檔 預設字型 預設字型大小 等寬字型 主題 + 主題自訂 通用配置 頭像服務 啟動時檢測軟體更新 diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index 5198a8b8..431fd8d8 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -66,16 +66,16 @@ namespace SourceGit.ViewModels set { if (SetProperty(ref _theme, value)) - App.SetTheme(_theme, _colorOverrides); + App.SetTheme(_theme, _themeOverrides); } } - public string ColorOverrides + public string ThemeOverrides { - get => _colorOverrides; + get => _themeOverrides; set { - if (SetProperty(ref _colorOverrides, value)) + if (SetProperty(ref _themeOverrides, value)) App.SetTheme(_theme, value); } } @@ -487,7 +487,7 @@ namespace SourceGit.ViewModels private string _locale = "en_US"; private string _theme = "Default"; - private string _colorOverrides = string.Empty; + private string _themeOverrides = string.Empty; private FontFamily _defaultFont = null; private FontFamily _monospaceFont = null; private double _defaultFontSize = 13; diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index 6ac67d0b..05fe1a81 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -158,7 +158,6 @@ namespace SourceGit.Views var geo = new StreamGeometry(); var pen = Models.CommitGraph.Pens[line.Color]; - pen.Thickness = Models.CommitGraph.GetPenThickness(); using (var ctx = geo.Open()) { diff --git a/src/Views/Preference.axaml b/src/Views/Preference.axaml index 56561c46..5ca3b83f 100644 --- a/src/Views/Preference.axaml +++ b/src/Views/Preference.axaml @@ -229,15 +229,15 @@ Value="{Binding DefaultFontSize, Mode=TwoWay}"/> + Text="{Binding ThemeOverrides, Mode=TwoWay}"> - diff --git a/src/Views/Preference.axaml.cs b/src/Views/Preference.axaml.cs index 0bc477f3..d483659c 100644 --- a/src/Views/Preference.axaml.cs +++ b/src/Views/Preference.axaml.cs @@ -210,18 +210,18 @@ namespace SourceGit.Views Close(); } - private async void SelectColorSchemaFile(object sender, RoutedEventArgs e) + private async void SelectThemeOverrideFile(object sender, RoutedEventArgs e) { var options = new FilePickerOpenOptions() { - FileTypeFilter = [new FilePickerFileType("Theme Color Schema File") { Patterns = ["*.json"] }], + FileTypeFilter = [new FilePickerFileType("Theme Overrides File") { Patterns = ["*.json"] }], AllowMultiple = false, }; var selected = await StorageProvider.OpenFilePickerAsync(options); if (selected.Count == 1) { - ViewModels.Preference.Instance.ColorOverrides = selected[0].Path.LocalPath; + ViewModels.Preference.Instance.ThemeOverrides = selected[0].Path.LocalPath; } e.Handled = true;