Merge branch 'fix/app-fixes': localized error toasts, plural counts, archive and import view-model fixes

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-12 11:13:16 +00:00
commit 2e2145366f
303 files changed
+968 -2234

No files matched your search

+73 -12
View File
@@ -46,12 +46,17 @@ public sealed class ArchiveViewModel : SectionViewModel
private IReadOnlyList<Core.Model.Archive> _archives = [];
private Core.Model.Archive? _archive;
private ArchiveAvailability _availability = ArchiveAvailability.Offline;
/// <summary>The archive whose availability, figures and tree were read last: until it is the picked one, nothing acts on them.</summary>
private Guid? _readId;
private ArchiveStats? _stats;
private int _withoutProxies;
private ArchiveTree? _tree;
private int _viewIndex;
private bool _loaded;
private Task _load = Task.CompletedTask;
private bool _reloadPending;
private bool _jobEvents;
private string _lastScanText = string.Empty;
private ArchiveDialogViewModel? _dialog;
@@ -78,7 +83,7 @@ public sealed class ArchiveViewModel : SectionViewModel
_ = LoadAsync();
};
ScanCommand = new AsyncRelayCommand(() => QueueAsync(a => ArchiveJobs.Scan(a, deepAnalysis: Services.Settings.DeepAnalysisAfterScan)), IsOnline);
RebuildCommand = new AsyncRelayCommand(() => OpenRebuildDialogAsync(), () => _archive is not null);
RebuildCommand = new AsyncRelayCommand(() => OpenRebuildDialogAsync(), IsRead);
VerifyCommand = new AsyncRelayCommand(() => QueueAsync(a => ArchiveJobs.Verify(a)), IsOnline);
AdoptCommand = new AsyncRelayCommand(AdoptAsync);
CopyFolderCommand = new RelayCommand(CopyFolder, () => _archive is not null);
@@ -126,9 +131,23 @@ public sealed class ArchiveViewModel : SectionViewModel
set
{
if (value is null || value == _archive) return;
var other = value.Id != _archive?.Id;
_archive = value;
_duplicates = null;
_orphans = null;
if (other)
{
// Until the picked archive is read (IsRead), nothing of the previous one stays actionable: no tree to take
// a set from, no availability to allow a scan, no figures for the rebuild dialog or the health fixes, no
// search results. The tooltips say the archive is being read.
_search?.Cancel();
_tree = null;
_stats = null;
_health = [];
RebuildRows();
OnPropertyChanged(string.Empty);
CommandManager.InvalidateRequerySuggested();
}
_ = LoadAsync();
}
}
@@ -379,8 +398,30 @@ public sealed class ArchiveViewModel : SectionViewModel
_ = LoadAsync();
}
/// <summary>Reads archives, figures, tree, health and recent maintenance of the selected archive; joins a read in progress.</summary>
public Task LoadAsync() => _load.IsCompleted ? _load = ReadAsync() : _load;
/// <summary>
/// Reads archives, figures, tree, health and recent maintenance of the selected archive. A call during a read joins
/// it and reads once more when it ends, so a newly picked archive, a language switch or a finished job is never lost
/// behind the read in progress.
/// </summary>
public Task LoadAsync()
{
if (!_load.IsCompleted)
{
_reloadPending = true;
return _load;
}
return _load = ReadUntilCurrentAsync();
}
private async Task ReadUntilCurrentAsync()
{
do
{
_reloadPending = false;
await ReadAsync();
}
while (_reloadPending);
}
private async Task ReadAsync()
{
@@ -393,12 +434,17 @@ public sealed class ArchiveViewModel : SectionViewModel
_archive ??= CurrentArchive.Pick(Archives, Services.Settings.LastArchivePath);
if (_archive is not { } archive) return;
var root = archive.RootPath;
_availability = await Task.Run(() => ArchiveVolume.Probe(new ArchivePaths(root)));
_stats = await db.Sequences.GetStatsAsync(archive.Id);
var availability = await Task.Run(() => ArchiveVolume.Probe(new ArchivePaths(root)));
var stats = await db.Sequences.GetStatsAsync(archive.Id);
var sequences = await ListSequencesAsync(db, archive.Id);
var withoutProxies = await db.Sequences.CountAsync(new SequenceQuery { ArchiveId = archive.Id, WithoutStatus = SequenceStatus.ProxiesBuilt });
ShowFigures(_stats, withoutProxies);
ShowTree(ArchiveTree.Build(archive, _availability, sequences));
// Another archive was picked meanwhile: the read its pick queued shows it, never this one's tree.
if (!IsShowing(archive)) return;
_availability = availability;
_stats = stats;
_readId = archive.Id;
ShowFigures(stats, withoutProxies);
ShowTree(ArchiveTree.Build(archive, availability, sequences));
await LoadRecentAsync(db, archive);
}
catch (DatabaseException ex)
@@ -416,7 +462,7 @@ public sealed class ArchiveViewModel : SectionViewModel
/// <summary>Opens the rebuild dialog (BRIEF §12.5) and counts, off the UI thread, the sidecars the rebuild will read.</summary>
public async Task<RebuildDialogViewModel?> OpenRebuildDialogAsync()
{
if (_archive is not { } archive || Services.Engine is not { } engine) return null;
if (_archive is not { } archive || !IsRead() || Services.Engine is not { } engine) return null;
var dialog = new RebuildDialogViewModel(archive, _availability, _stats?.Sequences ?? 0, async () =>
{
var request = ArchiveJobs.Rebuild(archive);
@@ -583,6 +629,7 @@ public sealed class ArchiveViewModel : SectionViewModel
var jobs = new List<Job>();
foreach (var kind in MaintenanceReports.MaintenanceKinds)
jobs.AddRange((await db.Jobs.ListAsync(null, kind, RecentCount)).Items.Where(j => j.TargetIds.Contains(archive.Id)));
if (!IsShowing(archive)) return;
Recent = MaintenanceReports.Recent(jobs, RecentCount);
var scan = jobs.Where(j => j.Kind == JobKind.Scan && j is { State: JobState.Done, Finished: not null, Started: not null })
.MaxBy(j => j.Finished);
@@ -622,10 +669,19 @@ public sealed class ArchiveViewModel : SectionViewModel
// ---------------- Actions ----------------
private bool IsOnline() => _archive is not null && _availability == ArchiveAvailability.Online;
private bool IsOnline() => IsRead() && _availability == ArchiveAvailability.Online;
/// <summary>The picked archive's availability and figures are known (a slow volume is probed for seconds).</summary>
private bool IsRead() => _archive is { } archive && _readId == archive.Id;
/// <summary>The archive a read started with is still the one picked.</summary>
private bool IsShowing(Core.Model.Archive archive) => _archive?.Id == archive.Id;
/// <summary>A command's tooltip, or why it is disabled: these commands write to the archive or read all of it.</summary>
private string WhenOnline(string key) => _archive is null || IsOnline() ? Loc.L(key) : Loc.L("Archive.Blocked.NotOnline");
private string WhenOnline(string key) =>
_archive is null || IsOnline() ? Loc.L(key)
: !IsRead() ? Loc.L("Archive.Blocked.Reading")
: Loc.L("Archive.Blocked.NotOnline");
private bool HasSet() => _archive is not null && _tree is not null && Set().Count > 0;
@@ -823,7 +879,10 @@ public sealed class ArchiveViewModel : SectionViewModel
try
{
var groups = await Task.Run(() => archives.FindDuplicatesAsync(archive.Id, search.Token), search.Token);
Duplicates = DuplicateRows(groups, await db.Sequences.ListLocationsAsync(archive.Id, search.Token));
var locations = await db.Sequences.ListLocationsAsync(archive.Id, search.Token);
// Picking another archive cancels the search; one that ended just then is not the picked archive's.
if (!IsShowing(archive)) return;
Duplicates = DuplicateRows(groups, locations);
Log.Info("archive", $"Duplicates search in {archive.RootPath}: {groups.Count} group(s)");
}
catch (OperationCanceledException) when (search.IsCancellationRequested)
@@ -851,7 +910,9 @@ public sealed class ArchiveViewModel : SectionViewModel
try
{
var report = await Task.Run(() => archives.FindOrphansAsync(archive.Id, search.Token), search.Token);
Orphans = OrphanRows(report, await db.Sequences.ListLocationsAsync(archive.Id, search.Token));
var locations = await db.Sequences.ListLocationsAsync(archive.Id, search.Token);
if (!IsShowing(archive)) return;
Orphans = OrphanRows(report, locations);
Log.Info("archive", $"Orphans search in {archive.RootPath}: {report.UnindexedFiles} unlisted, {report.MissingFiles} missing, "
+ $"{report.MissingSequences.Count} rows without sidecar, {report.UnindexedFolders.Count} new folders");
}