Skip to content

Commit fafa2a5

Browse files
committed
enhance: show commit full message tooltip when hover commit subject in FileHistories view (#1232)
Signed-off-by: leo <[email protected]>
1 parent 7890f7a commit fafa2a5

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/ViewModels/FileHistories.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,23 @@ public void NavigateToCommit(Models.Commit commit)
305305
_repo.NavigateToCommit(commit.SHA);
306306
}
307307

308+
public string GetCommitFullMessage(Models.Commit commit)
309+
{
310+
var sha = commit.SHA;
311+
if (_fullCommitMessages.TryGetValue(sha, out var msg))
312+
return msg;
313+
314+
msg = new Commands.QueryCommitFullMessage(_repo.FullPath, sha).Result();
315+
_fullCommitMessages[sha] = msg;
316+
return msg;
317+
}
318+
308319
private readonly Repository _repo = null;
309320
private readonly string _file = null;
310321
private bool _isLoading = true;
311322
private bool _prevIsDiffMode = true;
312323
private List<Models.Commit> _commits = null;
324+
private Dictionary<string, string> _fullCommitMessages = new Dictionary<string, string>();
313325
private object _viewContent = null;
314326
}
315327
}

src/Views/FileHistories.axaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@
9393
<TextBlock Grid.Column="3" Classes="primary" Text="{Binding AuthorTimeShortStr}" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Right"/>
9494
</Grid>
9595

96-
<TextBlock Grid.Row="1" Classes="primary" Text="{Binding Subject}" VerticalAlignment="Bottom"/>
96+
<TextBlock Grid.Row="1"
97+
Classes="primary"
98+
Text="{Binding Subject}"
99+
VerticalAlignment="Bottom"
100+
DataContextChanged="OnCommitSubjectDataContextChanged"
101+
PointerMoved="OnCommitSubjectPointerMoved"/>
97102
</Grid>
98103
</Border>
99104
</DataTemplate>

src/Views/FileHistories.axaml.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
using Avalonia.Controls;
24
using Avalonia.Input;
35
using Avalonia.Interactivity;
@@ -57,5 +59,22 @@ private async void OnSaveAsPatch(object sender, RoutedEventArgs e)
5759
e.Handled = true;
5860
}
5961
}
62+
63+
private void OnCommitSubjectDataContextChanged(object sender, EventArgs e)
64+
{
65+
if (sender is TextBlock textBlock)
66+
ToolTip.SetTip(textBlock, null);
67+
}
68+
69+
private void OnCommitSubjectPointerMoved(object sender, PointerEventArgs e)
70+
{
71+
if (sender is TextBlock { DataContext: Models.Commit commit } textBlock &&
72+
DataContext is ViewModels.FileHistories vm)
73+
{
74+
var tooltip = ToolTip.GetTip(textBlock);
75+
if (tooltip == null)
76+
ToolTip.SetTip(textBlock, vm.GetCommitFullMessage(commit));
77+
}
78+
}
6079
}
6180
}

0 commit comments

Comments
 (0)