ApplicationListView.axaml.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Avalonia.Controls;
  2. using Avalonia.Input;
  3. using Avalonia.Input.Platform;
  4. using Avalonia.Interactivity;
  5. using Ryujinx.Ava.UI.Helpers;
  6. using Ryujinx.Ava.UI.ViewModels;
  7. using Ryujinx.Ava.Utilities.AppLibrary;
  8. using Ryujinx.Ava.Utilities.Compat;
  9. using System;
  10. using System.Linq;
  11. namespace Ryujinx.Ava.UI.Controls
  12. {
  13. public partial class ApplicationListView : UserControl
  14. {
  15. public static readonly RoutedEvent<ApplicationOpenedEventArgs> ApplicationOpenedEvent =
  16. RoutedEvent.Register<ApplicationListView, ApplicationOpenedEventArgs>(nameof(ApplicationOpened), RoutingStrategies.Bubble);
  17. public event EventHandler<ApplicationOpenedEventArgs> ApplicationOpened
  18. {
  19. add => AddHandler(ApplicationOpenedEvent, value);
  20. remove => RemoveHandler(ApplicationOpenedEvent, value);
  21. }
  22. public ApplicationListView() => InitializeComponent();
  23. public void GameList_DoubleTapped(object sender, TappedEventArgs args)
  24. {
  25. if (sender is ListBox { SelectedItem: ApplicationData selected })
  26. RaiseEvent(new ApplicationOpenedEventArgs(selected, ApplicationOpenedEvent));
  27. }
  28. private async void PlayabilityStatus_OnClick(object sender, RoutedEventArgs e)
  29. {
  30. if (DataContext is not MainWindowViewModel mwvm)
  31. return;
  32. if (sender is not Button { Content: TextBlock playabilityLabel })
  33. return;
  34. await CompatibilityList.Show((string)playabilityLabel.Tag);
  35. }
  36. private async void IdString_OnClick(object sender, RoutedEventArgs e)
  37. {
  38. if (DataContext is not MainWindowViewModel mwvm)
  39. return;
  40. if (sender is not Button { Content: TextBlock idText })
  41. return;
  42. if (!RyujinxApp.IsClipboardAvailable(out IClipboard clipboard))
  43. return;
  44. ApplicationData appData = mwvm.Applications.FirstOrDefault(it => it.IdString == idText.Text);
  45. if (appData is null)
  46. return;
  47. await clipboard.SetTextAsync(appData.IdString);
  48. NotificationHelper.ShowInformation(
  49. "Copied Title ID",
  50. $"{appData.Name} ({appData.IdString})");
  51. }
  52. }
  53. }