diff --git a/src/Titano.App/Shell/EditBehavior.cs b/src/Titano.App/Shell/EditBehavior.cs index 5c5a8d31..e9e32c38 100644 --- a/src/Titano.App/Shell/EditBehavior.cs +++ b/src/Titano.App/Shell/EditBehavior.cs @@ -9,7 +9,7 @@ namespace Titano.App.Shell; /// /// Attaches an 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). /// 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) { diff --git a/src/Titano.Ui/Mvvm/RelayCommand.cs b/src/Titano.Ui/Mvvm/RelayCommand.cs index ba45ffbb..fa0c396e 100644 --- a/src/Titano.Ui/Mvvm/RelayCommand.cs +++ b/src/Titano.Ui/Mvvm/RelayCommand.cs @@ -21,17 +21,33 @@ public sealed class RelayCommand(Action execute, Func? c public void Execute(object? parameter) => execute(parameter); } -/// Asynchronous command that disables itself while running and reports failures through . +/// +/// Asynchronous command that disables itself while running and reports failures through . Like +/// , its buttons re-query it on . +/// public sealed class AsyncRelayCommand(Func execute, Func? canExecute = null) : ICommand { private CancellationTokenSource? _cts; + private EventHandler? _canExecuteChanged; public AsyncRelayCommand(Func execute, Func? 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; + } + } /// Raised on the UI thread when the command throws (other than cancellation). public static event Action? Failed; @@ -66,5 +82,5 @@ public sealed class AsyncRelayCommand(Func exe public void Cancel() => _cts?.Cancel(); - public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty); + public void RaiseCanExecuteChanged() => _canExecuteChanged?.Invoke(this, EventArgs.Empty); }