mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 12:15:00 +00:00
feature: add commit web links (#357)
This commit is contained in:
parent
a145d6e4c3
commit
34a598d421
13 changed files with 124 additions and 52 deletions
|
@ -2,20 +2,12 @@ using Avalonia;
|
|||
using Avalonia.Collections;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public partial class CommitBaseInfo : UserControl
|
||||
{
|
||||
public static readonly StyledProperty<bool> CanNavigateProperty =
|
||||
AvaloniaProperty.Register<CommitBaseInfo, bool>(nameof(CanNavigate), true);
|
||||
|
||||
public bool CanNavigate
|
||||
{
|
||||
get => GetValue(CanNavigateProperty);
|
||||
set => SetValue(CanNavigateProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<string> MessageProperty =
|
||||
AvaloniaProperty.Register<CommitBaseInfo, string>(nameof(Message), string.Empty);
|
||||
|
||||
|
@ -25,6 +17,15 @@ namespace SourceGit.Views
|
|||
set => SetValue(MessageProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<AvaloniaList<Models.CommitLink>> WebLinksProperty =
|
||||
AvaloniaProperty.Register<CommitBaseInfo, AvaloniaList<Models.CommitLink>>(nameof(WebLinks));
|
||||
|
||||
public AvaloniaList<Models.CommitLink> WebLinks
|
||||
{
|
||||
get => GetValue(WebLinksProperty);
|
||||
set => SetValue(WebLinksProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<AvaloniaList<Models.IssueTrackerRule>> IssueTrackerRulesProperty =
|
||||
AvaloniaProperty.Register<CommitBaseInfo, AvaloniaList<Models.IssueTrackerRule>>(nameof(IssueTrackerRules));
|
||||
|
||||
|
@ -39,11 +40,43 @@ namespace SourceGit.Views
|
|||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void OnOpenWebLink(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.CommitDetail detail)
|
||||
{
|
||||
var links = WebLinks;
|
||||
if (links.Count > 1)
|
||||
{
|
||||
var menu = new ContextMenu();
|
||||
|
||||
foreach (var link in links)
|
||||
{
|
||||
var url = link.URLTemplate.Replace("SOURCEGIT_COMMIT_HASH_CODE", detail.Commit.SHA);
|
||||
var item = new MenuItem() { Header = link.Name };
|
||||
item.Click += (_, ev) =>
|
||||
{
|
||||
Native.OS.OpenBrowser(url);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
menu.Items.Add(item);
|
||||
}
|
||||
|
||||
(sender as Control)?.OpenContextMenu(menu);
|
||||
}
|
||||
else if (links.Count == 1)
|
||||
{
|
||||
var url = links[0].URLTemplate.Replace("SOURCEGIT_COMMIT_HASH_CODE", detail.Commit.SHA);
|
||||
Native.OS.OpenBrowser(url);
|
||||
}
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnParentSHAPressed(object sender, PointerPressedEventArgs e)
|
||||
{
|
||||
if (sender is Control { DataContext: string sha } &&
|
||||
DataContext is ViewModels.CommitDetail detail &&
|
||||
CanNavigate)
|
||||
if (DataContext is ViewModels.CommitDetail detail && sender is Control { DataContext: string sha })
|
||||
{
|
||||
detail.NavigateTo(sha);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue