mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 04:34:59 +00:00
feature: add tooltip for SHA in commit message presenter (#734)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
637f138d63
commit
b2e01f0d3e
4 changed files with 80 additions and 11 deletions
|
@ -1,12 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Collections;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Documents;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Threading;
|
||||
using Avalonia.VisualTree;
|
||||
|
||||
namespace SourceGit.Views
|
||||
|
@ -43,7 +45,9 @@ namespace SourceGit.Views
|
|||
if (change.Property == MessageProperty || change.Property == IssueTrackerRulesProperty)
|
||||
{
|
||||
Inlines!.Clear();
|
||||
_inlineCommits.Clear();
|
||||
_matches = null;
|
||||
_lastHover = null;
|
||||
ClearHoveredIssueLink();
|
||||
|
||||
var message = Message;
|
||||
|
@ -154,6 +158,10 @@ namespace SourceGit.Views
|
|||
ToolTip.SetTip(this, match.Link);
|
||||
ToolTip.SetIsOpen(this, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ProcessHoverCommitLink(match);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -256,6 +264,52 @@ namespace SourceGit.Views
|
|||
ClearHoveredIssueLink();
|
||||
}
|
||||
|
||||
private void ProcessHoverCommitLink(Models.Hyperlink link)
|
||||
{
|
||||
var sha = link.Link;
|
||||
|
||||
// If we have already queried this SHA, just use it.
|
||||
if (_inlineCommits.TryGetValue(sha, out var exist))
|
||||
{
|
||||
if (exist != null)
|
||||
{
|
||||
ToolTip.SetTip(this, exist);
|
||||
ToolTip.SetIsOpen(this, true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var parentView = this.FindAncestorOfType<CommitBaseInfo>();
|
||||
if (parentView is { DataContext: ViewModels.CommitDetail detail })
|
||||
{
|
||||
// Record the SHA of current viewing commit in the CommitDetail panel to determine if it is changed after
|
||||
// asynchronous queries.
|
||||
var lastDetailCommit = detail.Commit.SHA;
|
||||
Task.Run(() =>
|
||||
{
|
||||
var c = detail.GetParent(sha);
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
// Make sure the DataContext of CommitBaseInfo is not changed.
|
||||
var currentParent = this.FindAncestorOfType<CommitBaseInfo>();
|
||||
if (currentParent is { DataContext: ViewModels.CommitDetail currentDetail } &&
|
||||
currentDetail.Commit.SHA == lastDetailCommit)
|
||||
{
|
||||
_inlineCommits.Add(sha, c);
|
||||
|
||||
// Make sure user still hovers the target SHA.
|
||||
if (_lastHover == link)
|
||||
{
|
||||
ToolTip.SetTip(this, c);
|
||||
ToolTip.SetIsOpen(this, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearHoveredIssueLink()
|
||||
{
|
||||
if (_lastHover != null)
|
||||
|
@ -268,5 +322,6 @@ namespace SourceGit.Views
|
|||
|
||||
private List<Models.Hyperlink> _matches = null;
|
||||
private Models.Hyperlink _lastHover = null;
|
||||
private Dictionary<string, Models.Commit> _inlineCommits = new();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue