fix(uploader): follow right-to-left languages, name and reach every control by keyboard
Uploader: - Mirror the main window, the confirmation dialog and the tray menu for ar/he/fa/ur; keep paths, addresses, file names, the fingerprint, the brand mark and media glyphs left to right. - Queue rows take keyboard focus, are named "file · state" for screen readers, and Enter retries a failed file; a "✕ n failed" link jumps to the first failure; the list follows the upload near its top. - Focus moves into the settings panel (Tab cycles inside) and back to the gear, to Browse after sign-in and to the refused field after a failed one; activity changes and sign-in errors are announced. - A wrong address or password marks its field (error border, message in the tooltip); Retry only where it can help; session-ended toasts offer Sign in; the form stays visible while its own sign-in runs. - Watch chips and the add button wrap and shorten long paths; target choices wrap with their fields; the settings panel uses the side-panel width with wrapping labels; disabled controls say why. - The window opens at 760x700 (min 630 high) so the per-file list shows five rows; --capture adds an Arabic pass. Setup: - Every stage has a default and a cancel button (safe action first), the keyboard moves to the new default and outcomes are announced; the title-bar Close is disabled while files are written. - "Remove my data" measures the user data folder and shows the plan (largest entries, total) before Uninstall can run; the tooltip names backups and the uploader queue. - Folder field before Browse in Tab order; paths and file names left to right; disabled tooltips say why. Both: byte units come from the language (Common.Size.*). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
32 files changed
+1145
-227
No files matched your search
@@ -1,31 +1,44 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Automation;
|
||||
using System.Windows.Automation.Peers;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
using Titano.Ui.Controls;
|
||||
using Titano.Uploader.Infrastructure;
|
||||
using Titano.Uploader.Uploads;
|
||||
|
||||
namespace Titano.Uploader.Shell;
|
||||
|
||||
/// <summary>The uploader's single window (mockup Uploader.html).</summary>
|
||||
public sealed partial class MainWindow : TitanoWindow
|
||||
{
|
||||
/// <summary>Height of a queue row; the list scrolls by whole rows.</summary>
|
||||
public const double RowHeight = 28;
|
||||
|
||||
private readonly MainViewModel _vm;
|
||||
private readonly UploaderSettings _settings;
|
||||
private bool _connectShown;
|
||||
|
||||
public MainWindow(MainViewModel vm, UploaderSettings settings)
|
||||
{
|
||||
_vm = vm;
|
||||
_settings = settings;
|
||||
_connectShown = vm.IsConnectVisible;
|
||||
DataContext = vm;
|
||||
InitializeComponent();
|
||||
WindowDirection.Follow(this);
|
||||
vm.PendingToasts.CollectionChanged += OnToastRequested;
|
||||
vm.PropertyChanged += OnViewModelChanged;
|
||||
vm.Connect.PropertyChanged += OnConnectChanged;
|
||||
vm.SignInRequested += (_, _) => FocusLater(Password);
|
||||
PreviewKeyDown += OnPreviewKeyDown;
|
||||
Loaded += (_, _) => FocusStart();
|
||||
RestorePlacement();
|
||||
}
|
||||
|
||||
@@ -95,6 +108,23 @@ public sealed partial class MainWindow : TitanoWindow
|
||||
|
||||
private void OnPasswordChanged(object sender, RoutedEventArgs e) => _vm.Connect.Password = Password.Password;
|
||||
|
||||
/// <summary>The "3 failed" link: brings the first failed file into view and gives it the keyboard (Enter retries it).</summary>
|
||||
private void OnShowFailedClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_vm.FirstFailed() is not { } item) return;
|
||||
ScrollNearTop(item);
|
||||
ItemList.UpdateLayout();
|
||||
if (ItemList.ItemContainerGenerator.ContainerFromItem(item) is ListBoxItem row) row.Focus();
|
||||
}
|
||||
|
||||
/// <summary>Enter on a failed row retries it: the keyboard path to the row's Retry button.</summary>
|
||||
private void OnItemListKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key != Key.Enter || e.OriginalSource is not ListBoxItem { DataContext: UploadItem { State: UploadItemState.Failed } item }) return;
|
||||
_vm.RetryItemCommand.Execute(item);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
/// <summary>DESIGN §4 inputs: Enter commits, Esc reverts; Esc also closes the settings panel.</summary>
|
||||
private void OnPreviewKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
@@ -114,8 +144,86 @@ public sealed partial class MainWindow : TitanoWindow
|
||||
|
||||
private void OnViewModelChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(MainViewModel.CurrentItem) && _vm.CurrentItem is { } item) ItemList.ScrollIntoView(item);
|
||||
if (e.PropertyName == nameof(MainViewModel.IsConnectVisible) && _vm.IsConnectVisible) Password.Clear();
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case nameof(MainViewModel.CurrentItem) when _vm.CurrentItem is { } item && !ItemList.IsKeyboardFocusWithin:
|
||||
// Follow the upload unless the user is reading the list with the keyboard.
|
||||
ScrollNearTop(item);
|
||||
break;
|
||||
// Raised with every session change; only a real switch between the form and the queue moves the keyboard.
|
||||
case nameof(MainViewModel.IsConnectVisible) when _vm.IsConnectVisible != _connectShown:
|
||||
_connectShown = _vm.IsConnectVisible;
|
||||
if (_connectShown) Password.Clear();
|
||||
FocusStart();
|
||||
break;
|
||||
case nameof(MainViewModel.IsSettingsOpen):
|
||||
// Focus moves into the panel and comes back to the gear, so it is never left behind the scrim.
|
||||
FocusLater(_vm.IsSettingsOpen ? CloseSettingsButton : SettingsButton);
|
||||
break;
|
||||
case nameof(MainViewModel.Activity):
|
||||
Announce(QueueLine);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A refused address or password takes the keyboard to that field; other failures are announced.</summary>
|
||||
private void OnConnectChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
var connect = _vm.Connect;
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case nameof(ConnectViewModel.AddressError) when connect.AddressError is not null:
|
||||
FocusLater(AddressBox);
|
||||
break;
|
||||
case nameof(ConnectViewModel.PasswordError) when connect.PasswordError is not null:
|
||||
FocusLater(Password);
|
||||
break;
|
||||
case nameof(ConnectViewModel.ErrorText) when connect.ErrorText is not null:
|
||||
Dispatcher.BeginInvoke(DispatcherPriority.Loaded, () => Announce(ErrorMessage));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Where the keyboard starts: the first empty field of the sign-in form, or Browse once signed in.</summary>
|
||||
private void FocusStart()
|
||||
{
|
||||
if (!_vm.IsConnectVisible) FocusLater(BrowseButton);
|
||||
else FocusLater(_vm.Connect.Address.Length == 0 || _vm.Connect.Username.Length == 0 ? AddressBox : Password);
|
||||
}
|
||||
|
||||
/// <summary>Focuses <paramref name="target"/> once a visibility change has been laid out; text is selected so typing replaces it.</summary>
|
||||
private void FocusLater(Control target) => Dispatcher.BeginInvoke(DispatcherPriority.Loaded, () =>
|
||||
{
|
||||
if (!target.IsVisible || !target.Focus()) return;
|
||||
if (target is TextBox box) box.SelectAll();
|
||||
else if (target is PasswordBox password) password.SelectAll();
|
||||
});
|
||||
|
||||
/// <summary>Scrolls so <paramref name="item"/> is the second visible row (the list scrolls by rows), unless it is already in view.</summary>
|
||||
private void ScrollNearTop(UploadItem item)
|
||||
{
|
||||
if (FindScrollViewer(ItemList) is not { } scroll) return;
|
||||
var index = ItemList.Items.IndexOf(item);
|
||||
if (index < 0) return;
|
||||
if (index >= scroll.VerticalOffset && index + 1 <= scroll.VerticalOffset + scroll.ViewportHeight) return;
|
||||
scroll.ScrollToVerticalOffset(Math.Max(0, index - 1));
|
||||
}
|
||||
|
||||
private static ScrollViewer? FindScrollViewer(DependencyObject node)
|
||||
{
|
||||
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(node); i++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(node, i);
|
||||
if (child is ScrollViewer scroll) return scroll;
|
||||
if (FindScrollViewer(child) is { } found) return found;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>Asks screen readers to read <paramref name="element"/> again (it carries <see cref="AutomationProperties.LiveSettingProperty"/>).</summary>
|
||||
private static void Announce(UIElement element)
|
||||
{
|
||||
if (element.IsVisible) UIElementAutomationPeer.CreatePeerForElement(element)?.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);
|
||||
}
|
||||
|
||||
private void OnToastRequested(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
|
||||
Reference in new issue
Block a user