fix(ui): async commands re-query on CommandManager requests; Ctrl+Enter passes through edit fields
AsyncRelayCommand raised CanExecuteChanged only around its own execution, so buttons bound to it never re-evaluated after the view model's state changed (CommandManager.InvalidateRequerySuggested reached RelayCommand only). EditBehavior swallowed Ctrl+Enter, so a screen shortcut never fired while a field had focus. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
2 files changed
+21
-5
No files matched your search
@@ -9,7 +9,7 @@ namespace Titano.App.Shell;
|
||||
|
||||
/// <summary>
|
||||
/// Attaches an <see cref="EditableField"/> to a text box (DESIGN §4 inputs): Enter commits, Esc reverts, leaving
|
||||
/// the field commits a valid value.
|
||||
/// the field commits a valid value. Ctrl+Enter commits and still reaches the screen's shortcut (Import · Ctrl+Enter).
|
||||
/// </summary>
|
||||
public static class EditBehavior
|
||||
{
|
||||
@@ -37,7 +37,7 @@ public static class EditBehavior
|
||||
{
|
||||
field.Commit();
|
||||
box.SelectAll();
|
||||
e.Handled = true;
|
||||
e.Handled = Keyboard.Modifiers != ModifierKeys.Control;
|
||||
}
|
||||
else if (e.Key == Key.Escape)
|
||||
{
|
||||
|
||||
@@ -21,17 +21,33 @@ public sealed class RelayCommand(Action<object?> execute, Func<object?, bool>? c
|
||||
public void Execute(object? parameter) => execute(parameter);
|
||||
}
|
||||
|
||||
/// <summary>Asynchronous command that disables itself while running and reports failures through <see cref="Failed"/>.</summary>
|
||||
/// <summary>
|
||||
/// Asynchronous command that disables itself while running and reports failures through <see cref="Failed"/>. Like
|
||||
/// <see cref="RelayCommand"/>, its buttons re-query it on <see cref="CommandManager.InvalidateRequerySuggested"/>.
|
||||
/// </summary>
|
||||
public sealed class AsyncRelayCommand(Func<object?, CancellationToken, Task> execute, Func<object?, bool>? canExecute = null) : ICommand
|
||||
{
|
||||
private CancellationTokenSource? _cts;
|
||||
private EventHandler? _canExecuteChanged;
|
||||
|
||||
public AsyncRelayCommand(Func<Task> execute, Func<bool>? canExecute = null)
|
||||
: this((_, _) => execute(), canExecute is null ? null : _ => canExecute())
|
||||
{
|
||||
}
|
||||
|
||||
public event EventHandler? CanExecuteChanged;
|
||||
public event EventHandler? CanExecuteChanged
|
||||
{
|
||||
add
|
||||
{
|
||||
_canExecuteChanged += value;
|
||||
CommandManager.RequerySuggested += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_canExecuteChanged -= value;
|
||||
CommandManager.RequerySuggested -= value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Raised on the UI thread when the command throws (other than cancellation).</summary>
|
||||
public static event Action<Exception>? Failed;
|
||||
@@ -66,5 +82,5 @@ public sealed class AsyncRelayCommand(Func<object?, CancellationToken, Task> exe
|
||||
|
||||
public void Cancel() => _cts?.Cancel();
|
||||
|
||||
public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
public void RaiseCanExecuteChanged() => _canExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
Reference in new issue
Block a user