Delete… runs in an in-window dialog shared by the Library and the Archive manager: the dry run and the move into the trash report progress and stop on Cancel, the toast counts only what really moved, and its Undo reports failures. The confirmation names at most six moves and three refusals in the UI font. Delete… stands apart at the far right of both bars and last in the tab order. The toolbar's filters wrap instead of pushing out the right-hand group at 1200 px. Card and row quick actions show while selected or focused, so Tab reaches them; Analyse and Render are disabled with a reason when nothing can run them, and say so in a toast if the session drops. Remote cards get their own card, Analyse and Render tooltips; the details panel's Folder and the saved-view menu say why they are disabled. Status offers Rendered, Not rendered and Synced. Remote cards count in the Year and Camera choices and the timeline. The trash dialog shows one sentence when empty. --capture adds archive-trash and library-viewname. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
92 lines
4.2 KiB
C#
92 lines
4.2 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using Titano.Core.Diagnostics;
|
|
using Titano.Core.Localization;
|
|
using Titano.Data.Repositories;
|
|
|
|
namespace Titano.App.Library;
|
|
|
|
/// <summary>A named set of Library filters and sort ("Night, 4K, not rendered"), BRIEF §12.2.</summary>
|
|
public sealed record SavedView
|
|
{
|
|
public const int MaxName = 40;
|
|
|
|
public required Guid Id { get; init; }
|
|
public required string Name { get; init; }
|
|
public string? Text { get; init; }
|
|
public int? Year { get; init; }
|
|
public string? Camera { get; init; }
|
|
public StatusFilter Status { get; init; }
|
|
public string? Tag { get; init; }
|
|
public OriginFilter Origin { get; init; }
|
|
public SequenceSort Sort { get; init; } = SequenceSort.Newest;
|
|
|
|
public static SavedView Of(Guid id, string name, LibraryFilter filter) => new()
|
|
{
|
|
Id = id,
|
|
Name = name.Trim(),
|
|
Text = string.IsNullOrWhiteSpace(filter.Text) ? null : filter.Text.Trim(),
|
|
Year = filter.Year,
|
|
Camera = filter.Camera,
|
|
Status = filter.Status,
|
|
Tag = filter.Tag,
|
|
Origin = filter.Origin,
|
|
Sort = filter.Sort,
|
|
};
|
|
|
|
public LibraryFilter ToFilter() => new() { Text = Text, Year = Year, Camera = Camera, Status = Status, Tag = Tag, Origin = Origin, Sort = Sort };
|
|
|
|
/// <summary>The Library shows exactly this view (search text compared trimmed and case-insensitively).</summary>
|
|
public bool Matches(LibraryFilter filter) =>
|
|
string.Equals(Text ?? string.Empty, filter.Text?.Trim() ?? string.Empty, StringComparison.OrdinalIgnoreCase)
|
|
&& Year == filter.Year && Camera == filter.Camera && Status == filter.Status && Tag == filter.Tag && Origin == filter.Origin && Sort == filter.Sort;
|
|
|
|
/// <summary>The problem of a view name, localized; null when it can be used.</summary>
|
|
/// <param name="others">Names of the other saved views (a name is used once).</param>
|
|
public static string? Validate(string? name, IEnumerable<string> others)
|
|
{
|
|
var trimmed = name?.Trim() ?? string.Empty;
|
|
if (trimmed.Length == 0) return Loc.L("Library.Views.Error.Empty");
|
|
if (trimmed.Length > MaxName || trimmed.Any(char.IsControl)) return Loc.L("Library.Views.Error.Long", MaxName);
|
|
return others.Contains(trimmed, StringComparer.CurrentCultureIgnoreCase) ? Loc.L("Library.Views.Error.Taken") : null;
|
|
}
|
|
}
|
|
|
|
/// <summary>Saved views as app-scope settings rows (<c>library.view.<id></c>), one row per view.</summary>
|
|
public sealed class SavedViewStore(SettingsRepository settings)
|
|
{
|
|
private const string Prefix = "library.view.";
|
|
|
|
/// <summary>Every saved view by name; unreadable rows are skipped.</summary>
|
|
public async Task<IReadOnlyList<SavedView>> ListAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
var views = new List<SavedView>();
|
|
foreach (var (key, json) in await settings.ListAsync(SettingScope.App, null, cancellationToken))
|
|
{
|
|
if (!key.StartsWith(Prefix, StringComparison.Ordinal)) continue;
|
|
try
|
|
{
|
|
if (JsonSerializer.Deserialize(json, SavedViewJson.Default.SavedView) is { } view) views.Add(view);
|
|
}
|
|
catch (JsonException ex)
|
|
{
|
|
Log.Warning("library", $"Saved view {key} is unreadable", ex);
|
|
}
|
|
}
|
|
return [.. views.OrderBy(v => v.Name, StringComparer.CurrentCultureIgnoreCase)];
|
|
}
|
|
|
|
/// <summary>Adds the view or replaces the one with its id.</summary>
|
|
public Task SaveAsync(SavedView view, CancellationToken cancellationToken = default) =>
|
|
settings.SetAsync(SettingScope.App, null, Key(view.Id), view, SavedViewJson.Default.SavedView, cancellationToken);
|
|
|
|
public Task<bool> DeleteAsync(Guid id, CancellationToken cancellationToken = default) => settings.DeleteAsync(SettingScope.App, null, Key(id), cancellationToken);
|
|
|
|
private static string Key(Guid id) => Prefix + id.ToString("N");
|
|
}
|
|
|
|
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
|
UseStringEnumConverter = true)]
|
|
[JsonSerializable(typeof(SavedView))]
|
|
internal sealed partial class SavedViewJson : JsonSerializerContext;
|