refactor: use another way to open tooltip of SHA after getting commit info (#810)

This commit is contained in:
leo 2024-12-16 13:29:46 +08:00
parent e4cfca0ffd
commit 5425fa64fe
No known key found for this signature in database

View file

@ -5,6 +5,7 @@ using Avalonia.Collections;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Threading;
namespace SourceGit.Views namespace SourceGit.Views
{ {
@ -124,7 +125,7 @@ namespace SourceGit.Views
e.Handled = true; e.Handled = true;
} }
private async void OnSHAPointerEntered(object sender, PointerEventArgs e) private void OnSHAPointerEntered(object sender, PointerEventArgs e)
{ {
if (DataContext is ViewModels.CommitDetail detail && sender is Control { DataContext: string sha } ctl) if (DataContext is ViewModels.CommitDetail detail && sender is Control { DataContext: string sha } ctl)
{ {
@ -132,14 +133,22 @@ namespace SourceGit.Views
if (tooltip is Models.Commit commit && commit.SHA == sha) if (tooltip is Models.Commit commit && commit.SHA == sha)
return; return;
var c = await Task.Run(() => detail.GetParent(sha)); Task.Run(() =>
if (c != null && ctl.IsVisible && ctl.DataContext is string newSHA && newSHA == sha) {
var c = detail.GetParent(sha);
if (c == null) return;
Dispatcher.UIThread.Invoke(() =>
{
if (ctl.IsEffectivelyVisible && ctl.DataContext is string newSHA && newSHA == sha)
{ {
ToolTip.SetTip(ctl, c); ToolTip.SetTip(ctl, c);
if (ctl.IsPointerOver) if (ctl.IsPointerOver)
ToolTip.SetIsOpen(ctl, true); ToolTip.SetIsOpen(ctl, true);
} }
});
});
} }
e.Handled = true; e.Handled = true;