* dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0052 warnings * Silence dotnet format IDE0059 warnings * Address or silence dotnet format IDE1006 warnings * Address dotnet format CA1816 warnings * Address dotnet format CA1822 warnings * Address or silence dotnet format CA1069 warnings * Make dotnet format succeed in style mode * Address dotnet format CA1401 warnings * Address remaining dotnet format analyzer warnings * Address review comments * dotnet-format fixes after rebase * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Format if-blocks correctly * Another rebase, another dotnet format run * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Add comments to disabled warnings * Remove a few unused parameters * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Start working on disabled warnings * Fix and silence a few dotnet-format warnings again * Address IDE0260 warnings * Address a few disabled IDE0060 warnings * Silence IDE0060 in .editorconfig * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * dotnet format pass with new editorconfig * Fix naming style issues * Apply suggestions from code review Co-authored-by: Ac_K <Acoustik666@gmail.com> * Revert one suggestion * Second dotnet format pass and fix build issues * Final pass of dotnet format * Add trailing commas * Fix formatting issues * Keep unnecessary assignment in IconColorPicker.cs * Use using declarations and extend resource lifetimes * Fix rebase issues * Adjust comment spacing * Fix typo * Fix naming issues * Apply suggestions from code review Co-authored-by: Ac_K <Acoustik666@gmail.com> * Revert unintentional change * Remove unused file * Remove static keyword from ViewModels Binding of static members doesn't work and is silently ignored. --------- Co-authored-by: Ac_K <Acoustik666@gmail.com>
184 lines
6.7 KiB
C#
184 lines
6.7 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Input;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Media;
|
|
using FluentAvalonia.UI.Controls;
|
|
using Ryujinx.Ava.Common.Locale;
|
|
using Ryujinx.Ava.UI.Helpers;
|
|
using Ryujinx.HLE.HOS.Applets;
|
|
using Ryujinx.HLE.HOS.Applets.SoftwareKeyboard;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Ryujinx.Ava.UI.Controls
|
|
{
|
|
internal partial class SwkbdAppletDialog : UserControl
|
|
{
|
|
private Predicate<int> _checkLength = _ => true;
|
|
private Predicate<string> _checkInput = _ => true;
|
|
private int _inputMax;
|
|
private int _inputMin;
|
|
private readonly string _placeholder;
|
|
|
|
private ContentDialog _host;
|
|
|
|
public SwkbdAppletDialog(string mainText, string secondaryText, string placeholder, string message)
|
|
{
|
|
MainText = mainText;
|
|
SecondaryText = secondaryText;
|
|
Message = message ?? "";
|
|
DataContext = this;
|
|
_placeholder = placeholder;
|
|
InitializeComponent();
|
|
|
|
Input.Watermark = _placeholder;
|
|
|
|
Input.AddHandler(TextInputEvent, Message_TextInput, RoutingStrategies.Tunnel, true);
|
|
}
|
|
|
|
public SwkbdAppletDialog()
|
|
{
|
|
DataContext = this;
|
|
InitializeComponent();
|
|
}
|
|
|
|
protected override void OnGotFocus(GotFocusEventArgs e)
|
|
{
|
|
// FIXME: This does not work. Might be a bug in Avalonia with DialogHost
|
|
// Currently focus will be redirected to the overlay window instead.
|
|
Input.Focus();
|
|
}
|
|
|
|
public string Message { get; set; } = "";
|
|
public string MainText { get; set; } = "";
|
|
public string SecondaryText { get; set; } = "";
|
|
|
|
public static async Task<(UserResult Result, string Input)> ShowInputDialog(string title, SoftwareKeyboardUiArgs args)
|
|
{
|
|
ContentDialog contentDialog = new();
|
|
|
|
UserResult result = UserResult.Cancel;
|
|
|
|
SwkbdAppletDialog content = new(args.HeaderText, args.SubtitleText, args.GuideText, args.InitialText);
|
|
|
|
string input = string.Empty;
|
|
|
|
content.SetInputLengthValidation(args.StringLengthMin, args.StringLengthMax);
|
|
content.SetInputValidation(args.KeyboardMode);
|
|
|
|
content._host = contentDialog;
|
|
contentDialog.Title = title;
|
|
contentDialog.PrimaryButtonText = args.SubmitText;
|
|
contentDialog.IsPrimaryButtonEnabled = content._checkLength(content.Message.Length);
|
|
contentDialog.SecondaryButtonText = "";
|
|
contentDialog.CloseButtonText = LocaleManager.Instance[LocaleKeys.InputDialogCancel];
|
|
contentDialog.Content = content;
|
|
|
|
void Handler(ContentDialog sender, ContentDialogClosedEventArgs eventArgs)
|
|
{
|
|
if (eventArgs.Result == ContentDialogResult.Primary)
|
|
{
|
|
result = UserResult.Ok;
|
|
input = content.Input.Text;
|
|
}
|
|
}
|
|
|
|
contentDialog.Closed += Handler;
|
|
|
|
await ContentDialogHelper.ShowAsync(contentDialog);
|
|
|
|
return (result, input);
|
|
}
|
|
|
|
private void ApplyValidationInfo(string text)
|
|
{
|
|
Error.IsVisible = !string.IsNullOrEmpty(text);
|
|
Error.Text = text;
|
|
}
|
|
|
|
public void SetInputLengthValidation(int min, int max)
|
|
{
|
|
_inputMin = Math.Min(min, max);
|
|
_inputMax = Math.Max(min, max);
|
|
|
|
Error.IsVisible = false;
|
|
Error.FontStyle = FontStyle.Italic;
|
|
|
|
string validationInfoText = "";
|
|
|
|
if (_inputMin <= 0 && _inputMax == int.MaxValue) // Disable.
|
|
{
|
|
Error.IsVisible = false;
|
|
|
|
_checkLength = length => true;
|
|
}
|
|
else if (_inputMin > 0 && _inputMax == int.MaxValue)
|
|
{
|
|
validationInfoText = LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.SwkbdMinCharacters, _inputMin);
|
|
|
|
_checkLength = length => _inputMin <= length;
|
|
}
|
|
else
|
|
{
|
|
validationInfoText = LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.SwkbdMinRangeCharacters, _inputMin, _inputMax);
|
|
|
|
_checkLength = length => _inputMin <= length && length <= _inputMax;
|
|
}
|
|
|
|
ApplyValidationInfo(validationInfoText);
|
|
Message_TextInput(this, new TextInputEventArgs());
|
|
}
|
|
|
|
private void SetInputValidation(KeyboardMode mode)
|
|
{
|
|
string validationInfoText = Error.Text;
|
|
string localeText;
|
|
switch (mode)
|
|
{
|
|
case KeyboardMode.NumbersOnly:
|
|
localeText = LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.SoftwareKeyboardModeNumbersOnly);
|
|
validationInfoText = string.IsNullOrEmpty(validationInfoText) ? localeText : string.Join("\n", validationInfoText, localeText);
|
|
_checkInput = text => text.All(char.IsDigit);
|
|
break;
|
|
case KeyboardMode.Alphabet:
|
|
localeText = LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.SoftwareKeyboardModeAlphabet);
|
|
validationInfoText = string.IsNullOrEmpty(validationInfoText) ? localeText : string.Join("\n", validationInfoText, localeText);
|
|
_checkInput = text => text.All(value => !CJKCharacterValidation.IsCJK(value));
|
|
break;
|
|
case KeyboardMode.ASCII:
|
|
localeText = LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.SoftwareKeyboardModeASCII);
|
|
validationInfoText = string.IsNullOrEmpty(validationInfoText) ? localeText : string.Join("\n", validationInfoText, localeText);
|
|
_checkInput = text => text.All(char.IsAscii);
|
|
break;
|
|
default:
|
|
_checkInput = _ => true;
|
|
break;
|
|
}
|
|
|
|
ApplyValidationInfo(validationInfoText);
|
|
Message_TextInput(this, new TextInputEventArgs());
|
|
}
|
|
|
|
private void Message_TextInput(object sender, TextInputEventArgs e)
|
|
{
|
|
if (_host != null)
|
|
{
|
|
_host.IsPrimaryButtonEnabled = _checkLength(Message.Length) && _checkInput(Message);
|
|
}
|
|
}
|
|
|
|
private void Message_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.Key == Key.Enter && _host.IsPrimaryButtonEnabled)
|
|
{
|
|
_host.Hide(ContentDialogResult.Primary);
|
|
}
|
|
else
|
|
{
|
|
_host.IsPrimaryButtonEnabled = _checkLength(Message.Length) && _checkInput(Message);
|
|
}
|
|
}
|
|
}
|
|
}
|