fix(reorganize): Apply on the first click, one offer per toast, no open dialog replaced
Review of owner review 2, phase 4a (R7): the Reorganize dialogs of the desktop and the web panel. Desktop - Clicking Apply first takes the focus from the template field, which committed it and started a dry run identical to the one on screen: Apply turned off under the click. A commit now plans only when the templates differ from the shown plan (or the last dry run failed). - The Settings toast's Reorganize… disposed whatever dialog the Archive screen had open, so a running Delete stopped without being asked. An open dialog now stays and its archive is not switched; Reorganize says it waits and opens once that dialog closes, with the archive's templates read again and every part the toasts offered meanwhile. - Each Settings toast takes its own archive's offer (one pending offer per archive), and a toast gone early (dismissed, pushed out) lets the next change of that archive raise its own toast: Toast.Closed now says when a toast leaves the screen. Web panel - The Library sends the selected ids up to a thousand. all:true is used only above that, when the selection is exactly what Select all fetched without a filter and the archive has not grown since, so a sequence unticked or added later is never reorganized; otherwise the toast asks to select again. - The preview's "before" of an untitled sequence is its old name, not the new title twice. - A dry run of the same request answering during the confirmation no longer drops the confirmed apply; a plan that really changed is shown and said (Admin.Reorganize.PlanChanged). - Enter in a template plans at once (the form never submitted on Enter). - The confirm tooltip and the module header no longer say the moves are verified: moves and renames are not hashed. Strings in en and it; the reworded key exists in no other culture. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit bed718fb5af2ef69943fd348690c689259872a34)
This commit is contained in:
1 parent
9ae773aa5a
commit
59ee982e4d
14 files changed
+301
-49
No files matched your search
@@ -98,7 +98,7 @@ public sealed class ReorganizeDialogViewModel : ArchiveDialogViewModel
|
||||
ApplyCommand = new AsyncRelayCommand(ApplyAsync, () => ApplyBlocker is null);
|
||||
|
||||
ReorganizeTemplate Template(ReorganizeParts part, string text, string toolTip) =>
|
||||
new(part, text, enabled.HasFlag(part), toolTip, OnTyped, () => _ = PlanAsync(), () => _ = PlanAsync());
|
||||
new(part, text, enabled.HasFlag(part), toolTip, OnTyped, () => _ = PlanAsync(), OnCommitted);
|
||||
}
|
||||
|
||||
public ReorganizeTemplate Folders { get; }
|
||||
@@ -182,6 +182,23 @@ public sealed class ReorganizeDialogViewModel : ArchiveDialogViewModel
|
||||
_delay.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enter, or the focus leaving a field, plans at once, unless the dry run on screen or the one under way is already of
|
||||
/// these templates: a click on Apply takes the focus from the field first, and an identical dry run started then
|
||||
/// would turn Apply off under the click.
|
||||
/// </summary>
|
||||
private void OnCommitted()
|
||||
{
|
||||
if (IsPlanned()) _delay.Stop();
|
||||
else _ = PlanAsync();
|
||||
}
|
||||
|
||||
/// <summary>The templates on screen have their plan, or a dry run of them is under way; false after a failed one.</summary>
|
||||
private bool IsPlanned()
|
||||
{
|
||||
lock (_gate) return _run.For is { } templates && templates == Current() && (_run.Plan is not null || _planning is not null);
|
||||
}
|
||||
|
||||
private async Task DryRunAsync()
|
||||
{
|
||||
var templates = Current();
|
||||
|
||||
@@ -112,33 +112,45 @@ public static class ReorganizePlans
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What Settings › Archive offers to reorganize after its templates changed (owner review 2, R7): the archive and every
|
||||
/// template changed since the offer was last taken. A change while the toast is still up joins the offer on screen
|
||||
/// instead of raising another toast; a change in another archive raises its own.
|
||||
/// What Settings › Archive offers to reorganize after its templates changed (owner review 2, R7): per archive, every
|
||||
/// template changed since its offer was last taken. A change while that archive's toast is still up joins the offer on
|
||||
/// screen instead of raising another toast; a change in another archive raises its own, and each toast takes only its
|
||||
/// archive's offer.
|
||||
/// </summary>
|
||||
/// <param name="toastTime">How long a toast stays up.</param>
|
||||
public sealed class ReorganizeOffer(TimeSpan toastTime)
|
||||
{
|
||||
private (Core.Model.Archive Archive, ReorganizeParts Parts)? _pending;
|
||||
private DateTime _raised;
|
||||
private readonly Dictionary<Guid, Pending> _pending = [];
|
||||
|
||||
/// <summary>Records that <paramref name="part"/> of <paramref name="archive"/> changed at <paramref name="now"/>; true when a toast should offer it.</summary>
|
||||
/// <summary>
|
||||
/// Records that <paramref name="part"/> of <paramref name="archive"/> changed at <paramref name="now"/>; true when a
|
||||
/// toast should offer it (none of that archive is up), raised at <paramref name="now"/>.
|
||||
/// </summary>
|
||||
public bool Add(Core.Model.Archive archive, ReorganizeParts part, DateTime now)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(archive);
|
||||
var same = _pending is { } pending && pending.Archive.Id == archive.Id;
|
||||
_pending = same ? (archive, _pending!.Value.Parts | part) : (archive, part);
|
||||
if (same && now - _raised < toastTime) return false;
|
||||
_raised = now;
|
||||
return true;
|
||||
var known = _pending.TryGetValue(archive.Id, out var pending);
|
||||
var shown = known && pending!.Raised is { } raised && now - raised < toastTime;
|
||||
_pending[archive.Id] = new Pending(archive, (known ? pending!.Parts : ReorganizeParts.None) | part, shown ? pending!.Raised : now);
|
||||
return !shown;
|
||||
}
|
||||
|
||||
/// <summary>The offer when a toast's action runs: the archive as it was last saved and every template changed; null when taken already.</summary>
|
||||
public (Core.Model.Archive Archive, ReorganizeParts Parts)? Take()
|
||||
/// <summary>
|
||||
/// The toast of <paramref name="archiveId"/> raised at <paramref name="raised"/> left the screen (dismissed, timed out,
|
||||
/// pushed out by newer ones): the next change raises a new one. A toast older than the one up now changes nothing.
|
||||
/// </summary>
|
||||
public void Closed(Guid archiveId, DateTime raised)
|
||||
{
|
||||
var pending = _pending;
|
||||
_pending = null;
|
||||
_raised = default;
|
||||
return pending;
|
||||
if (_pending.TryGetValue(archiveId, out var pending) && pending.Raised == raised) _pending[archiveId] = pending with { Raised = null };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The offer of <paramref name="archiveId"/> when its toast's action runs: the archive as it was last saved and every
|
||||
/// template changed; null when taken already. Other archives' offers stay.
|
||||
/// </summary>
|
||||
public (Core.Model.Archive Archive, ReorganizeParts Parts)? Take(Guid archiveId) =>
|
||||
_pending.Remove(archiveId, out var pending) ? (pending.Archive, pending.Parts) : null;
|
||||
|
||||
/// <param name="Raised">When the toast on screen was raised; null once it left.</param>
|
||||
private sealed record Pending(Core.Model.Archive Archive, ReorganizeParts Parts, DateTime? Raised);
|
||||
}
|
||||
@@ -61,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 = [];
|
||||
@@ -516,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();
|
||||
}
|
||||
@@ -772,11 +777,19 @@ public sealed class ArchiveViewModel : SectionViewModel
|
||||
|
||||
/// <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.
|
||||
/// 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);
|
||||
@@ -784,6 +797,14 @@ public sealed class ArchiveViewModel : SectionViewModel
|
||||
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)
|
||||
{
|
||||
@@ -853,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()
|
||||
|
||||
@@ -1074,15 +1074,25 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
Log.Warning("settings", "The sequences of the archive were not counted", ex);
|
||||
return;
|
||||
}
|
||||
if (!_reorganize.Add(archive, part, DateTime.UtcNow)) return;
|
||||
Shell.Notify(Loc.L("Settings.Archive.TemplatesSaved"), Loc.L("Settings.Archive.ExistingKept"), Loc.L("Settings.Archive.Reorganize"),
|
||||
Loc.L("Tooltips.Settings.Reorganize"), () =>
|
||||
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 changed since; what this toast offered when another one was used since.
|
||||
var (target, parts) = _reorganize.Take() ?? (archive, part);
|
||||
// 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>
|
||||
|
||||
Reference in new issue
Block a user