Skip to content

Commit 8fab599

Browse files
committed
feat: 添加对悬停提交的支持,更新相关视图模型和UI绑定
1 parent 9ca70ff commit 8fab599

File tree

6 files changed

+40
-0
lines changed

6 files changed

+40
-0
lines changed

src/Models/Commit.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public static double OpacityForNotMerged
5151
public string CommitterTimeShortStr => DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime().ToString(DateTimeFormat.Active.DateOnly);
5252

5353
public bool IsCommitFilterHead { get; set; } = false;
54+
public bool IsHoveredRelated { get; set; } = false;
5455
public bool IsMerged { get; set; } = false;
5556
public bool IsCommitterVisible => !Author.Equals(Committer) || AuthorTime != CommitterTime;
5657
public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null;

src/ViewModels/Histories.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ public long NavigationId
6363
private set => SetProperty(ref _navigationId, value);
6464
}
6565

66+
public long HoveredCommitId
67+
{
68+
get => _hoveredCommitId;
69+
set
70+
{
71+
if (SetProperty(ref _hoveredCommitId, value))
72+
{
73+
}
74+
}
75+
}
76+
6677
public IDisposable DetailContext
6778
{
6879
get => _detailContext;
@@ -233,6 +244,9 @@ public void ProcessHoveredCommit(Models.Commit commit)
233244
Console.WriteLine($"=========");
234245
childrens.Reverse();
235246

247+
_commits.ForEach(c => c.IsHoveredRelated = false);
248+
childrens.ForEach(c => c.IsHoveredRelated = true);
249+
HoveredCommitId = commit.Index;
236250
foreach (var c in childrens)
237251
{
238252
Console.WriteLine($"{c.Index}.{c.Subject}");
@@ -570,6 +584,8 @@ private void NavigateTo(Models.Commit commit)
570584
private Models.Commit _autoSelectedCommit = null;
571585
private Models.Bisect _bisect = null;
572586
private long _navigationId = 0;
587+
private long _hoveredCommitId = 0;
588+
573589
private IDisposable _detailContext = null;
574590

575591
private GridLength _leftArea = new GridLength(1, GridUnitType.Star);

src/Views/CommitGraph.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ public bool OnlyHighlightCurrentBranch
3333
set => SetValue(OnlyHighlightCurrentBranchProperty, value);
3434
}
3535

36+
public static readonly StyledProperty<long> HoveredCommitIdProperty =
37+
AvaloniaProperty.Register<CommitGraph, long>(nameof(HoveredCommitId), 0);
38+
39+
public long HoveredCommitId
40+
{
41+
get => GetValue(HoveredCommitIdProperty);
42+
set => SetValue(HoveredCommitIdProperty, value);
43+
}
44+
3645
public static readonly StyledProperty<Models.CommitGraphLayout> LayoutProperty =
3746
AvaloniaProperty.Register<CommitGraph, Models.CommitGraphLayout>(nameof(Layout));
3847

@@ -48,6 +57,7 @@ static CommitGraph()
4857
GraphProperty,
4958
DotBrushProperty,
5059
OnlyHighlightCurrentBranchProperty,
60+
HoveredCommitIdProperty,
5161
LayoutProperty);
5262
}
5363

@@ -75,6 +85,7 @@ public override void Render(DrawingContext context)
7585
private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double top, double bottom, double rowHeight)
7686
{
7787
var grayedPen = new Pen(new SolidColorBrush(Colors.Gray, 0.4), Models.CommitGraph.Pens[0].Thickness);
88+
var grayedPenHover = new Pen(new SolidColorBrush(Colors.Gray, 0.7), Models.CommitGraph.Pens[0].Thickness);
7889
var onlyHighlightCurrentBranch = OnlyHighlightCurrentBranch;
7990

8091
if (onlyHighlightCurrentBranch)
@@ -169,6 +180,7 @@ private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double
169180
}
170181
}
171182

183+
172184
if (!line.IsMerged && onlyHighlightCurrentBranch)
173185
context.DrawGeometry(null, grayedPen, geo);
174186
else

src/Views/Histories.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@
235235
Graph="{Binding Graph}"
236236
DotBrush="{DynamicResource Brush.Contents}"
237237
OnlyHighlightCurrentBranch="{Binding $parent[v:Histories].OnlyHighlightCurrentBranch}"
238+
HoveredCommitId="{Binding $parent[v:Histories].HoveredCommitId}"
238239
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
239240
IsHitTestVisible="False"
240241
ClipToBounds="True"/>

src/Views/Histories.axaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ public long NavigationId
122122
set => SetValue(NavigationIdProperty, value);
123123
}
124124

125+
public static readonly StyledProperty<long> HoveredCommitIdProperty =
126+
AvaloniaProperty.Register<Histories, long>(nameof(HoveredCommitId));
127+
128+
public long HoveredCommitId
129+
{
130+
get => GetValue(HoveredCommitIdProperty);
131+
set => SetValue(HoveredCommitIdProperty, value);
132+
}
133+
125134
public static readonly StyledProperty<List<Models.Commit>> LastSelectedCommitsProperty =
126135
AvaloniaProperty.Register<Histories, List<Models.Commit>>(nameof(LastSelectedCommits));
127136

src/Views/Repository.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@
839839
IssueTrackers="{Binding $parent[v:Repository].((vm:Repository)DataContext).IssueTrackers}"
840840
OnlyHighlightCurrentBranch="{Binding $parent[v:Repository].((vm:Repository)DataContext).OnlyHighlightCurrentBranchInHistories}"
841841
LastSelectedCommits="{Binding LastSelectedCommits}"
842+
HoveredCommitId="{Binding HoveredCommitId}"
842843
NavigationId="{Binding NavigationId}"/>
843844
</DataTemplate>
844845

0 commit comments

Comments
 (0)