mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
refactor: rename Models.CustomColorSchema
to Models.ThemeOverrides
because it do NOT contains only colors currently.
This commit is contained in:
parent
af388bad60
commit
16d9b627f0
12 changed files with 49 additions and 74 deletions
|
@ -6,8 +6,8 @@ namespace SourceGit
|
|||
[JsonSourceGenerationOptions(WriteIndented = true, IgnoreReadOnlyFields = true, IgnoreReadOnlyProperties = true)]
|
||||
[JsonSerializable(typeof(List<Models.InteractiveRebaseJob>))]
|
||||
[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 { }
|
||||
|
|
|
@ -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,22 +154,19 @@ 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);
|
||||
|
@ -178,40 +174,30 @@ namespace SourceGit
|
|||
resDic[$"Color.{kv.Key}"] = Color.Parse(kv.Value);
|
||||
}
|
||||
|
||||
|
||||
if (schema.Graph.Count > 0)
|
||||
if (overrides.GraphColors.Count > 0)
|
||||
{
|
||||
var penColors = new List<Color>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,30 +108,21 @@ namespace SourceGit.Models
|
|||
private set;
|
||||
} = new List<Pen>();
|
||||
|
||||
public static void SetDefaultPens()
|
||||
public static void SetDefaultPens(double thickness = 1.5)
|
||||
{
|
||||
SetPenColors(_defaultPenColors);
|
||||
SetPens(_defaultPenColors, thickness);
|
||||
}
|
||||
|
||||
public static void SetPenColors(List<Color> colors)
|
||||
public static void SetPens(List<Color> 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<Commit> 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<Color> _defaultPenColors = [
|
||||
Colors.Orange,
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public class CustomColorSchema
|
||||
{
|
||||
public Dictionary<string, string> Basic { get; set; } = new Dictionary<string, string>();
|
||||
public List<string> Graph { get; set; } = new List<string>();
|
||||
public Dictionary<string,string> General { get; set; } = new Dictionary<string, string>();
|
||||
}
|
||||
}
|
11
src/Models/ThemeOverrides.cs
Normal file
11
src/Models/ThemeOverrides.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public class ThemeOverrides
|
||||
{
|
||||
public Dictionary<string, string> BasicColors { get; set; } = new Dictionary<string, string>();
|
||||
public double GraphPenThickness { get; set; } = 1.5;
|
||||
public List<string> GraphColors { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
|
@ -337,11 +337,11 @@
|
|||
<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>
|
||||
<x:String x:Key="Text.Preference.Appearance.Theme" xml:space="preserve">Theme</x:String>
|
||||
<x:String x:Key="Text.Preference.Appearance.ThemeOverrides" xml:space="preserve">Theme Overrides</x:String>
|
||||
<x:String x:Key="Text.Preference.General" xml:space="preserve">GENERAL</x:String>
|
||||
<x:String x:Key="Text.Preference.General.AvatarServer" xml:space="preserve">Avatar Server</x:String>
|
||||
<x:String x:Key="Text.Preference.General.Check4UpdatesOnStartup" xml:space="preserve">Check for updates on startup</x:String>
|
||||
|
|
|
@ -340,11 +340,11 @@
|
|||
<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>
|
||||
<x:String x:Key="Text.Preference.Appearance.Theme" xml:space="preserve">主题</x:String>
|
||||
<x:String x:Key="Text.Preference.Appearance.ThemeOverrides" xml:space="preserve">主题自定义</x:String>
|
||||
<x:String x:Key="Text.Preference.General" xml:space="preserve">通用配置</x:String>
|
||||
<x:String x:Key="Text.Preference.General.AvatarServer" xml:space="preserve">头像服务</x:String>
|
||||
<x:String x:Key="Text.Preference.General.Check4UpdatesOnStartup" xml:space="preserve">启动时检测软件更新</x:String>
|
||||
|
|
|
@ -340,11 +340,11 @@
|
|||
<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>
|
||||
<x:String x:Key="Text.Preference.Appearance.Theme" xml:space="preserve">主題</x:String>
|
||||
<x:String x:Key="Text.Preference.Appearance.ThemeOverrides" xml:space="preserve">主題自訂</x:String>
|
||||
<x:String x:Key="Text.Preference.General" xml:space="preserve">通用配置</x:String>
|
||||
<x:String x:Key="Text.Preference.General.AvatarServer" xml:space="preserve">頭像服務</x:String>
|
||||
<x:String x:Key="Text.Preference.General.Check4UpdatesOnStartup" xml:space="preserve">啟動時檢測軟體更新</x:String>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
|
|
|
@ -229,15 +229,15 @@
|
|||
Value="{Binding DefaultFontSize, Mode=TwoWay}"/>
|
||||
|
||||
<TextBlock Grid.Row="4" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.Appearance.ColorOverrides}"
|
||||
Text="{DynamicResource Text.Preference.Appearance.ThemeOverrides}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,16,0"/>
|
||||
<TextBox Grid.Row="4" Grid.Column="1"
|
||||
Height="28"
|
||||
CornerRadius="3"
|
||||
Text="{Binding ColorOverrides, Mode=TwoWay}">
|
||||
Text="{Binding ThemeOverrides, Mode=TwoWay}">
|
||||
<TextBox.InnerRightContent>
|
||||
<Button Classes="icon_button" Width="30" Height="30" Click="SelectColorSchemaFile">
|
||||
<Button Classes="icon_button" Width="30" Height="30" Click="SelectThemeOverrideFile">
|
||||
<Path Data="{StaticResource Icons.Folder.Open}" Fill="{DynamicResource Brush.FG1}"/>
|
||||
</Button>
|
||||
</TextBox.InnerRightContent>
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue