fix(archive): focus returns safely after a dialog; Retry of a relink asks for the folder again
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
3 files changed
+32
-9
No files matched your search
@@ -3,6 +3,7 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using Titano.App.Archiving;
|
||||
|
||||
@@ -106,16 +107,18 @@ public partial class ArchiveView : UserControl
|
||||
/// </summary>
|
||||
private void OnModelChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName != nameof(ArchiveViewModel.Dialog) || Model is not { } model || !IsVisible) return;
|
||||
if (e.PropertyName != nameof(ArchiveViewModel.Dialog) || Model is not { } model) return;
|
||||
if (model.Dialog is not null)
|
||||
{
|
||||
if (!IsVisible) return;
|
||||
// Raised before the screen behind the dialog is disabled: the control that opened it still has the keyboard.
|
||||
_beforeDialog ??= Keyboard.FocusedElement is DependencyObject focused && IsAncestorOf(focused) ? Keyboard.FocusedElement : null;
|
||||
_beforeDialog ??= Keyboard.FocusedElement is Visual focused && IsAncestorOf(focused) ? Keyboard.FocusedElement : null;
|
||||
Dispatcher.BeginInvoke(DispatcherPriority.Input, () => DialogHost.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)));
|
||||
return;
|
||||
}
|
||||
var back = _beforeDialog;
|
||||
_beforeDialog = null;
|
||||
if (!IsVisible) return;
|
||||
Dispatcher.BeginInvoke(DispatcherPriority.Input, () =>
|
||||
{
|
||||
if (back is UIElement { IsVisible: true, IsEnabled: true, Focusable: true } element && element.Focus()) return;
|
||||
|
||||
@@ -726,14 +726,10 @@ public sealed class ArchiveViewModel : SectionViewModel
|
||||
|
||||
/// <summary>A moved archive keeps its id: opening it at the new root relinks every sequence (BRIEF §12.5 Move archive).</summary>
|
||||
private async Task RelinkAsync()
|
||||
{
|
||||
var folder = Services.Dialogs.PickFolder(Loc.L("Archive.Relink.Title"));
|
||||
if (folder is not null) await RelinkAsync(folder);
|
||||
}
|
||||
|
||||
private async Task RelinkAsync(string folder)
|
||||
{
|
||||
if (Services.Archives is not { } archives) return;
|
||||
var folder = Services.Dialogs.PickFolder(Loc.L("Archive.Relink.Title"));
|
||||
if (folder is null) return;
|
||||
try
|
||||
{
|
||||
var archive = await Task.Run(() => archives.OpenAsync(folder));
|
||||
@@ -747,7 +743,8 @@ public sealed class ArchiveViewModel : SectionViewModel
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or DatabaseException)
|
||||
{
|
||||
Log.Warning("archive", $"Relinking {folder} failed", ex);
|
||||
NotifyFailure("Archive.Relink.Failed", ex, new AsyncRelayCommand(() => RelinkAsync(folder)));
|
||||
// Retry asks for the folder again: the same one once its drive is back, or the right one.
|
||||
NotifyFailure("Archive.Relink.Failed", ex, RelinkCommand);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user