Ryujinx/Ryujinx.Ava/Ui/Applet/ErrorAppletWindow.axaml.cs
Emmanuel Hansen 6e02cac952
Avalonia - Use content dialog for user profile manager (#3455)
* remove content dialog placeholder from all windows

* remove redundant window argument

* redesign user profile window

* wip

* use avalonia auto name generator

* add edit and new user options

* move profile image selection to content dialog

* remove usings

* fix updater

* address review

* adjust avatar dialog size

* add validation for user editor

* fix typo

* Shorten some labels
2022-07-24 14:38:38 -03:00

81 lines
No EOL
1.9 KiB
C#

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
{
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["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;
}
}
}