ErrorAppletWindow.axaml.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using Avalonia.Controls;
  2. using Avalonia.Interactivity;
  3. using Avalonia.Threading;
  4. using Ryujinx.Ava.Common.Locale;
  5. using Ryujinx.Ava.UI.Windows;
  6. using System.Threading.Tasks;
  7. #if DEBUG
  8. using Avalonia;
  9. #endif
  10. namespace Ryujinx.Ava.UI.Applet
  11. {
  12. internal partial class ErrorAppletWindow : StyleableWindow
  13. {
  14. private readonly Window _owner;
  15. private object _buttonResponse;
  16. public ErrorAppletWindow(Window owner, string[] buttons, string message)
  17. {
  18. _owner = owner;
  19. Message = message;
  20. DataContext = this;
  21. InitializeComponent();
  22. #if DEBUG
  23. this.AttachDevTools();
  24. #endif
  25. int responseId = 0;
  26. if (buttons != null)
  27. {
  28. foreach (string buttonText in buttons)
  29. {
  30. AddButton(buttonText, responseId);
  31. responseId++;
  32. }
  33. }
  34. else
  35. {
  36. AddButton(LocaleManager.Instance[LocaleKeys.InputDialogOk], 0);
  37. }
  38. }
  39. public ErrorAppletWindow()
  40. {
  41. DataContext = this;
  42. InitializeComponent();
  43. #if DEBUG
  44. this.AttachDevTools();
  45. #endif
  46. }
  47. public string Message { get; set; }
  48. private void AddButton(string label, object tag)
  49. {
  50. Dispatcher.UIThread.InvokeAsync(() =>
  51. {
  52. Button button = new() { Content = label, Tag = tag };
  53. button.Click += Button_Click;
  54. ButtonStack.Children.Add(button);
  55. });
  56. }
  57. private void Button_Click(object sender, RoutedEventArgs e)
  58. {
  59. if (sender is Button button)
  60. {
  61. _buttonResponse = button.Tag;
  62. }
  63. Close();
  64. }
  65. public async Task<object> Run()
  66. {
  67. await ShowDialog(_owner);
  68. return _buttonResponse;
  69. }
  70. }
  71. }