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:
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;
|
||||
}
|
||||
}
|
||||
@@ -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),
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -39,6 +39,9 @@ public sealed class LibraryActions(ShellViewModel shell)
|
||||
/// <summary>What the signed-in account may do; nothing while signed out.</summary>
|
||||
public SyncRights Rights => Services.Server.User is { } user ? SyncRights.Of(user.Permissions) : default;
|
||||
|
||||
/// <summary>A job can be posted to the server now (a remote card's Analyse and Render).</summary>
|
||||
public bool CanPost => Services.Server is { IsConnected: true, Flow: { Address: not null, Token: not null } };
|
||||
|
||||
/// <summary>Deep analysis of sequences on this PC (one job), or of a remote card on the server.</summary>
|
||||
public async Task AnalyseAsync(IReadOnlyList<Sequence> sequences)
|
||||
{
|
||||
@@ -63,8 +66,9 @@ public sealed class LibraryActions(ShellViewModel shell)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Render quick action: the sequence's own export (its recommended preset, else the default) with its project as
|
||||
/// stored, on this PC's engine — or posted to the server for a remote card, which renders it where the originals are.
|
||||
/// The Render quick action: the sequence's own export with its project as stored — the preset chosen in the editor,
|
||||
/// else the advisor's recommendation the analyses store in the project, else the default — on this PC's engine, or
|
||||
/// posted to the server for a remote card, which renders it where the originals are.
|
||||
/// </summary>
|
||||
public async Task RenderAsync(Sequence sequence)
|
||||
{
|
||||
@@ -134,16 +138,20 @@ public sealed class LibraryActions(ShellViewModel shell)
|
||||
return job.Id;
|
||||
}
|
||||
|
||||
/// <summary>Sets the rating of sequences on this PC (sidecar and index together); returns how many changed.</summary>
|
||||
/// <summary>
|
||||
/// Sets the rating of sequences on this PC (sidecar and index together), changing nothing else: the title, tags and
|
||||
/// notes are those the sidecar holds then, not the Library's copy. Returns how many changed.
|
||||
/// </summary>
|
||||
public async Task<int> RateAsync(IReadOnlyList<Sequence> sequences, int rating)
|
||||
{
|
||||
if (Services.Archives is not { } archives) return 0;
|
||||
if (Services.Archives is not { } archives || Services.Database is not { } db) return 0;
|
||||
var changed = 0;
|
||||
try
|
||||
{
|
||||
foreach (var s in sequences.Where(s => s.Rating != rating))
|
||||
foreach (var s in sequences)
|
||||
{
|
||||
await Task.Run(() => archives.SetSequenceInfoAsync(s.Id, s.Title, s.Tags, rating, s.Notes));
|
||||
if (await db.Sequences.GetAsync(s.Id) is not { } current || current.Rating == rating) continue;
|
||||
await Task.Run(() => archives.EditSequenceInfoAsync(s.Id, info => info with { Rating = rating }));
|
||||
changed++;
|
||||
}
|
||||
}
|
||||
@@ -174,7 +182,7 @@ public sealed class LibraryActions(ShellViewModel shell)
|
||||
private async Task PostAsync(Func<Task<CreateJobRequest>> build, JobKind kind, string label)
|
||||
{
|
||||
var session = Services.Server;
|
||||
if (!session.IsConnected || session.Flow is not { Address: { } address, Token: { } token }) return;
|
||||
if (!CanPost || session.Flow is not { Address: { } address, Token: { } token }) return;
|
||||
try
|
||||
{
|
||||
var request = await build();
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using Titano.Core.Model;
|
||||
using Titano.Data.Repositories;
|
||||
|
||||
namespace Titano.App.Library;
|
||||
|
||||
/// <summary>
|
||||
/// What the Library's Year and Camera choices and its timeline bands count (BRIEF §4.4 mixed mode): the index's
|
||||
/// figures, the server's sequences without a copy here, or both, as the origin filter says.
|
||||
/// </summary>
|
||||
public static class LibraryFacets
|
||||
{
|
||||
/// <summary>
|
||||
/// <paramref name="local"/> with its years, months and cameras replaced by those of the origins in view: the index's
|
||||
/// own unless only the server's sequences show, plus the remote cards' unless only this PC's show.
|
||||
/// </summary>
|
||||
public static ArchiveStats Of(ArchiveStats local, IReadOnlyList<Sequence> remote, OriginFilter origin)
|
||||
{
|
||||
var keepLocal = origin != OriginFilter.Server;
|
||||
var years = keepLocal ? local.ByYear.ToDictionary(y => y.Year) : [];
|
||||
var months = keepLocal ? local.ByMonth.ToDictionary(m => (m.Year, m.Month)) : [];
|
||||
var cameras = keepLocal ? local.ByCamera.ToDictionary(c => (c.Make, c.Model)) : [];
|
||||
foreach (var s in origin == OriginFilter.Local ? [] : remote)
|
||||
{
|
||||
if (s.FirstCapture is { } at)
|
||||
{
|
||||
years[at.Year] = years.TryGetValue(at.Year, out var y)
|
||||
? y with { Sequences = y.Sequences + 1, Photos = y.Photos + s.FrameCount, Bytes = y.Bytes + s.TotalBytes }
|
||||
: new YearBucket(at.Year, 1, s.FrameCount, s.TotalBytes);
|
||||
months[(at.Year, at.Month)] = months.TryGetValue((at.Year, at.Month), out var m)
|
||||
? m with { Sequences = m.Sequences + 1, Photos = m.Photos + s.FrameCount }
|
||||
: new MonthBucket(at.Year, at.Month, 1, s.FrameCount);
|
||||
}
|
||||
cameras[(s.CameraMake, s.CameraModel)] = cameras.TryGetValue((s.CameraMake, s.CameraModel), out var c)
|
||||
? c with { Sequences = c.Sequences + 1, Photos = c.Photos + s.FrameCount, Bytes = c.Bytes + s.TotalBytes }
|
||||
: new CameraBucket(s.CameraMake, s.CameraModel, 1, s.FrameCount, s.TotalBytes);
|
||||
}
|
||||
return local with
|
||||
{
|
||||
ByYear = [.. years.Values.OrderBy(y => y.Year)],
|
||||
ByMonth = [.. months.Values.OrderBy(m => m.Year).ThenBy(m => m.Month)],
|
||||
ByCamera = [.. cameras.Values],
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using Titano.Data.Repositories;
|
||||
|
||||
namespace Titano.App.Library;
|
||||
|
||||
/// <summary>Status choices of the Library toolbar; each maps onto status flags the index can filter on.</summary>
|
||||
/// <summary>Status choices of the Library toolbar (Main.html: analysed, proxies, rendered, synced); each is a test the index can run.</summary>
|
||||
public enum StatusFilter
|
||||
{
|
||||
Any,
|
||||
@@ -11,8 +11,11 @@ public enum StatusFilter
|
||||
NotAnalysed,
|
||||
Proxies,
|
||||
NoProxies,
|
||||
Rendered,
|
||||
NotRendered,
|
||||
Verified,
|
||||
NotVerified,
|
||||
Synced,
|
||||
Warnings,
|
||||
}
|
||||
|
||||
@@ -42,6 +45,9 @@ public sealed record LibraryFilter
|
||||
/// <summary>The same sort without filters ("Clear filters").</summary>
|
||||
public LibraryFilter Cleared() => new() { Sort = Sort };
|
||||
|
||||
/// <summary>Sync states a "Synced" sequence is in: the ones whose card wears the ● Synced glyph.</summary>
|
||||
public static IReadOnlyCollection<SyncState> SyncedStates { get; } = [SyncState.InSync, SyncState.LocalAhead];
|
||||
|
||||
/// <summary>The repository query for one page.</summary>
|
||||
public SequenceQuery ToQuery(int limit, string? cursor)
|
||||
{
|
||||
@@ -54,6 +60,13 @@ public sealed record LibraryFilter
|
||||
Tag = Tag,
|
||||
WithStatus = with,
|
||||
WithoutStatus = without,
|
||||
Rendered = Status switch
|
||||
{
|
||||
StatusFilter.Rendered => true,
|
||||
StatusFilter.NotRendered => false,
|
||||
_ => null,
|
||||
},
|
||||
SyncStates = Status == StatusFilter.Synced ? SyncedStates : null,
|
||||
Sort = Sort,
|
||||
Limit = limit,
|
||||
Cursor = cursor,
|
||||
@@ -68,8 +81,7 @@ public sealed record LibraryFilter
|
||||
{
|
||||
if (Year is { } year && sequence.FirstCapture?.Year != year) return false;
|
||||
if (Camera is not null && sequence.CameraModel != Camera) return false;
|
||||
var (with, without) = Flags(Status);
|
||||
if ((sequence.Status & with) != with || (sequence.Status & without) != 0) return false;
|
||||
if (!MatchesStatus(sequence, Status)) return false;
|
||||
if (Tag is not null && !sequence.Tags.Contains(TagRepository.Normalize(Tag), StringComparer.OrdinalIgnoreCase)) return false;
|
||||
if (string.IsNullOrWhiteSpace(Text)) return true;
|
||||
var text = Text.Trim();
|
||||
@@ -101,7 +113,24 @@ public sealed record LibraryFilter
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Flags that must be set and clear for a status choice.</summary>
|
||||
/// <summary>The status test of the index (<see cref="ToQuery"/>) on one sequence.</summary>
|
||||
public static bool MatchesStatus(Sequence sequence, StatusFilter status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case StatusFilter.Rendered:
|
||||
return sequence.RenderedCount > 0;
|
||||
case StatusFilter.NotRendered:
|
||||
return sequence.RenderedCount == 0;
|
||||
case StatusFilter.Synced:
|
||||
return SyncedStates.Contains(sequence.SyncState);
|
||||
default:
|
||||
var (with, without) = Flags(status);
|
||||
return (sequence.Status & with) == with && (sequence.Status & without) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Flags that must be set and clear for a status choice (none for the choices that test renders or sync).</summary>
|
||||
public static (SequenceStatus With, SequenceStatus Without) Flags(StatusFilter status) => status switch
|
||||
{
|
||||
StatusFilter.Analysed => (SequenceStatus.AnalyzedLight, SequenceStatus.None),
|
||||
|
||||
@@ -22,13 +22,17 @@ public sealed record RemoteSource(SyncService Service, string Server, ISyncRemot
|
||||
/// <summary>
|
||||
/// Thumbnails of server sequences without a copy here (BRIEF §4.4): the hero frame (else the first) from the proxy
|
||||
/// cache when the sequence was fetched with proxies, otherwise the server's thumbnail of that frame through the API.
|
||||
/// Decoded at a 64 px width step and kept in an LRU cache; failed downloads are not cached, so they are tried again.
|
||||
/// The first frame of a sequence without a hero is asked once (one row of its frames page) and remembered. Decoded at
|
||||
/// a 64 px width step and kept in an LRU cache; failed downloads are not cached, so they are tried again.
|
||||
/// </summary>
|
||||
public sealed class RemoteThumbnails(Func<RemoteSource?> source, int capacity = 256) : ISequenceThumbnails, IDisposable
|
||||
{
|
||||
private const int WidthStep = 64;
|
||||
|
||||
private readonly ConcurrentDictionary<Guid, Guid?> _heroes = new();
|
||||
|
||||
/// <summary>The first frame of sequences without a hero frame (a sequence with no frame yet is asked again later).</summary>
|
||||
private readonly ConcurrentDictionary<Guid, Guid> _firstFrames = new();
|
||||
private ThumbnailCache<(Guid Sequence, int Width), ImageSource>? _cache;
|
||||
|
||||
private ThumbnailCache<(Guid Sequence, int Width), ImageSource> Cache => _cache ??= new(capacity, LoadAsync, maxConcurrentLoads: 4);
|
||||
@@ -43,7 +47,11 @@ public sealed class RemoteThumbnails(Func<RemoteSource?> source, int capacity =
|
||||
public IThumbnailSource? ScrubSource(Sequence sequence) => null;
|
||||
|
||||
/// <summary>Forgets every thumbnail (another server, or the cache was cleared).</summary>
|
||||
public void Clear() => _cache?.Clear();
|
||||
public void Clear()
|
||||
{
|
||||
_cache?.Clear();
|
||||
_firstFrames.Clear();
|
||||
}
|
||||
|
||||
public void Dispose() => _cache?.Dispose();
|
||||
|
||||
@@ -58,7 +66,7 @@ public sealed class RemoteThumbnails(Func<RemoteSource?> source, int capacity =
|
||||
await using var file = new FileStream(cached.Files[index]!, FileMode.Open, FileAccess.Read, FileShare.Read, 1 << 16, FileOptions.Asynchronous);
|
||||
return ThumbnailService.DecodeStream(file, cached.Frames[index].Orientation, key.Width);
|
||||
}
|
||||
var frameId = hero ?? (await connection.Remote.GetManifestAsync(key.Sequence, ct).ConfigureAwait(false)).Frames.FirstOrDefault()?.Id;
|
||||
var frameId = hero ?? await FirstFrameAsync(connection.Remote, key.Sequence, ct).ConfigureAwait(false);
|
||||
if (frameId is null) return null;
|
||||
using var thumbnail = new MemoryStream();
|
||||
await connection.Remote.DownloadFrameAsync(frameId.Value, "thumb", thumbnail, ct).ConfigureAwait(false);
|
||||
@@ -67,6 +75,14 @@ public sealed class RemoteThumbnails(Func<RemoteSource?> source, int capacity =
|
||||
return ThumbnailService.DecodeStream(thumbnail, 1, key.Width);
|
||||
}
|
||||
|
||||
private async Task<Guid?> FirstFrameAsync(ISyncRemote remote, Guid sequence, CancellationToken ct)
|
||||
{
|
||||
if (_firstFrames.TryGetValue(sequence, out var known)) return known;
|
||||
if ((await remote.FirstFrameAsync(sequence, ct).ConfigureAwait(false))?.Id is not { } first) return null;
|
||||
_firstFrames[sequence] = first;
|
||||
return first;
|
||||
}
|
||||
|
||||
private static int IndexOf(IReadOnlyList<Frame> frames, Guid id)
|
||||
{
|
||||
for (var i = 0; i < frames.Count; i++)
|
||||
|
||||
@@ -23,6 +23,7 @@ public sealed class SequenceItem : ObservableObject
|
||||
private SyncEntry? _sync;
|
||||
private string? _syncToolTip;
|
||||
private bool _canSync;
|
||||
private string? _quickBlocker;
|
||||
private string? _presetName;
|
||||
private ImageSource? _thumbnail;
|
||||
private IThumbnailSource? _scrub;
|
||||
@@ -51,12 +52,27 @@ public sealed class SequenceItem : ObservableObject
|
||||
|
||||
public string SyncToolTip => _syncToolTip ?? Loc.L("Library.Blocked.NotConnected");
|
||||
|
||||
/// <summary>"Render · 4K archive": the preset the Render quick action queues, the recommended one or the default.</summary>
|
||||
public string RenderToolTip => Loc.L(IsRemote ? "Tooltips.Library.QuickRenderServer" : "Tooltips.Library.QuickRender", PresetName);
|
||||
/// <summary>The Analyse and Render quick actions can start (<see cref="AnalyseToolTip"/> says why not).</summary>
|
||||
public bool CanRunQuick => _quickBlocker is null;
|
||||
|
||||
/// <summary>The export preset of the sequence's project (the advisor's choice when it made one, else the default).</summary>
|
||||
/// <summary>What Analyse does here or on the server, or why it cannot start.</summary>
|
||||
public string AnalyseToolTip => _quickBlocker ?? Loc.L(IsRemote ? "Tooltips.Library.AnalyseServer" : "Tooltips.Library.Analyse");
|
||||
|
||||
/// <summary>
|
||||
/// "Queue a render with 4K archive…": the preset the Render quick action queues, or why it cannot start. A remote
|
||||
/// card's project lives on the server, which renders it with the sequence's own preset.
|
||||
/// </summary>
|
||||
public string RenderToolTip => _quickBlocker ?? (IsRemote ? Loc.L("Tooltips.Library.QuickRenderServer") : Loc.L("Tooltips.Library.QuickRender", PresetName));
|
||||
|
||||
/// <summary>
|
||||
/// The export preset of the sequence's project: the one chosen in the editor, else the advisor's recommendation the
|
||||
/// analyses store in the project (Auto), else the default.
|
||||
/// </summary>
|
||||
public string PresetName => _presetName ??= ResolvePreset(_sequence.SettingsJson);
|
||||
|
||||
/// <summary>How the card reacts to the mouse; remote cards have no frames here to scrub.</summary>
|
||||
public string CardToolTip => Loc.L(IsRemote ? "Tooltips.Library.CardRemote" : "Tooltips.Library.Card");
|
||||
|
||||
/// <summary>User title or "{date} {camera}".</summary>
|
||||
public string Title => _sequence.DisplayTitle;
|
||||
|
||||
@@ -107,6 +123,16 @@ public sealed class SequenceItem : ObservableObject
|
||||
OnPropertyChanged(nameof(SyncToolTip));
|
||||
}
|
||||
|
||||
/// <summary>Why Analyse and Render cannot start now (no engine here, or the server is not connected); null when they can.</summary>
|
||||
public void SetQuickBlocker(string? blocker)
|
||||
{
|
||||
if (_quickBlocker == blocker) return;
|
||||
_quickBlocker = blocker;
|
||||
OnPropertyChanged(nameof(CanRunQuick));
|
||||
OnPropertyChanged(nameof(AnalyseToolTip));
|
||||
OnPropertyChanged(nameof(RenderToolTip));
|
||||
}
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
get => _isSelected;
|
||||
|
||||
@@ -9,8 +9,10 @@ namespace Titano.Ui.Visuals;
|
||||
/// Library timeline mode (BRIEF §12.2): one band per year with its label on the left and a density bar per slot
|
||||
/// (month) on a scale shared by all bands, slot labels underneath and a divider between bands. The current slot
|
||||
/// (<see cref="CurrentBand"/>, <see cref="CurrentSlot"/>) is outlined in Accent; clicking a slot makes it current
|
||||
/// and raises <see cref="SlotActivatedEvent"/>. Desired height = bands × <see cref="BandHeight"/>, so the control
|
||||
/// scrolls inside a ScrollViewer.
|
||||
/// and raises <see cref="SlotActivatedEvent"/>. From the keyboard, the arrow keys move a dashed focus ring from month to
|
||||
/// month (Left and Right run across years, Up and Down change year, Home and End go to the year's ends) with its
|
||||
/// readout, and Enter or Space activates the slot under it. Desired height = bands × <see cref="BandHeight"/>, so the
|
||||
/// control scrolls inside a ScrollViewer and brings the focused band into sight.
|
||||
/// </summary>
|
||||
public sealed class TimelineBands : DrawingElement
|
||||
{
|
||||
@@ -46,6 +48,16 @@ public sealed class TimelineBands : DrawingElement
|
||||
|
||||
private (int Band, int Slot) _hover = (-1, -1);
|
||||
|
||||
/// <summary>The slot the keyboard is on; (−1, −1) until the control first takes keyboard focus.</summary>
|
||||
private (int Band, int Slot) _keyboard = (-1, -1);
|
||||
|
||||
static TimelineBands()
|
||||
{
|
||||
FocusableProperty.OverrideMetadata(typeof(TimelineBands), new FrameworkPropertyMetadata(true));
|
||||
// The focused slot is outlined on the drawing itself.
|
||||
FocusVisualStyleProperty.OverrideMetadata(typeof(TimelineBands), new FrameworkPropertyMetadata(null));
|
||||
}
|
||||
|
||||
/// <summary>One band per year: label + one value per slot.</summary>
|
||||
public IReadOnlyList<ChartRow>? Bands { get => (IReadOnlyList<ChartRow>?)GetValue(BandsProperty); set => SetValue(BandsProperty, value); }
|
||||
|
||||
@@ -90,6 +102,7 @@ public sealed class TimelineBands : DrawingElement
|
||||
protected override void OnDataChanged()
|
||||
{
|
||||
_hover = (-1, -1);
|
||||
if (_keyboard.Band >= (Bands?.Count ?? 0) || _keyboard.Slot >= SlotCount) _keyboard = (-1, -1);
|
||||
base.OnDataChanged();
|
||||
}
|
||||
|
||||
@@ -137,6 +150,8 @@ public sealed class TimelineBands : DrawingElement
|
||||
}
|
||||
if (b == CurrentBand && s == CurrentSlot)
|
||||
dc.DrawRoundedRectangle(null, GetPen("Brush.Accent", 1.5), new Rect(cx - pitch / 2 + 2, top + 4, pitch - 4, BandHeight - 8), 4, 4);
|
||||
if (IsKeyboardFocused && b == _keyboard.Band && s == _keyboard.Slot)
|
||||
dc.DrawRoundedRectangle(null, GetPen("Brush.Accent", 2, LineDash.Dashed), new Rect(cx - pitch / 2 + 0.5, top + 1, pitch - 1, BandHeight - 2), 5, 5);
|
||||
}
|
||||
if (b < bands.Count - 1)
|
||||
{
|
||||
@@ -174,10 +189,75 @@ public sealed class TimelineBands : DrawingElement
|
||||
base.OnMouseLeftButtonUp(e);
|
||||
var (band, slot) = HitTest(e.GetPosition(this));
|
||||
if (band < 0) return;
|
||||
_keyboard = (band, slot);
|
||||
Activate(band, slot);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
|
||||
{
|
||||
base.OnGotKeyboardFocus(e);
|
||||
if (_keyboard.Band < 0 && Bands is { Count: > 0 } && SlotCount > 0)
|
||||
_keyboard = CurrentBand >= 0 && CurrentSlot >= 0 ? (CurrentBand, CurrentSlot) : (0, 0);
|
||||
InvalidateVisual();
|
||||
}
|
||||
|
||||
protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
|
||||
{
|
||||
base.OnLostKeyboardFocus(e);
|
||||
Readout.Hide();
|
||||
InvalidateVisual();
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
var bands = Bands?.Count ?? 0;
|
||||
var slots = SlotCount;
|
||||
if (e.Handled || bands == 0 || slots == 0) return;
|
||||
var (band, slot) = _keyboard.Band >= 0 ? _keyboard : (0, 0);
|
||||
switch (e.Key)
|
||||
{
|
||||
case Key.Enter or Key.Space:
|
||||
Activate(band, slot);
|
||||
e.Handled = true;
|
||||
return;
|
||||
// Bands run newest first: Left goes back in time, into the year below after January.
|
||||
case Key.Left:
|
||||
(band, slot) = slot > 0 ? (band, slot - 1) : band < bands - 1 ? (band + 1, slots - 1) : (band, slot);
|
||||
break;
|
||||
case Key.Right:
|
||||
(band, slot) = slot < slots - 1 ? (band, slot + 1) : band > 0 ? (band - 1, 0) : (band, slot);
|
||||
break;
|
||||
case Key.Up:
|
||||
band = Math.Max(0, band - 1);
|
||||
break;
|
||||
case Key.Down:
|
||||
band = Math.Min(bands - 1, band + 1);
|
||||
break;
|
||||
case Key.Home:
|
||||
slot = 0;
|
||||
break;
|
||||
case Key.End:
|
||||
slot = slots - 1;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
_keyboard = (band, slot);
|
||||
var pitch = SlotPitch;
|
||||
var top = band * BandHeight;
|
||||
BringIntoView(new Rect(0, top, ActualWidth, BandHeight));
|
||||
Readout.Show(ReadoutText(band, slot), new Point(LabelColumn + pitch * (slot + 0.5), top + BandHeight / 2));
|
||||
InvalidateVisual();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void Activate(int band, int slot)
|
||||
{
|
||||
SetCurrentValue(CurrentBandProperty, band);
|
||||
SetCurrentValue(CurrentSlotProperty, slot);
|
||||
RaiseEvent(new ChartItemEventArgs(SlotActivatedEvent, band, slot));
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private (int Band, int Slot) HitTest(Point p)
|
||||
|
||||
Reference in new issue
Block a user