2024-05-28 21:50:26 -07:00
|
|
|
using Avalonia;
|
2024-08-05 03:18:57 -07:00
|
|
|
using Avalonia.Collections;
|
2024-02-05 23:08:37 -08:00
|
|
|
using Avalonia.Controls;
|
|
|
|
using Avalonia.Input;
|
2024-08-13 02:15:17 -07:00
|
|
|
using Avalonia.Interactivity;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
namespace SourceGit.Views
|
|
|
|
{
|
|
|
|
public partial class CommitBaseInfo : UserControl
|
|
|
|
{
|
2024-06-07 21:19:48 -07:00
|
|
|
public static readonly StyledProperty<string> MessageProperty =
|
|
|
|
AvaloniaProperty.Register<CommitBaseInfo, string>(nameof(Message), string.Empty);
|
|
|
|
|
|
|
|
public string Message
|
|
|
|
{
|
|
|
|
get => GetValue(MessageProperty);
|
|
|
|
set => SetValue(MessageProperty, value);
|
|
|
|
}
|
2024-05-28 21:50:26 -07:00
|
|
|
|
2024-08-13 02:15:17 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-08-05 03:18:57 -07:00
|
|
|
public static readonly StyledProperty<AvaloniaList<Models.IssueTrackerRule>> IssueTrackerRulesProperty =
|
|
|
|
AvaloniaProperty.Register<CommitBaseInfo, AvaloniaList<Models.IssueTrackerRule>>(nameof(IssueTrackerRules));
|
2024-08-05 02:34:49 -07:00
|
|
|
|
2024-08-05 03:18:57 -07:00
|
|
|
public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules
|
2024-08-05 02:34:49 -07:00
|
|
|
{
|
2024-08-05 03:18:57 -07:00
|
|
|
get => GetValue(IssueTrackerRulesProperty);
|
|
|
|
set => SetValue(IssueTrackerRulesProperty, value);
|
2024-08-05 02:34:49 -07:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public CommitBaseInfo()
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
|
2024-08-13 02:15:17 -07:00
|
|
|
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)
|
|
|
|
{
|
2024-08-14 19:39:31 -07:00
|
|
|
var url = $"{link.URLPrefix}{detail.Commit.SHA}";
|
2024-08-13 02:15:17 -07:00
|
|
|
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)
|
|
|
|
{
|
2024-08-14 19:39:31 -07:00
|
|
|
var url = $"{links[0].URLPrefix}{detail.Commit.SHA}";
|
2024-08-13 02:15:17 -07:00
|
|
|
Native.OS.OpenBrowser(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void OnParentSHAPressed(object sender, PointerPressedEventArgs e)
|
|
|
|
{
|
2024-08-13 02:15:17 -07:00
|
|
|
if (DataContext is ViewModels.CommitDetail detail && sender is Control { DataContext: string sha })
|
2024-07-14 00:55:15 -07:00
|
|
|
{
|
|
|
|
detail.NavigateTo(sha);
|
|
|
|
}
|
2024-06-06 00:31:02 -07:00
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
}
|