ErrorAppletWindow.axaml.cs 1.9 KB

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