feat: context menu for a commit in commit message (#734)

* feat: context menu for a commit in commit message

When a commit message happens to contain a commit link and the user elects to right-click it, instead of navigating them to the commit,  present a menu with options to navigate to it or to copy SHA.

* feat: show commit tooltip as well

`_lastHover` in the `if` is also swapped for `match`for consistency with the block body
This commit is contained in:
Dmitrij D. Czarkoff 2024-11-24 02:53:16 +00:00 committed by GitHub
parent 693940368b
commit 12f75315bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 51 additions and 2 deletions

View file

@ -7,6 +7,7 @@ using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Controls.Documents;
using Avalonia.Input;
using Avalonia.Platform.Storage;
using Avalonia.VisualTree;
namespace SourceGit.Views
@ -149,11 +150,16 @@ namespace SourceGit.Views
SetCurrentValue(CursorProperty, Cursor.Parse("Hand"));
_lastHover = match;
if (!_lastHover.IsCommitSHA)
if (!match.IsCommitSHA)
{
ToolTip.SetTip(this, match.Link);
ToolTip.SetIsOpen(this, true);
}
else if (this.FindAncestorOfType<CommitBaseInfo>() is { DataContext: ViewModels.CommitDetail detail } && detail.GetParent(match.Link) is Models.Commit c)
{
ToolTip.SetTip(this, c);
ToolTip.SetIsOpen(this, true);
}
return;
}
@ -172,7 +178,40 @@ namespace SourceGit.Views
{
var parentView = this.FindAncestorOfType<CommitBaseInfo>();
if (parentView is { DataContext: ViewModels.CommitDetail detail })
detail.NavigateTo(_lastHover.Link);
{
var point = e.GetCurrentPoint(this);
var link = _lastHover.Link;
if (point.Properties.IsLeftButtonPressed)
{
detail.NavigateTo(_lastHover.Link);
}
else if (point.Properties.IsRightButtonPressed)
{
var open = new MenuItem();
open.Header = App.Text("SHALinkCM.NavigateTo");
open.Icon = App.CreateMenuIcon("Icons.Commit");
open.Click += (_, ev) =>
{
detail.NavigateTo(_lastHover.Link);
ev.Handled = true;
};
var copy = new MenuItem();
copy.Header = App.Text("SHALinkCM.CopySHA");
copy.Icon = App.CreateMenuIcon("Icons.Copy");
copy.Click += (_, ev) =>
{
App.CopyText(link);
ev.Handled = true;
};
var menu = new ContextMenu();
menu.Items.Add(open);
menu.Items.Add(copy);
menu.Open(this);
}
}
}
else
{