Files
Chronos/src/Titano.App/Shell/LoginDialog.xaml.cs
T
Claude a92120fb0d fix(app): shell follows RTL from startup; welcome keeps the keyboard; accessible dialogs and errors
- The rail grows with the longest label (128-200 px); the first-run dialog disables the shell behind it
  and focuses its chosen option; toasts stay above it; F6 reaches the newest toast.
- Confirm and login dialogs are named by their heading, focus the safe button, announce sign-in errors.
- Error toasts say what happened only for catalog sentences (ErrorText); other details stay in the log.
- Window title, queued-jobs text (plural) and the pause button name come from resources.
- Logs, paths and templates in the client styles stay left to right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-03 17:22:42 +00:00

68 lines
2.5 KiB
C#

using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
using Titano.Ui.Controls;
namespace Titano.App.Shell;
/// <summary>
/// The login form (BRIEF §12.7). It calls back the connection with the credentials and stays open with the
/// error sentence until the sign-in succeeds or the user cancels. The password never leaves the PasswordBox
/// except for that call. A failed sign-in is announced to screen readers and stays as the password box's help text.
/// </summary>
public sealed partial class LoginDialog : TitanoWindow
{
private readonly Func<string, string, Task<string?>> _signIn;
private LoginDialog(string server, string? username, Func<string, string, Task<string?>> signIn)
{
_signIn = signIn;
InitializeComponent();
ServerText.Text = server;
User.Text = username ?? string.Empty;
Loaded += (_, _) =>
{
if (User.Text.Length == 0) User.Focus();
else Password.Focus();
};
}
/// <summary>True when the user signed in.</summary>
public static bool Ask(Window? owner, string server, string? username, Func<string, string, Task<string?>> signIn)
{
var dialog = new LoginDialog(server, username, signIn);
if (owner is { IsVisible: true }) dialog.Owner = owner;
else dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
return dialog.ShowDialog() == true;
}
private void OnCancel(object sender, RoutedEventArgs e) => DialogResult = false;
private async void OnSignIn(object sender, RoutedEventArgs e)
{
SignIn.IsEnabled = false;
Error.Visibility = Visibility.Collapsed;
AutomationProperties.SetHelpText(Password, string.Empty);
try
{
var error = await _signIn(User.Text, Password.Password);
if (error is null)
{
DialogResult = true;
return;
}
Error.Text = error;
Error.Visibility = Visibility.Visible;
AutomationProperties.SetHelpText(Password, error);
Password.Clear();
Password.Focus();
UIElementAutomationPeer.CreatePeerForElement(this)?.RaiseNotificationEvent(
AutomationNotificationKind.ActionCompleted, AutomationNotificationProcessing.ImportantMostRecent, error, "Titano.SignIn");
}
finally
{
SignIn.IsEnabled = true;
}
}
}