1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-18 22:26:40 +00:00
Ryujinx/Ryujinx.Ava/UI/Applet/ErrorAppletWindow.axaml.cs
Emmanuel Hansen 02714a1291
Avalonia - Add source generator for locale items (#3999)
* Add source generator for locale keys

* use locale keys in Ui subdir
2023-01-03 19:45:08 +01:00

80 lines
No EOL
1.9 KiB
C#

using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Threading;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Windows;
using System.Threading.Tasks;
namespace Ryujinx.Ava.UI.Applet
{
internal partial 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[LocaleKeys.InputDialogOk], 0);
}
}
public ErrorAppletWindow()
{
DataContext = this;
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}
public string Message { 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;
}
}
}