feature: add option to only highlight current branch in commit graph (#848)

- add a toggle button to only highlight current branch in commit graph
- re-order buttons in histories toolbar
- remove unused icons and styles
This commit is contained in:
leo 2025-01-06 14:59:27 +08:00
parent 65e820e4d5
commit 26ebd5ae7e
No known key found for this signature in database
20 changed files with 194 additions and 120 deletions

View file

@ -25,10 +25,11 @@ namespace SourceGit.Models
s_penCount = colors.Count;
}
public class Path(int color)
public class Path(int color, bool isMerged)
{
public List<Point> Points { get; } = [];
public int Color { get; } = color;
public bool IsMerged { get; } = isMerged;
}
public class Link
@ -37,6 +38,7 @@ namespace SourceGit.Models
public Point Control;
public Point End;
public int Color;
public bool IsMerged;
}
public enum DotType
@ -51,6 +53,7 @@ namespace SourceGit.Models
public DotType Type;
public Point Center;
public int Color;
public bool IsMerged;
}
public List<Path> Paths { get; } = [];
@ -108,7 +111,6 @@ namespace SourceGit.Models
}
isMerged = isMerged || l.IsMerged;
major.IsMerged = isMerged;
}
else
{
@ -122,7 +124,8 @@ namespace SourceGit.Models
unsolved.Remove(l);
ended.Clear();
// Create new curve for branch head
// If no path found, create new curve for branch head
// Otherwise, create new curve for new merged commit
if (major == null)
{
offsetX += unitWidth;
@ -136,11 +139,16 @@ namespace SourceGit.Models
colorIdx = (colorIdx + 1) % s_penCount;
}
else if (isMerged && !major.IsMerged && commit.Parents.Count > 0)
{
major.ReplaceMerged();
temp.Paths.Add(major.Path);
}
// Calculate link position of this commit.
var position = new Point(major?.LastX ?? offsetX, offsetY);
var dotColor = major?.Path.Color ?? 0;
var anchor = new Dot() { Center = position, Color = dotColor };
var anchor = new Dot() { Center = position, Color = dotColor, IsMerged = isMerged };
if (commit.IsCurrentHead)
anchor.Type = DotType.Head;
else if (commit.Parents.Count > 1)
@ -158,16 +166,20 @@ namespace SourceGit.Models
var parent = unsolved.Find(x => x.Next.Equals(parentHash, StringComparison.Ordinal));
if (parent != null)
{
// Try to change the merge state of linked graph
if (isMerged)
parent.IsMerged = true;
if (isMerged && !parent.IsMerged)
{
parent.Goto(parent.LastX, offsetY + halfHeight, halfHeight);
parent.ReplaceMerged();
temp.Paths.Add(parent.Path);
}
temp.Links.Add(new Link
{
Start = position,
End = new Point(parent.LastX, offsetY + halfHeight),
Control = new Point(parent.LastX, position.Y),
Color = parent.Path.Color
Color = parent.Path.Color,
IsMerged = isMerged,
});
}
else
@ -207,30 +219,29 @@ namespace SourceGit.Models
private class PathHelper
{
public Path Path { get; }
public Path Path { get; private set; }
public string Next { get; set; }
public bool IsMerged { get; set; }
public double LastX { get; private set; }
public bool IsMerged => Path.IsMerged;
public PathHelper(string next, bool isMerged, int color, Point start)
{
Next = next;
IsMerged = isMerged;
LastX = start.X;
_lastY = start.Y;
Path = new Path(color);
Path = new Path(color, isMerged);
Path.Points.Add(start);
}
public PathHelper(string next, bool isMerged, int color, Point start, Point to)
{
Next = next;
IsMerged = isMerged;
LastX = to.X;
_lastY = to.Y;
Path = new Path(color);
Path = new Path(color, isMerged);
Path.Points.Add(start);
Path.Points.Add(to);
}
@ -310,6 +321,19 @@ namespace SourceGit.Models
_lastY = y;
}
/// <summary>
/// End the current path and create a new from the end.
/// </summary>
public void ReplaceMerged()
{
var color = Path.Color;
Add(LastX, _lastY);
Path = new Path(color, true);
Path.Points.Add(new Point(LastX, _lastY));
_endY = 0;
}
private void Add(double x, double y)
{
if (_endY < y)
@ -327,7 +351,6 @@ namespace SourceGit.Models
private static readonly List<Color> s_defaultPenColors = [
Colors.Orange,
Colors.ForestGreen,
Colors.Gray,
Colors.Turquoise,
Colors.Olive,
Colors.Magenta,

View file

@ -32,6 +32,12 @@ namespace SourceGit.Models
set;
} = false;
public bool OnlyHighlighCurrentBranchInHistories
{
get;
set;
} = false;
public bool IncludeUntrackedInLocalChanges
{
get;