- reloads and expanding never clear the tree selection; only jobs on this archive reload it, once they settle - one-row toolbar with the view switch and last scan on their own row; figure tiles shrink instead of cutting at the minimum width - set filter by camera, status and tag; duplicates and orphans searches can be cancelled; health fixes cover every matching sequence - Right/Left/Enter open and close years; dialogs hold the keyboard and only close themselves; disabled commands say why - adopt folder can copy into the layout (Import screen); database backup in Maintenance; Move dialog capture state Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
115 lines
5.6 KiB
C#
115 lines
5.6 KiB
C#
using Titano.App.Library;
|
|
using Titano.App.Settings;
|
|
using Titano.Core.Archiving;
|
|
using Titano.Core.Localization;
|
|
using Titano.Core.Model;
|
|
using Titano.Core.Naming;
|
|
using Titano.Data.Repositories;
|
|
|
|
namespace Titano.App.Archiving;
|
|
|
|
/// <summary>What a mass rename changes: the sequence titles (Rename) or the folder layout (Move).</summary>
|
|
public enum RenameMode
|
|
{
|
|
Titles,
|
|
Folders,
|
|
}
|
|
|
|
/// <summary>One line of the rename dry run: before → after.</summary>
|
|
public sealed record RenameRow(Guid SequenceId, string From, string To);
|
|
|
|
/// <summary>
|
|
/// Mass rename and move of sequences (BRIEF §7, §12.5): the template is checked live, the engine's dry run
|
|
/// (<see cref="RenamePlan"/>) is listed line by line, and applying makes exactly those changes.
|
|
/// </summary>
|
|
public static class MassRename
|
|
{
|
|
/// <summary>The first problem of a template, localized; null when it can be used.</summary>
|
|
public static string? Validate(RenameMode mode, string? template)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(template)) return Loc.L("Errors.Template.Empty", string.Empty, 1);
|
|
if (mode == RenameMode.Folders) return NamingPreview.Validate(template, isFolder: true);
|
|
var parsed = PathTemplate.Parse(template);
|
|
return parsed.Errors is [var error, ..] ? Loc.L("Errors.Template." + error.Code, error.Token ?? string.Empty, error.Position + 1) : null;
|
|
}
|
|
|
|
/// <summary>The changes of a plan as rows: titles or folders, whichever the mode changes.</summary>
|
|
public static IReadOnlyList<RenameRow> Rows(RenamePlan plan, RenameMode mode) =>
|
|
[
|
|
.. plan.Steps.Select(s => mode == RenameMode.Folders
|
|
? new RenameRow(s.SequenceId, s.FromFolder, s.ToFolder)
|
|
: new RenameRow(s.SequenceId, s.FromTitle ?? string.Empty, s.ToTitle ?? string.Empty)),
|
|
];
|
|
|
|
/// <summary>"12 of 36 sequences change".</summary>
|
|
public static string Summary(RenamePlan plan, int setSize) => Loc.Plural("Archive.Rename.Summary", plan.Steps.Count, setSize);
|
|
}
|
|
|
|
/// <summary>Adding and removing tags on a set of sequences (BRIEF §12.5 Retag).</summary>
|
|
public static class Retag
|
|
{
|
|
/// <summary>"sunset, harbour; Holy grail" → normalized, distinct tags; entries that cannot be tags are left out.</summary>
|
|
public static IReadOnlyList<string> Parse(string? text)
|
|
{
|
|
var seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
|
return [.. Split(text).Where(IsValid).Select(TagRepository.Normalize).Where(seen.Add)];
|
|
}
|
|
|
|
/// <summary>The problem of a tag list as one sentence; null when every entry can be a tag.</summary>
|
|
public static string? Validate(string? text) => Split(text).All(IsValid) ? null : Loc.L("Archive.Retag.Invalid", TagRepository.MaxLength);
|
|
|
|
private static IEnumerable<string> Split(string? text) =>
|
|
string.IsNullOrWhiteSpace(text) ? [] : text.Split([',', ';'], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
|
|
|
private static bool IsValid(string tag) => tag.Length is > 0 and <= TagRepository.MaxLength && !tag.Any(char.IsControl);
|
|
|
|
/// <summary>The new tag list of one sequence: removals first, then additions not already present.</summary>
|
|
public static IReadOnlyList<string> Apply(IReadOnlyList<string> current, IReadOnlyList<string> add, IReadOnlyList<string> remove)
|
|
{
|
|
var removed = new HashSet<string>(remove, StringComparer.OrdinalIgnoreCase);
|
|
var result = current.Where(t => !removed.Contains(t)).ToList();
|
|
var present = new HashSet<string>(result, StringComparer.OrdinalIgnoreCase);
|
|
result.AddRange(add.Where(present.Add));
|
|
return result;
|
|
}
|
|
|
|
/// <summary>Only the sequences whose tags change, with their new tags (the dry run).</summary>
|
|
public static IReadOnlyList<(Sequence Sequence, IReadOnlyList<string> Tags)> Changes(IEnumerable<Sequence> sequences, IReadOnlyList<string> add,
|
|
IReadOnlyList<string> remove) =>
|
|
[
|
|
.. sequences.Select(s => (Sequence: s, Tags: Apply(s.Tags, add, remove)))
|
|
.Where(c => !c.Tags.SequenceEqual(c.Sequence.Tags, StringComparer.Ordinal)),
|
|
];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Narrows the mass-operation set on top of the tree selection (Archive.html "Filtered set ▾"): camera, status and tag;
|
|
/// years and single sequences are chosen in the tree.
|
|
/// </summary>
|
|
public sealed record ArchiveSetFilter(string? Camera = null, StatusFilter Status = StatusFilter.Any, string? Tag = null)
|
|
{
|
|
public bool IsEmpty => Camera is null && Status == StatusFilter.Any && Tag is null;
|
|
|
|
public bool Matches(Sequence sequence)
|
|
{
|
|
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;
|
|
}
|
|
|
|
/// <summary>"Canon EOS R5 · Not analysed · sunset"; empty without a filter.</summary>
|
|
public string Describe() => string.Join(" · ", new[]
|
|
{
|
|
Camera ?? string.Empty,
|
|
Status == StatusFilter.Any ? string.Empty : StatusLabel(Status),
|
|
Tag ?? string.Empty,
|
|
}.Where(t => t.Length > 0));
|
|
|
|
/// <summary>The camera a sequence is filed under, as the camera chart names it.</summary>
|
|
public static string CameraOf(Sequence sequence) =>
|
|
PathTemplate.CameraName(sequence.CameraMake, sequence.CameraModel) is { Length: > 0 } name ? name : Loc.L("Archive.Chart.UnknownCamera");
|
|
|
|
public static string StatusLabel(StatusFilter status) => Loc.L(status == StatusFilter.Any ? "Library.Filter.AnyStatus" : "Library.Filter.Status." + status);
|
|
}
|