feat: owner review 2 phase 4a: Reorganize sequences after import (#12)
CI / Build and test (push) Successful in 9m15s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 15m35s
CI / PostgreSQL 16 integration (push) Successful in 7m26s
CI / PostgreSQL 17 integration (push) Successful in 6m47s
CI / Docker image (push) Successful in 59s
Release / Server image (push) Successful in 1m24s

- Reorganize… on the web panel and the desktop: folder, file and title templates applied to existing sequences, with a dry run and an explicit Apply that runs as a job.
- One naming rule (FrameNaming) for import, upload and Reorganize.
- Crash-safe plan and file journals, held plans, stale-plan refusal; exports move with their folder.
- Writers refuse a folder another program moved or gave to another sequence.
- Server: POST /api/v1/archive/reorganize with a bounded plan cache; template rules.
- Phase 3 docs and translations merged; strings in all 38 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #12.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-10-27 21:58:39 +01:00
1 parent 9aa818ed47
commit 7e4a3b481d
416 files changed
+15304 -1572

No files matched your search

+2 -2
View File
@@ -423,8 +423,8 @@
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Thumbnails}" Command="{Binding ThumbnailsSetCommand}"
ToolTip="{Binding ThumbnailsSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Verify}" Command="{Binding VerifySetCommand}" ToolTip="{Binding VerifySetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Rename}" Command="{Binding RenameSetCommand}" ToolTip="{Binding RenameSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Move}" Command="{Binding MoveSetCommand}" ToolTip="{Binding MoveSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Reorganize}" Command="{Binding ReorganizeSetCommand}"
ToolTip="{Binding ReorganizeSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Retag}" Command="{Binding RetagSetCommand}" ToolTip="{Binding RetagSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Export}" Command="{Binding ExportSetCommand}" ToolTip="{Binding ExportSetToolTip}" />
</WrapPanel>
+80 -17
View File
@@ -15,6 +15,7 @@ using Chronos.Core.Model;
using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Data.Archiving.Jobs;
using Chronos.Data.Jobs;
using Chronos.Data.Processing;
using Chronos.Data.Repositories;
using Chronos.Ui.Mvvm;
@@ -24,8 +25,8 @@ namespace Chronos.App.Sections;
/// <summary>
/// Archive manager (BRIEF §12.5, Archive.html): the archive's tree (years, sequences) with its availability, its
/// figures and charts, mass operations on the selected and filtered set (analyse, proxies, thumbnails, verify, rename,
/// move, retag, CSV, delete into the trash), and the operations on the whole archive as jobs (scan, rebuild with its
/// figures and charts, mass operations on the selected and filtered set (analyse, proxies, thumbnails, verify,
/// reorganize, retag, CSV, delete into the trash), and the operations on the whole archive as jobs (scan, rebuild with its
/// dialog, verify, maintenance), the trash, plus the maintenance view: index health, duplicates and orphans with safe
/// fixes, recent runs. The
/// tree selection is only ever changed by the user: reloads and expanding keep it.
@@ -60,6 +61,10 @@ public sealed class ArchiveViewModel : SectionViewModel
private bool _jobEvents;
private string _lastScanText = string.Empty;
private ArchiveDialogViewModel? _dialog;
/// <summary>A Reorganize the Settings toast asked for while a dialog was open: it opens once that one closes.</summary>
private (Core.Model.Archive Archive, ReorganizeParts Parts)? _waitingReorganize;
private IReadOnlyList<ArchiveTile> _tiles = [];
private IReadOnlyList<ChartRow> _months = [];
private IReadOnlyList<ChartItem> _storage = [];
@@ -104,8 +109,7 @@ public sealed class ArchiveViewModel : SectionViewModel
ProxiesSetCommand = new AsyncRelayCommand(() => QueueSetAsync(ids => ArchiveJobs.Proxies(ids, SetLabel()), Set()), HasSet);
ThumbnailsSetCommand = new AsyncRelayCommand(() => QueueSetAsync(ids => ArchiveJobs.Thumbnails(ids, SetLabel()), Set()), HasSet);
VerifySetCommand = new AsyncRelayCommand(() => QueueSetAsync(ids => ArchiveJobs.Verify(_archive!, ids), Set()), HasSet);
RenameSetCommand = new AsyncRelayCommand(() => OpenRenameDialogAsync(RenameMode.Titles), () => HasSet() && IsOnline());
MoveSetCommand = new AsyncRelayCommand(() => OpenRenameDialogAsync(RenameMode.Folders), () => HasSet() && IsOnline());
ReorganizeSetCommand = new AsyncRelayCommand(() => OpenReorganizeDialogAsync(), () => HasSet() && IsOnline());
RetagSetCommand = new RelayCommand(OpenRetag, () => HasSet() && IsOnline());
ExportSetCommand = new AsyncRelayCommand(ExportAsync, HasSet);
DeleteSetCommand = new AsyncRelayCommand(DeleteSetAsync, () => HasSet() && IsOnline());
@@ -174,8 +178,7 @@ public sealed class ArchiveViewModel : SectionViewModel
public string ThumbnailsSetToolTip => WhenSet("Tooltips.Archive.SetThumbnails");
public string VerifySetToolTip => WhenSet("Tooltips.Archive.SetVerify");
public string ExportSetToolTip => WhenSet("Tooltips.Archive.SetExport");
public string RenameSetToolTip => WhenSet("Tooltips.Archive.SetRename", needsOnline: true);
public string MoveSetToolTip => WhenSet("Tooltips.Archive.SetMove", needsOnline: true);
public string ReorganizeSetToolTip => WhenSet("Tooltips.Archive.SetReorganize", needsOnline: true);
public string RetagSetToolTip => WhenSet("Tooltips.Archive.SetRetag", needsOnline: true);
public string DeleteSetToolTip => WhenSet("Tooltips.Archive.SetDelete", needsOnline: true);
@@ -275,8 +278,10 @@ public sealed class ArchiveViewModel : SectionViewModel
public ICommand ProxiesSetCommand { get; }
public ICommand ThumbnailsSetCommand { get; }
public ICommand VerifySetCommand { get; }
public ICommand RenameSetCommand { get; }
public ICommand MoveSetCommand { get; }
/// <summary>Reorganize…: the set's folders, file names and titles from templates, a dry run first, then a job.</summary>
public ICommand ReorganizeSetCommand { get; }
public ICommand RetagSetCommand { get; }
public ICommand ExportSetCommand { get; }
@@ -359,7 +364,7 @@ public sealed class ArchiveViewModel : SectionViewModel
// ---------------- Dialogs ----------------
/// <summary>The open in-window dialog (rebuild, rename, retag, trash); null when none.</summary>
/// <summary>The open in-window dialog (rebuild, reorganize, retag, delete, trash); null when none.</summary>
public ArchiveDialogViewModel? Dialog
{
get => _dialog;
@@ -515,6 +520,7 @@ public sealed class ArchiveViewModel : SectionViewModel
_reloadDelay.Stop();
_search?.Cancel();
if (_jobEvents && Services.Jobs is { } jobs) jobs.JobChanged -= OnJobChanged;
_waitingReorganize = null;
_dialog?.Dispose();
base.Dispose();
}
@@ -627,8 +633,7 @@ public sealed class ArchiveViewModel : SectionViewModel
OnPropertyChanged(nameof(ThumbnailsSetToolTip));
OnPropertyChanged(nameof(VerifySetToolTip));
OnPropertyChanged(nameof(ExportSetToolTip));
OnPropertyChanged(nameof(RenameSetToolTip));
OnPropertyChanged(nameof(MoveSetToolTip));
OnPropertyChanged(nameof(ReorganizeSetToolTip));
OnPropertyChanged(nameof(RetagSetToolTip));
OnPropertyChanged(nameof(DeleteSetToolTip));
CommandManager.InvalidateRequerySuggested();
@@ -675,7 +680,7 @@ public sealed class ArchiveViewModel : SectionViewModel
{
if (job.State is not (JobState.Done or JobState.Failed)) return;
if (job.Kind is not (JobKind.Scan or JobKind.Rebuild or JobKind.Verify or JobKind.Maintenance or JobKind.Import or JobKind.Proxies or JobKind.Thumbs
or JobKind.LightAnalyse or JobKind.DeepAnalyse)) return;
or JobKind.LightAnalyse or JobKind.DeepAnalyse or JobKind.Move)) return;
System.Windows.Application.Current?.Dispatcher.BeginInvoke(() =>
{
if (_archive is not { } archive || !job.TargetIds.Any(id => id == archive.Id || _sequenceIds.Contains(id))) return;
@@ -758,15 +763,69 @@ public sealed class ArchiveViewModel : SectionViewModel
Shell.Notify(Loc.L("Library.Queued", JobText.Kind(kind), label), actionText: Loc.L("Shell.Nav.Jobs"), actionToolTip: Loc.L("Tooltips.Nav.Jobs"),
action: () => Shell.Navigate(SectionKey.Jobs));
/// <summary>Opens Rename or Move on the set and waits for its dry run.</summary>
public async Task OpenRenameDialogAsync(RenameMode mode)
/// <summary>Opens Reorganize on the set, the archive's layout (folders and file names) switched on, and waits for its dry run.</summary>
public async Task OpenReorganizeDialogAsync()
{
if (Services.Archives is not { } archives || _archive is not { } archive) return;
var dialog = new RenameDialogViewModel(mode, archives, archive, Set(), Applied, CloseDialog);
if (Services.Archives is not { } archives || Services.Engine is not { } engine || _archive is not { } shown) return;
IReadOnlyList<Guid> set = [.. Set().Select(s => s.Id)];
// The templates as they are now: Settings › Archive may have changed them since this screen read the archive.
var archive = await FreshAsync(shown);
var dialog = new ReorganizeDialogViewModel(archives, archive, set, ReorganizePlans.Layout, r => EnqueueAsync(engine, r), CloseDialog);
OpenDialog(dialog);
await dialog.PlanAsync();
}
/// <summary>
/// Opens Reorganize on every sequence of <paramref name="archive"/> (Settings › Archive offers it after its templates
/// changed), with <paramref name="parts"/> switched on; the screen shows that archive. The toast is reached from
/// another screen, so a dialog may be open here, a Delete moving sequences say: it is never replaced nor its archive
/// switched under it; Reorganize waits, says so, and opens once that dialog closes.
/// </summary>
public async Task OpenReorganizeAllAsync(Core.Model.Archive archive, ReorganizeParts parts)
{
ArgumentNullException.ThrowIfNull(archive);
if (_dialog is not null)
{
_waitingReorganize = _waitingReorganize is { } waiting && waiting.Archive.Id == archive.Id ? (archive, waiting.Parts | parts) : (archive, parts);
Shell.Notify(Loc.L("Archive.Reorganize.Waiting"));
return;
}
if (Services.Archives is not { } archives || Services.Engine is not { } engine) return;
if (_archive != archive) SelectedArchive = archive;
var dialog = new ReorganizeDialogViewModel(archives, archive, null, parts, r => EnqueueAsync(engine, r), CloseDialog);
OpenDialog(dialog);
await dialog.PlanAsync();
}
/// <summary>The Reorganize that waited for the dialog that just closed, with the archive's templates as they are now.</summary>
private async Task OpenWaitingReorganizeAsync()
{
if (_waitingReorganize is not { } waiting) return;
_waitingReorganize = null;
await OpenReorganizeAllAsync(await FreshAsync(waiting.Archive), waiting.Parts);
}
/// <summary>The archive's record as the index holds it now; <paramref name="archive"/> when it cannot be read.</summary>
private async Task<Core.Model.Archive> FreshAsync(Core.Model.Archive archive)
{
if (Services.Database is not { } db) return archive;
try
{
return await db.Archives.GetAsync(archive.Id) ?? archive;
}
catch (DatabaseException ex)
{
Log.Warning("archive", "The archive's templates were not read again", ex);
return archive;
}
}
private async Task EnqueueAsync(JobEngine engine, ArchiveJobRequest request)
{
await engine.EnqueueAsync(request);
Queued(request.Kind, request.Label ?? SetLabel());
}
/// <summary>
/// Delete… on the set: the dry run, the typed confirmation and the move into the trash, in the in-window dialog the
/// Library shares, which says how far it is and stops on Cancel. True when something left the archive.
@@ -815,12 +874,16 @@ public sealed class ArchiveViewModel : SectionViewModel
await Shell.Library.RefreshAsync();
}
/// <summary>Closes <paramref name="dialog"/> if it is still the open one (an apply that finishes late closes nothing else).</summary>
/// <summary>
/// Closes <paramref name="dialog"/> if it is still the open one (an apply that finishes late closes nothing else); a
/// Reorganize asked for meanwhile opens then.
/// </summary>
private void CloseDialog(ArchiveDialogViewModel dialog)
{
if (!ReferenceEquals(_dialog, dialog)) return;
dialog.Dispose();
Dialog = null;
_ = OpenWaitingReorganizeAsync();
}
private async Task AdoptAsync()
+1 -1
View File
@@ -422,7 +422,7 @@
<ContextMenu ItemsSource="{Binding RatingChoices}" ItemContainerStyle="{StaticResource MenuItem.Rating}" />
</Button.ContextMenu>
</Button>
<Button Style="{StaticResource Button.Bar}" Content="{l:Loc Library.Action.Move}" Command="{Binding MoveCommand}" ToolTip="{Binding MoveToolTip}" />
<Button Style="{StaticResource Button.Bar}" Content="{l:Loc Library.Action.Reorganize}" Command="{Binding ReorganizeCommand}" ToolTip="{Binding ReorganizeToolTip}" />
<Button Style="{StaticResource Button.Bar}" Content="{l:Loc Library.Action.Upload}" Command="{Binding UploadCommand}" ToolTip="{Binding UploadToolTip}" />
<Button Style="{StaticResource Button.Bar}" Content="{l:Loc Library.Action.Download}" Command="{Binding DownloadCommand}" ToolTip="{Binding DownloadToolTip}" />
<Button Style="{StaticResource Button.Bar}" Content="{l:Loc Library.Action.ExportList}" Command="{Binding ExportListCommand}" ToolTip="{Binding ExportListToolTip}" />
+24 -11
View File
@@ -6,6 +6,7 @@ using System.Windows.Input;
using System.Windows.Threading;
using Chronos.App.Archiving;
using Chronos.App.Infrastructure;
using Chronos.App.Jobs;
using Chronos.App.Library;
using Chronos.App.Server;
using Chronos.App.Shell;
@@ -14,6 +15,7 @@ using Chronos.Core.IO;
using Chronos.Core.Localization;
using Chronos.Core.Model;
using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Data.Repositories;
using Chronos.Data.Sync;
using Chronos.Protocol;
@@ -28,8 +30,9 @@ namespace Chronos.App.Sections;
/// have no copy here (remote cards) — in a virtualised card grid, a table, or a timeline of year bands over the grid;
/// filtered by search, year, camera, status, tag and origin, sorted, loaded page by page (keyset paging) as the view
/// scrolls. Filters and sort can be saved as named views. Cards and rows reveal quick actions (open, analyse, render
/// the sequence's preset, sync); a selection gets the mass actions bar (analyse, proxies, verify, tag, rate, move,
/// upload, download, delete into the trash, CSV), each disabled with its reason when it cannot run on the selection.
/// the sequence's preset, sync); a selection gets the mass actions bar (analyse, proxies, verify, tag, rate,
/// reorganize, upload, download, delete into the trash, CSV), each disabled with its reason when it cannot run on the
/// selection.
/// </summary>
public sealed class LibraryViewModel : SectionViewModel
{
@@ -126,7 +129,7 @@ public sealed class LibraryViewModel : SectionViewModel
VerifyCommand = Mass(MassAction.Verify, t => _actions.VerifyAsync(t));
TagCommand = Mass(MassAction.Tag, OpenRetag);
RateCommand = new AsyncRelayCommand((p, _) => p is int rating ? RateAsync(rating) : Task.CompletedTask, _ => CanRun(MassAction.Rate));
MoveCommand = Mass(MassAction.Move, OpenMoveAsync);
ReorganizeCommand = Mass(MassAction.Reorganize, OpenReorganizeAsync);
UploadCommand = Mass(MassAction.Upload, _ => TransferAsync(MassAction.Upload));
DownloadCommand = Mass(MassAction.Download, _ => TransferAsync(MassAction.Download));
DeleteCommand = Mass(MassAction.Delete, t => DeleteAsync([.. t.Select(s => s.Id)]));
@@ -176,7 +179,9 @@ public sealed class LibraryViewModel : SectionViewModel
/// <summary>Parameter: the rating, 0 (none) to 5.</summary>
public ICommand RateCommand { get; }
public ICommand MoveCommand { get; }
/// <summary>Reorganize…: the selection's folders, file names and titles from templates, a dry run first, then a job.</summary>
public ICommand ReorganizeCommand { get; }
public ICommand UploadCommand { get; }
public ICommand DownloadCommand { get; }
public ICommand DeleteCommand { get; }
@@ -486,7 +491,7 @@ public sealed class LibraryViewModel : SectionViewModel
public string VerifyToolTip => MassToolTip(MassAction.Verify);
public string TagToolTip => MassToolTip(MassAction.Tag);
public string RateToolTip => MassToolTip(MassAction.Rate);
public string MoveToolTip => MassToolTip(MassAction.Move);
public string ReorganizeToolTip => MassToolTip(MassAction.Reorganize);
public string UploadToolTip => MassToolTip(MassAction.Upload);
public string DownloadToolTip => MassToolTip(MassAction.Download);
public string DeleteToolTip => MassToolTip(MassAction.Delete);
@@ -504,7 +509,7 @@ public sealed class LibraryViewModel : SectionViewModel
// ---------------- Dialogs ----------------
/// <summary>The open in-window dialog (tags, move, view name, delete); null when none.</summary>
/// <summary>The open in-window dialog (tags, reorganize, view name, delete); null when none.</summary>
public ArchiveDialogViewModel? Dialog
{
get => _dialog;
@@ -1029,7 +1034,7 @@ public sealed class LibraryViewModel : SectionViewModel
OnPropertyChanged(nameof(VerifyToolTip));
OnPropertyChanged(nameof(TagToolTip));
OnPropertyChanged(nameof(RateToolTip));
OnPropertyChanged(nameof(MoveToolTip));
OnPropertyChanged(nameof(ReorganizeToolTip));
OnPropertyChanged(nameof(UploadToolTip));
OnPropertyChanged(nameof(DownloadToolTip));
OnPropertyChanged(nameof(DeleteToolTip));
@@ -1165,12 +1170,20 @@ public sealed class LibraryViewModel : SectionViewModel
OpenDialog(new RetagDialogViewModel(archives, targets, AppliedAsync, CloseDialog));
}
/// <summary>Move: the archive engine's folder rename with its dry run, for sequences of one archive.</summary>
private async Task OpenMoveAsync(IReadOnlyList<Sequence> targets)
/// <summary>
/// Reorganize…: the archive's folder and file templates (titles on request) applied to the selection of one archive,
/// a dry run first, then the engine's job, which the Library follows to read the sequences again.
/// </summary>
private async Task OpenReorganizeAsync(IReadOnlyList<Sequence> targets)
{
if (Shell.Services.Archives is not { } archives || _db is null || targets.Count == 0) return;
if (Shell.Services.Archives is not { } archives || Shell.Services.Engine is not { } engine || _db is null || targets.Count == 0) return;
if (await _db.Archives.GetAsync(targets[0].ArchiveId) is not { } archive) return;
var dialog = new RenameDialogViewModel(RenameMode.Folders, archives, archive, targets, AppliedAsync, CloseDialog);
var dialog = new ReorganizeDialogViewModel(archives, archive, [.. targets.Select(t => t.Id)], ReorganizePlans.Layout, async request =>
{
await engine.EnqueueAsync(request);
Shell.Notify(Loc.L("Library.Queued", JobText.Kind(request.Kind), request.Label ?? archive.Name), actionText: Loc.L("Shell.Nav.Jobs"),
actionToolTip: Loc.L("Tooltips.Nav.Jobs"), action: () => Shell.Navigate(SectionKey.Jobs));
}, CloseDialog);
OpenDialog(dialog);
await dialog.PlanAsync();
}
+52 -6
View File
@@ -18,6 +18,8 @@ using Chronos.Core.Naming;
using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Data.Jobs;
using Chronos.Data.Repositories;
using Chronos.Ui.Controls;
using Chronos.Ui.Mvvm;
using Chronos.Ui.Theming;
@@ -56,6 +58,9 @@ public sealed class SettingsViewModel : SectionViewModel
/// <summary>Drops a read of the open archive's settings that may have missed an edit being written meanwhile.</summary>
private readonly ArchiveReadGate _archiveReads = new();
/// <summary>The archive whose templates changed and which of them, offered by a toast (as long as a toast stays up).</summary>
private readonly ReorganizeOffer _reorganize = new(new Toast { Title = string.Empty }.Lifetime);
private bool _isDetectingFormats;
private IReadOnlyList<BackupOption> _backups = [];
private BackupOption? _selectedBackup;
@@ -104,13 +109,13 @@ public sealed class SettingsViewModel : SectionViewModel
{
_s.FolderTemplate = v;
Save();
_ = UpdateArchiveAsync(a => a with { Templates = a.Templates with { Folder = v } });
_ = OfferReorganizeAsync(UpdateArchiveAsync(a => a with { Templates = a.Templates with { Folder = v } }), ReorganizeParts.Folders);
}, () => Loc.L("Tooltips.Settings.FolderTemplate"));
FileTemplate = new EditableField(_s.FileTemplate, v => NamingPreview.Validate(v, isFolder: false), v =>
{
_s.FileTemplate = v;
Save();
_ = UpdateArchiveAsync(a => a with { Templates = a.Templates with { File = v } });
_ = OfferReorganizeAsync(UpdateArchiveAsync(a => a with { Templates = a.Templates with { File = v } }), ReorganizeParts.Files);
}, () => Loc.L("Tooltips.Settings.FileTemplate"));
FolderTemplate.PropertyChanged += (_, e) =>
{
@@ -1015,18 +1020,19 @@ public sealed class SettingsViewModel : SectionViewModel
/// that fails (offline, read-only, busy) the user hears why and the rows show the archive's values again. An edit made
/// while the archive at a folder just chosen is opening waits for it, then goes to that archive (or stays this PC's
/// default when there is none), instead of being lost. <paramref name="retarget"/> is the folder change the edit was
/// made after, the latest one by default.
/// made after, the latest one by default. Returns the archive as the edit left it; null when no archive took it.
/// </summary>
private async Task UpdateArchiveAsync(Func<ArchiveSettings, ArchiveSettings> edit, Task<Archive?>? retarget = null)
private async Task<Archive?> UpdateArchiveAsync(Func<ArchiveSettings, ArchiveSettings> edit, Task<Archive?>? retarget = null)
{
retarget ??= _retarget;
var waited = !retarget.IsCompleted;
if (await ArchiveAtFolderAsync(retarget) is not { } archive || Shell.Services.Archives is not { } archives) return;
if (await ArchiveAtFolderAsync(retarget) is not { } archive || Shell.Services.Archives is not { } archives) return null;
bool reload;
Archive? saved = null;
_archiveReads.BeginWrite();
try
{
var updated = await Task.Run(() => archives.UpdateSettingsAsync(archive.Id, edit));
var updated = saved = await Task.Run(() => archives.UpdateSettingsAsync(archive.Id, edit));
// The archive folder may have changed meanwhile: the rows then belong to another archive.
if (_archive?.Id == updated.Id) _archive = updated;
// The open showed the archive's values over the edit: unless another folder was chosen since, the rows (and
@@ -1047,6 +1053,46 @@ public sealed class SettingsViewModel : SectionViewModel
}
// Only once the write ended: a read begun while it is written waits for that end.
if (reload) await LoadArchiveAsync();
return saved;
}
/// <summary>
/// A template names only what is filed from now on: once the archive took a new one (<paramref name="update"/>), a toast
/// offers Reorganize, which applies the templates changed since to every sequence already in the archive, after a dry
/// run (owner review 2, R7). A template changed while the toast is still up joins it instead of raising another.
/// </summary>
private async Task OfferReorganizeAsync(Task<Archive?> update, ReorganizeParts part)
{
if (await update is not { } archive || Shell.Services.Database is not { } db) return;
try
{
// An empty archive has nothing to reorganize.
if (await db.Sequences.CountAsync(new SequenceQuery { ArchiveId = archive.Id }) == 0) return;
}
catch (DatabaseException ex)
{
Log.Warning("settings", "The sequences of the archive were not counted", ex);
return;
}
var raised = DateTime.UtcNow;
if (!_reorganize.Add(archive, part, raised)) return;
var toast = new Toast
{
Title = Loc.L("Settings.Archive.TemplatesSaved"),
Message = Loc.L("Settings.Archive.ExistingKept"),
ActionText = Loc.L("Settings.Archive.Reorganize"),
ActionToolTip = Loc.L("Tooltips.Settings.Reorganize"),
ActionCommand = new RelayCommand(() =>
{
// Every template of this archive changed since; what this toast offered when another toast of it took them.
var (target, parts) = _reorganize.Take(archive.Id) ?? (archive, part);
Shell.Navigate(SectionKey.Archive);
_ = Shell.Archive.OpenReorganizeAllAsync(target, parts);
}),
};
// Gone from the screen early (dismissed, pushed out), the next change of this archive raises a toast of its own.
toast.Closed += (_, _) => _reorganize.Closed(archive.Id, raised);
Shell.ShowToast(toast);
}
/// <summary>