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:
Claude committed 2026-10-06 08:21:44 +00:00
1 parent b7cf8e8faf
commit c5c6b801d9
3 files changed
+32 -9

No files matched your search

+5 -2
View File
@@ -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;
+4 -7
View File
@@ -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);
}
}
@@ -1,3 +1,4 @@
using System.IO;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
@@ -9,6 +10,7 @@ using Titano.App.Infrastructure;
using Titano.App.Sections;
using Titano.App.Shell;
using Titano.App.Tests.Windows;
using Titano.Core.Archiving;
using Titano.Core.Localization;
using Titano.Testing;
using Titano.Ui.Controls;
@@ -144,6 +146,27 @@ public sealed class ArchiveScreenSmokeTests
}
});
[Test]
public async Task RebuildCountsSayWhyInsteadOfCountingForever()
{
var offline = new RebuildDialogViewModel(Archive("/nowhere"), ArchiveAvailability.Offline, 3, () => Task.CompletedTask, _ => { });
await offline.CountAsync();
var sidecars = Fact(offline, "Archive.Rebuild.Sidecars");
Assert.Equal("—", sidecars.Value);
Assert.Equal(Loc.L("Archive.Error.Offline", Formatting.LeftToRight("/nowhere")), sidecars.ToolTip);
Assert.True(Fact(offline, "Archive.Rebuild.Root").IsPath, "the archive folder is shown left to right");
var missing = Path.Combine(Path.GetTempPath(), "titano-missing-" + Guid.NewGuid().ToString("N"));
var unreadable = new RebuildDialogViewModel(Archive(missing), ArchiveAvailability.Online, 3, () => Task.CompletedTask, _ => { });
await unreadable.CountAsync();
Assert.Equal("—", Fact(unreadable, "Archive.Rebuild.Metadata").Value);
Assert.Equal(Loc.L("Archive.Failed.Files"), Fact(unreadable, "Archive.Rebuild.Metadata").ToolTip);
Assert.Null(unreadable.BusyText, "nothing is counting any more");
static Core.Model.Archive Archive(string root) => new() { Id = Guid.CreateVersion7(), Name = "TitanoArchive", RootPath = root };
static DialogFact Fact(RebuildDialogViewModel dialog, string label) => dialog.FactRows.Single(f => f.Label == Loc.L(label));
}
[Test]
public void TheArrowTowardsTheIndentOpensAYearInEitherDirection()
{