DownloadableContentManagerWindow.axaml.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using Avalonia.Controls;
  2. using Avalonia.Interactivity;
  3. using Avalonia.Styling;
  4. using FluentAvalonia.UI.Controls;
  5. using Ryujinx.Ava.Common.Locale;
  6. using Ryujinx.Ava.UI.ViewModels;
  7. using Ryujinx.UI.App.Common;
  8. using Ryujinx.UI.Common.Helper;
  9. using Ryujinx.UI.Common.Models;
  10. using System.Threading.Tasks;
  11. namespace Ryujinx.Ava.UI.Windows
  12. {
  13. public partial class DownloadableContentManagerWindow : UserControl
  14. {
  15. public DownloadableContentManagerViewModel ViewModel;
  16. public DownloadableContentManagerWindow()
  17. {
  18. DataContext = this;
  19. InitializeComponent();
  20. }
  21. public DownloadableContentManagerWindow(ApplicationLibrary applicationLibrary, ApplicationData applicationData)
  22. {
  23. DataContext = ViewModel = new DownloadableContentManagerViewModel(applicationLibrary, applicationData);
  24. InitializeComponent();
  25. }
  26. public static async Task Show(ApplicationLibrary applicationLibrary, ApplicationData applicationData)
  27. {
  28. ContentDialog contentDialog = new()
  29. {
  30. PrimaryButtonText = string.Empty,
  31. SecondaryButtonText = string.Empty,
  32. CloseButtonText = string.Empty,
  33. Content = new DownloadableContentManagerWindow(applicationLibrary, applicationData),
  34. Title = string.Format(LocaleManager.Instance[LocaleKeys.DlcWindowTitle], applicationData.Name, applicationData.IdBaseString),
  35. };
  36. Style bottomBorder = new(x => x.OfType<Grid>().Name("DialogSpace").Child().OfType<Border>());
  37. bottomBorder.Setters.Add(new Setter(IsVisibleProperty, false));
  38. contentDialog.Styles.Add(bottomBorder);
  39. await contentDialog.ShowAsync();
  40. }
  41. private void SaveAndClose(object sender, RoutedEventArgs routedEventArgs)
  42. {
  43. ViewModel.Save();
  44. ((ContentDialog)Parent).Hide();
  45. }
  46. private void Close(object sender, RoutedEventArgs e)
  47. {
  48. ((ContentDialog)Parent).Hide();
  49. }
  50. private void RemoveDLC(object sender, RoutedEventArgs e)
  51. {
  52. if (sender is Button { DataContext: DownloadableContentModel dlc })
  53. {
  54. ViewModel.Remove(dlc);
  55. }
  56. }
  57. private void OpenLocation(object sender, RoutedEventArgs e)
  58. {
  59. if (sender is Button { DataContext: DownloadableContentModel dlc })
  60. {
  61. OpenHelper.LocateFile(dlc.ContainerPath);
  62. }
  63. }
  64. private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
  65. {
  66. foreach (var content in e.AddedItems)
  67. {
  68. if (content is DownloadableContentModel model)
  69. {
  70. ViewModel.Enable(model);
  71. }
  72. }
  73. foreach (var content in e.RemovedItems)
  74. {
  75. if (content is DownloadableContentModel model)
  76. {
  77. ViewModel.Disable(model);
  78. }
  79. }
  80. }
  81. }
  82. }