mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
ux: new custom theme configuration format
* supports customize the commit graph
This commit is contained in:
parent
c170f261db
commit
80f72676ec
5 changed files with 68 additions and 21 deletions
|
@ -4,10 +4,10 @@ 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.JetBrainsState))]
|
|
||||||
[JsonSerializable(typeof(List<Models.InteractiveRebaseJob>))]
|
[JsonSerializable(typeof(List<Models.InteractiveRebaseJob>))]
|
||||||
[JsonSerializable(typeof(Dictionary<string, string>))]
|
[JsonSerializable(typeof(Models.JetBrainsState))]
|
||||||
|
[JsonSerializable(typeof(Models.Version))]
|
||||||
|
[JsonSerializable(typeof(Models.CustomColorSchema))]
|
||||||
[JsonSerializable(typeof(ViewModels.Preference))]
|
[JsonSerializable(typeof(ViewModels.Preference))]
|
||||||
[JsonSerializable(typeof(ViewModels.RepositorySettings))]
|
[JsonSerializable(typeof(ViewModels.RepositorySettings))]
|
||||||
internal partial class JsonCodeGen : JsonSerializerContext { }
|
internal partial class JsonCodeGen : JsonSerializerContext { }
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
@ -159,15 +160,27 @@ namespace SourceGit
|
||||||
app._colorOverrides = null;
|
app._colorOverrides = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Models.CommitGraph.SetDefaultPens();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(colorsFile) && File.Exists(colorsFile))
|
if (!string.IsNullOrEmpty(colorsFile) && File.Exists(colorsFile))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var resDic = new ResourceDictionary();
|
var resDic = new ResourceDictionary();
|
||||||
|
|
||||||
var schema = JsonSerializer.Deserialize(File.ReadAllText(colorsFile), JsonCodeGen.Default.DictionaryStringString);
|
var schema = JsonSerializer.Deserialize(File.ReadAllText(colorsFile), JsonCodeGen.Default.CustomColorSchema);
|
||||||
foreach (var kv in schema)
|
foreach (var kv in schema.Basic)
|
||||||
resDic[kv.Key] = Color.Parse(kv.Value);
|
resDic[$"Color.{kv.Key}"] = Color.Parse(kv.Value);
|
||||||
|
|
||||||
|
if (schema.Graph.Count > 0)
|
||||||
|
{
|
||||||
|
var penColors = new List<Color>();
|
||||||
|
|
||||||
|
foreach (var c in schema.Graph)
|
||||||
|
penColors.Add(Color.Parse(c));
|
||||||
|
|
||||||
|
Models.CommitGraph.SetPenColors(penColors);
|
||||||
|
}
|
||||||
|
|
||||||
app.Resources.MergedDictionaries.Add(resDic);
|
app.Resources.MergedDictionaries.Add(resDic);
|
||||||
app._colorOverrides = resDic;
|
app._colorOverrides = resDic;
|
||||||
|
|
|
@ -8,17 +8,6 @@ namespace SourceGit.Models
|
||||||
{
|
{
|
||||||
public class CommitGraph
|
public class CommitGraph
|
||||||
{
|
{
|
||||||
public static readonly Pen[] Pens = [
|
|
||||||
new Pen(Brushes.Orange, 2),
|
|
||||||
new Pen(Brushes.ForestGreen, 2),
|
|
||||||
new Pen(Brushes.Gold, 2),
|
|
||||||
new Pen(Brushes.Magenta, 2),
|
|
||||||
new Pen(Brushes.Red, 2),
|
|
||||||
new Pen(Brushes.Gray, 2),
|
|
||||||
new Pen(Brushes.Turquoise, 2),
|
|
||||||
new Pen(Brushes.Olive, 2),
|
|
||||||
];
|
|
||||||
|
|
||||||
public class Path
|
public class Path
|
||||||
{
|
{
|
||||||
public List<Point> Points = new List<Point>();
|
public List<Point> Points = new List<Point>();
|
||||||
|
@ -113,7 +102,28 @@ namespace SourceGit.Models
|
||||||
public List<Link> Links { get; set; } = new List<Link>();
|
public List<Link> Links { get; set; } = new List<Link>();
|
||||||
public List<Dot> Dots { get; set; } = new List<Dot>();
|
public List<Dot> Dots { get; set; } = new List<Dot>();
|
||||||
|
|
||||||
public static CommitGraph Parse(List<Commit> commits, int colorCount)
|
public static List<Pen> Pens
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
} = new List<Pen>();
|
||||||
|
|
||||||
|
public static void SetDefaultPens()
|
||||||
|
{
|
||||||
|
SetPenColors(_defaultPenColors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetPenColors(List<Color> colors)
|
||||||
|
{
|
||||||
|
Pens.Clear();
|
||||||
|
|
||||||
|
foreach (var c in colors)
|
||||||
|
Pens.Add(new Pen(c.ToUInt32(), 2));
|
||||||
|
|
||||||
|
_penCount = colors.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommitGraph Parse(List<Commit> commits)
|
||||||
{
|
{
|
||||||
double UNIT_WIDTH = 12;
|
double UNIT_WIDTH = 12;
|
||||||
double HALF_WIDTH = 6;
|
double HALF_WIDTH = 6;
|
||||||
|
@ -184,7 +194,7 @@ namespace SourceGit.Models
|
||||||
major = new PathHelper(commit.Parents[0], isMerged, colorIdx, new Point(offsetX, offsetY));
|
major = new PathHelper(commit.Parents[0], isMerged, colorIdx, new Point(offsetX, offsetY));
|
||||||
unsolved.Add(major);
|
unsolved.Add(major);
|
||||||
temp.Paths.Add(major.Path);
|
temp.Paths.Add(major.Path);
|
||||||
colorIdx = (colorIdx + 1) % colorCount;
|
colorIdx = (colorIdx + 1) % _penCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate link position of this commit.
|
// Calculate link position of this commit.
|
||||||
|
@ -223,7 +233,7 @@ namespace SourceGit.Models
|
||||||
var l = new PathHelper(commit.Parents[j], isMerged, colorIdx, position, new Point(offsetX, position.Y + HALF_HEIGHT));
|
var l = new PathHelper(commit.Parents[j], isMerged, colorIdx, position, new Point(offsetX, position.Y + HALF_HEIGHT));
|
||||||
unsolved.Add(l);
|
unsolved.Add(l);
|
||||||
temp.Paths.Add(l.Path);
|
temp.Paths.Add(l.Path);
|
||||||
colorIdx = (colorIdx + 1) % colorCount;
|
colorIdx = (colorIdx + 1) % _penCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,5 +267,19 @@ namespace SourceGit.Models
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int _penCount = 0;
|
||||||
|
private static readonly List<Color> _defaultPenColors = [
|
||||||
|
Colors.Orange,
|
||||||
|
Colors.ForestGreen,
|
||||||
|
Colors.Gold,
|
||||||
|
Colors.Magenta,
|
||||||
|
Colors.Red,
|
||||||
|
Colors.Gray,
|
||||||
|
Colors.Turquoise,
|
||||||
|
Colors.Olive,
|
||||||
|
Colors.Khaki,
|
||||||
|
Colors.Lime,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
src/Models/CustomColorSchema.cs
Normal file
10
src/Models/CustomColorSchema.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
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>();
|
||||||
|
}
|
||||||
|
}
|
|
@ -709,7 +709,7 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
|
|
||||||
var commits = new Commands.QueryCommits(FullPath, limits).Result();
|
var commits = new Commands.QueryCommits(FullPath, limits).Result();
|
||||||
var graph = Models.CommitGraph.Parse(commits, 8);
|
var graph = Models.CommitGraph.Parse(commits);
|
||||||
|
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue