wip(app): delete dialog, keyboard timeline, status filters, remote facets

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 07:49:37 +00:00
1 parent dcc9dcd213
commit 490937e385
10 files changed
+407 -65

No files matched your search

@@ -0,0 +1,174 @@
using System.IO;
using Titano.App.Infrastructure;
using Titano.App.Shell;
using Titano.Core.Archiving;
using Titano.Core.Diagnostics;
using Titano.Core.Localization;
using Titano.Data;
using Titano.Data.Archiving;
using Titano.Ui.Mvvm;
namespace Titano.App.Archiving;
/// <summary>
/// "Delete…" of the Library and the Archive manager (BRIEF §0.2 rule 8, §12.2, §12.5) in an in-window dialog that says
/// how far it is and stops on Cancel: the archive engine's dry run, sequence by sequence; the destructive confirmation
/// that asks to type the number of sequences (DESIGN §4); then the move into the archives' trash, each sequence whole
/// or not at all. The toast that follows names what moved and brings it back.
/// </summary>
public sealed class DeleteDialogViewModel : ArchiveDialogViewModel
{
private readonly ShellViewModel _shell;
private readonly IReadOnlyList<Guid> _ids;
private CancellationTokenSource? _run;
private double _progress;
public DeleteDialogViewModel(ShellViewModel shell, IReadOnlyList<Guid> sequenceIds, Action<ArchiveDialogViewModel> close)
: base(close)
{
_shell = shell;
_ids = sequenceIds;
}
/// <summary>"Deleting 3 sequences".</summary>
public string Heading => Loc.Plural("Archive.Delete.Progress", _ids.Count);
/// <summary>0–1 of the dry run, then of the move.</summary>
public double Progress { get => _progress; private set => Set(ref _progress, value); }
protected override bool CanStop => _run is not null;
/// <summary>Stops the dry run, or the move after the sequence that is moving.</summary>
protected override void Stop() => _run?.Cancel();
public override void Dispose()
{
_run?.Cancel();
base.Dispose();
}
/// <summary>Plans, asks, deletes and offers to undo, then closes; true when something moved to the trash.</summary>
public async Task<bool> RunAsync()
{
using var run = _run = new CancellationTokenSource();
IsBusy = true;
try
{
if (_shell.Services.Archives is not { } archives || _ids.Count == 0) return false;
if (await PlanAsync(archives, run.Token) is not { } plan) return false;
if (DeletePlans.Request(plan) is not { } request)
{
_shell.Notify(Loc.L("Archive.Delete.Nothing"), string.Join(Environment.NewLine, DeletePlans.Blocked(plan, DeletePlans.BlockedLines)));
return false;
}
BusyText = null;
if (!_shell.Services.Dialogs.Confirm(request) || !await SequenceDeletion.CloseEditorAsync(_shell, plan)) return false;
return await DeleteAsync(archives, plan, run.Token);
}
finally
{
_run = null;
IsBusy = false;
Close();
}
}
/// <summary>The dry run; null when it was stopped or failed (said in a toast).</summary>
private async Task<DeletePlan?> PlanAsync(ArchiveService archives, CancellationToken cancellationToken)
{
var checking = new Progress<int>(n => Report("Archive.Delete.Checking", n, _ids.Count));
try
{
return await Task.Run(() => archives.PlanDeleteAsync(_ids, checking, cancellationToken), cancellationToken);
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
return null;
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException or DatabaseException)
{
Log.Warning("archive", "Delete dry run failed", ex);
_shell.Notify(Loc.L("Archive.Delete.Failed"), ex.Message);
return null;
}
}
/// <summary>
/// Moves the planned sequences; whatever moved before a stop or a failure is read back from the trash, so the toast
/// names it and offers to bring it back.
/// </summary>
private async Task<bool> DeleteAsync(ArchiveService archives, DeletePlan plan, CancellationToken cancellationToken)
{
var started = DateTimeOffset.UtcNow;
var moving = new Progress<int>(n => Report("Archive.Delete.Moving", n, plan.Steps.Count));
Report("Archive.Delete.Moving", 0, plan.Steps.Count);
Exception? failure = null;
try
{
await Task.Run(() => archives.DeleteAsync(plan, Environment.UserName, moving, cancellationToken), cancellationToken);
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
Log.Info("archive", "Delete stopped between two sequences");
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or StaleDeletePlanException or NewerFormatException
or ArgumentException or DatabaseException)
{
Log.Warning("archive", "Delete failed", ex);
failure = ex;
}
var moved = await MovedAsync(archives, plan, started);
var removed = await RemovedRowsAsync(plan);
Log.Info("archive", $"{moved.Count} sequence(s) moved to the trash, {removed} without a folder removed from the index");
await SequenceDeletion.RefreshAsync(_shell);
var undo = moved.Count == 0 ? null : new AsyncRelayCommand(() => SequenceDeletion.RestoreAsync(_shell, moved));
if (failure is not null)
_shell.Notify(Loc.L("Archive.Delete.Failed"), failure.Message, undo is null ? null : Loc.L("Archive.Delete.Undo"), Loc.L("Tooltips.Archive.DeleteUndo"),
undo is null ? null : () => undo.Execute(null));
else if (moved.Count > 0)
_shell.Notify(Loc.Plural("Archive.Delete.Done", moved.Count), Loc.L("Archive.Delete.Kept"), Loc.L("Archive.Delete.Undo"),
Loc.L("Tooltips.Archive.DeleteUndo"), () => undo!.Execute(null));
else if (removed > 0)
_shell.Notify(Loc.Plural("Archive.Delete.Removed", removed));
return moved.Count + removed > 0;
}
/// <summary>The trash entries this run made: the planned sequences that entered their archive's trash since it started.</summary>
private static async Task<IReadOnlyList<TrashEntry>> MovedAsync(ArchiveService archives, DeletePlan plan, DateTimeOffset started)
{
var planned = plan.Steps.Where(s => s.TrashFolder is not null).Select(s => s.Sequence.Id).ToHashSet();
var moved = new List<TrashEntry>();
foreach (var archive in plan.Steps.Where(s => s.TrashFolder is not null).Select(s => s.Sequence.ArchiveId).Distinct())
{
try
{
var entries = await Task.Run(() => archives.ListTrashAsync(archive));
moved.AddRange(entries.Where(e => planned.Contains(e.SequenceId) && e.DeletedAt >= started));
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException or DatabaseException)
{
Log.Warning("archive", "The trash could not be read after a delete", ex);
}
}
return moved;
}
/// <summary>Planned sequences without a folder (nothing to keep in a trash) whose rows are gone.</summary>
private async Task<int> RemovedRowsAsync(DeletePlan plan)
{
if (_shell.Services.Database is not { } db) return 0;
var removed = 0;
foreach (var step in plan.Steps.Where(s => s.TrashFolder is null))
{
if (await db.Sequences.GetAsync(step.Sequence.Id) is null) removed++;
}
return removed;
}
private void Report(string key, int done, int total)
{
BusyText = Loc.L(key, Formatting.Count(done), Formatting.Count(total));
Progress = total == 0 ? 0 : (double)done / total;
}
}
+6 -3
View File
@@ -8,8 +8,11 @@ namespace Titano.App.Archiving;
/// <summary>The words of a delete dry run (<see cref="DeletePlan"/>): the destructive confirmation and the lines of what cannot move.</summary>
public static class DeletePlans
{
/// <summary>Sequences named one by one in the confirmation; the rest are counted.</summary>
public const int ListedLines = 8;
/// <summary>Sequences that move, named one by one in the confirmation; the rest are counted.</summary>
public const int ListedLines = 6;
/// <summary>Sequences that cannot move, named one by one; the rest are counted. With <see cref="ListedLines"/> it keeps the confirmation within a 768 px screen.</summary>
public const int BlockedLines = 3;
/// <summary>The destructive confirmation of a plan; null when nothing in it can move.</summary>
public static ConfirmRequest? Request(DeletePlan plan)
@@ -19,7 +22,7 @@ public static class DeletePlans
var lines = plan.Steps.Take(ListedLines).Select(s => Loc.L("Archive.Delete.Line", s.Sequence.DisplayTitle,
Loc.Plural("Shell.Status.Photos", s.Sequence.FrameCount), Formatting.Bytes(s.Bytes))).ToList();
if (plan.Steps.Count > ListedLines) lines.Add(Loc.Plural("Archive.Delete.More", plan.Steps.Count - ListedLines));
lines.AddRange(Blocked(plan, ListedLines));
lines.AddRange(Blocked(plan, BlockedLines));
return new ConfirmRequest
{
Heading = Loc.Plural("Archive.Delete.Heading", plan.Steps.Count),
+1 -2
View File
@@ -94,8 +94,7 @@ public sealed record ArchiveSetFilter(string? Camera = null, StatusFilter Status
{
if (Camera is not null && CameraOf(sequence) != Camera) return false;
if (Tag is not null && !sequence.Tags.Contains(Tag, StringComparer.OrdinalIgnoreCase)) return false;
var (with, without) = LibraryFilter.Flags(Status);
return (sequence.Status & with) == with && (sequence.Status & without) == 0;
return LibraryFilter.MatchesStatus(sequence, Status);
}
/// <summary>"Canon EOS R5 · Not analysed · sunset"; empty without a filter.</summary>
+3 -40
View File
@@ -1,7 +1,5 @@
using System.IO;
using Titano.App.Infrastructure;
using Titano.App.Shell;
using Titano.Core.Archiving;
using Titano.Core.Diagnostics;
using Titano.Core.Localization;
using Titano.Data;
@@ -9,44 +7,9 @@ using Titano.Data.Archiving;
namespace Titano.App.Archiving;
/// <summary>
/// "Delete" of the Library and the Archive manager (BRIEF §0.2 rule 8, §12.2, §12.5): the archive engine's dry run is
/// shown in a destructive confirmation that asks to type the number of sequences (DESIGN §4), then the sequences move to
/// their archive's trash; the toast that follows brings them back.
/// </summary>
/// <summary>What Delete (<see cref="DeleteDialogViewModel"/>) and its Undo share in the Library and the Archive manager.</summary>
public static class SequenceDeletion
{
/// <summary>Plans, asks, deletes and offers to undo; true when something moved to the trash.</summary>
public static async Task<bool> RunAsync(ShellViewModel shell, IReadOnlyList<Guid> sequenceIds)
{
if (shell.Services.Archives is not { } archives || sequenceIds.Count == 0) return false;
try
{
var plan = await Task.Run(() => archives.PlanDeleteAsync(sequenceIds));
if (DeletePlans.Request(plan) is not { } request)
{
shell.Notify(Loc.L("Archive.Delete.Nothing"), string.Join(Environment.NewLine, DeletePlans.Blocked(plan, DeletePlans.ListedLines)));
return false;
}
if (!shell.Services.Dialogs.Confirm(request) || !await CloseEditorAsync(shell, plan)) return false;
var entries = await Task.Run(() => archives.DeleteAsync(plan, Environment.UserName));
Log.Info("archive", $"{entries.Count} sequence(s) moved to the trash, {plan.Steps.Count - entries.Count} removed from the index only");
await RefreshAsync(shell);
shell.Notify(Loc.Plural("Archive.Delete.Done", plan.Steps.Count), Loc.L("Archive.Delete.Kept"),
entries.Count == 0 ? null : Loc.L("Archive.Delete.Undo"), Loc.L("Tooltips.Archive.DeleteUndo"),
entries.Count == 0 ? null : () => _ = RestoreAsync(shell, entries));
return true;
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or StaleDeletePlanException or NewerFormatException
or ArgumentException or DatabaseException)
{
Log.Warning("archive", "Delete failed", ex);
shell.Notify(Loc.L("Archive.Delete.Failed"), ex.Message);
await RefreshAsync(shell);
return false;
}
}
/// <summary>Brings deleted sequences back from their archives' trash and indexes them again.</summary>
public static async Task RestoreAsync(ShellViewModel shell, IReadOnlyList<TrashEntry> entries)
{
@@ -74,7 +37,7 @@ public static class SequenceDeletion
/// The editor of a sequence about to move stores its last edit (so the trash keeps it) and closes; false when that
/// edit could not be stored and the user kept it.
/// </summary>
private static async Task<bool> CloseEditorAsync(ShellViewModel shell, DeletePlan plan)
internal static async Task<bool> CloseEditorAsync(ShellViewModel shell, DeletePlan plan)
{
if (shell.Sequence.Editor is null || shell.CurrentSequenceId is not { } open || plan.Steps.All(s => s.Sequence.Id != open)) return true;
if (!await shell.Sequence.ConfirmCloseAsync()) return false;
@@ -82,7 +45,7 @@ public static class SequenceDeletion
return true;
}
private static async Task RefreshAsync(ShellViewModel shell)
internal static async Task RefreshAsync(ShellViewModel shell)
{
await shell.Library.RefreshAsync();
await shell.Archive.LoadAsync();