aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Ava/Ui/Controls/InputDialog.axaml.cs
blob: b9bbb66da1e4e95c77b9a989a834dc27e27426a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using FluentAvalonia.UI.Controls;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.Ui.Models;
using Ryujinx.Ava.Ui.Windows;
using System.Threading.Tasks;

namespace Ryujinx.Ava.Ui.Controls
{
    public class InputDialog : UserControl
    {
        public string Message { get; set; }
        public string Input { get; set; }
        public string SubMessage { get; set; }

        public uint MaxLength { get; }

        public InputDialog(string message, string input = "", string subMessage = "", uint maxLength = int.MaxValue)
        {
            Message = message;
            Input = input;
            SubMessage = subMessage;
            MaxLength = maxLength;

            DataContext = this;

            InitializeComponent();
        }

        public InputDialog()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);
        }

        public static async Task<(UserResult Result, string Input)> ShowInputDialog(StyleableWindow window, string title, string message, string input = "", string subMessage = "", uint maxLength = int.MaxValue)
        {
            ContentDialog contentDialog = window.ContentDialog;

            UserResult result = UserResult.Cancel;

            InputDialog content = new InputDialog(message, input = "", subMessage = "", maxLength);

            if (contentDialog != null)
            {
                contentDialog.Title = title;
                contentDialog.PrimaryButtonText = LocaleManager.Instance["InputDialogOk"];
                contentDialog.SecondaryButtonText = "";
                contentDialog.CloseButtonText = LocaleManager.Instance["InputDialogCancel"];
                contentDialog.Content = content;
                contentDialog.PrimaryButtonCommand = MiniCommand.Create(() =>
                {
                    result = UserResult.Ok;
                    input = content.Input;
                });
                await contentDialog.ShowAsync();
            }

            return (result, input);
        }
    }
}