sourcegit/src/Views/CommitBaseInfo.axaml.cs

118 lines
3.8 KiB
C#
Raw Normal View History

using Avalonia;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Input;
2024-08-13 02:15:17 -07:00
using Avalonia.Interactivity;
namespace SourceGit.Views
{
public partial class CommitBaseInfo : UserControl
{
public static readonly StyledProperty<string> MessageProperty =
AvaloniaProperty.Register<CommitBaseInfo, string>(nameof(Message), string.Empty);
public string Message
{
get => GetValue(MessageProperty);
set => SetValue(MessageProperty, value);
}
public static readonly StyledProperty<bool> SupportsContainsInProperty =
AvaloniaProperty.Register<CommitBaseInfo, bool>(nameof(SupportsContainsIn));
public bool SupportsContainsIn
{
get => GetValue(SupportsContainsInProperty);
set => SetValue(SupportsContainsInProperty, value);
}
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);
}
public static readonly StyledProperty<AvaloniaList<Models.IssueTrackerRule>> IssueTrackerRulesProperty =
AvaloniaProperty.Register<CommitBaseInfo, AvaloniaList<Models.IssueTrackerRule>>(nameof(IssueTrackerRules));
public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules
{
get => GetValue(IssueTrackerRulesProperty);
set => SetValue(IssueTrackerRulesProperty, value);
}
public CommitBaseInfo()
{
InitializeComponent();
}
private void OnCopyCommitSHA(object sender, RoutedEventArgs e)
{
if (sender is Button { DataContext: Models.Commit commit })
App.CopyText(commit.SHA);
e.Handled = true;
}
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();
2024-08-18 08:14:44 -07:00
2024-08-13 02:15:17 -07:00
foreach (var link in links)
{
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)
{
var url = $"{links[0].URLPrefix}{detail.Commit.SHA}";
2024-08-13 02:15:17 -07:00
Native.OS.OpenBrowser(url);
}
2024-08-18 08:14:44 -07:00
}
2024-08-13 02:15:17 -07:00
e.Handled = true;
}
private void OnOpenContainsIn(object sender, RoutedEventArgs e)
{
if (DataContext is ViewModels.CommitDetail detail && sender is Button button)
{
var tracking = new CommitRelationTracking(detail);
var flyout = new Flyout();
flyout.Content = tracking;
flyout.ShowAt(button);
}
e.Handled = true;
}
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
e.Handled = true;
}
}
}