aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Ava/Ui/Applet/ErrorAppletWindow.axaml.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.Ava/Ui/Applet/ErrorAppletWindow.axaml.cs')
-rw-r--r--Ryujinx.Ava/Ui/Applet/ErrorAppletWindow.axaml.cs89
1 files changed, 89 insertions, 0 deletions
diff --git a/Ryujinx.Ava/Ui/Applet/ErrorAppletWindow.axaml.cs b/Ryujinx.Ava/Ui/Applet/ErrorAppletWindow.axaml.cs
new file mode 100644
index 00000000..d4ec45a8
--- /dev/null
+++ b/Ryujinx.Ava/Ui/Applet/ErrorAppletWindow.axaml.cs
@@ -0,0 +1,89 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Interactivity;
+using Avalonia.Markup.Xaml;
+using Avalonia.Threading;
+using Ryujinx.Ava.Common.Locale;
+using Ryujinx.Ava.Ui.Windows;
+using System.Threading.Tasks;
+
+namespace Ryujinx.Ava.Ui.Applet
+{
+ public class ErrorAppletWindow : StyleableWindow
+ {
+ private readonly Window _owner;
+ private object _buttonResponse;
+
+ public ErrorAppletWindow(Window owner, string[] buttons, string message)
+ {
+ _owner = owner;
+ Message = message;
+ DataContext = this;
+ InitializeComponent();
+#if DEBUG
+ this.AttachDevTools();
+#endif
+ int responseId = 0;
+
+ if (buttons != null)
+ {
+ foreach (string buttonText in buttons)
+ {
+ AddButton(buttonText, responseId);
+ responseId++;
+ }
+ }
+ else
+ {
+ AddButton(LocaleManager.Instance["InputDialogOk"], 0);
+ }
+ }
+
+ public ErrorAppletWindow()
+ {
+ DataContext = this;
+ InitializeComponent();
+#if DEBUG
+ this.AttachDevTools();
+#endif
+ }
+
+ public string Message { get; set; }
+
+ public StackPanel ButtonStack { get; set; }
+
+ private void AddButton(string label, object tag)
+ {
+ Dispatcher.UIThread.InvokeAsync(() =>
+ {
+ Button button = new() { Content = label, Tag = tag };
+
+ button.Click += Button_Click;
+ ButtonStack.Children.Add(button);
+ });
+ }
+
+ private void Button_Click(object sender, RoutedEventArgs e)
+ {
+ if (sender is Button button)
+ {
+ _buttonResponse = button.Tag;
+ }
+
+ Close();
+ }
+
+ public async Task<object> Run()
+ {
+ await ShowDialog(_owner);
+
+ return _buttonResponse;
+ }
+
+ private void InitializeComponent()
+ {
+ AvaloniaXamlLoader.Load(this);
+ ButtonStack = this.FindControl<StackPanel>("ButtonStack");
+ }
+ }
+} \ No newline at end of file