TitleUpdateWindow.axaml.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.Common.Models;
  7. using Ryujinx.Ava.UI.ViewModels;
  8. using Ryujinx.Ava.Utilities.AppLibrary;
  9. using Ryujinx.UI.Common.Helper;
  10. using System.Threading.Tasks;
  11. namespace Ryujinx.Ava.UI.Windows
  12. {
  13. public partial class TitleUpdateWindow : UserControl
  14. {
  15. public readonly TitleUpdateViewModel ViewModel;
  16. public TitleUpdateWindow()
  17. {
  18. DataContext = this;
  19. InitializeComponent();
  20. }
  21. public TitleUpdateWindow(ApplicationLibrary applicationLibrary, ApplicationData applicationData)
  22. {
  23. DataContext = ViewModel = new TitleUpdateViewModel(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 TitleUpdateWindow(applicationLibrary, applicationData),
  34. Title = LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.GameUpdateWindowHeading, 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 Close(object sender, RoutedEventArgs e)
  42. {
  43. ((ContentDialog)Parent).Hide();
  44. }
  45. public void Save(object sender, RoutedEventArgs e)
  46. {
  47. ViewModel.Save();
  48. ((ContentDialog)Parent).Hide();
  49. }
  50. private void OpenLocation(object sender, RoutedEventArgs e)
  51. {
  52. if (sender is Button { DataContext: TitleUpdateModel model })
  53. OpenHelper.LocateFile(model.Path);
  54. }
  55. private void RemoveUpdate(object sender, RoutedEventArgs e)
  56. {
  57. if (sender is Button { DataContext: TitleUpdateModel model })
  58. ViewModel.RemoveUpdate(model);
  59. }
  60. private void RemoveAll(object sender, RoutedEventArgs e)
  61. {
  62. ViewModel.TitleUpdates.Clear();
  63. ViewModel.SortUpdates();
  64. }
  65. }
  66. }