fix(app): archive tree selection, toolbar, filters and dialogs after review

- 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
This commit is contained in:
Claude committed 2026-10-03 10:44:22 +00:00
1 parent 29c82eba5c
commit 58ae096061
9 files changed
+614 -124

No files matched your search

+16 -1
View File
@@ -4,12 +4,20 @@
<resheader name="version"><value>2.0</value></resheader>
<resheader name="reader"><value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
<resheader name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
<data name="Archive.Adopt.Copy" xml:space="preserve"><value>Copy into the layout…</value></data>
<data name="Archive.Adopt.InPlace" xml:space="preserve"><value>Index in place…</value></data>
<data name="Archive.Applied.one" xml:space="preserve"><value>{0:N0} sequence changed</value></data>
<data name="Archive.Applied.other" xml:space="preserve"><value>{0:N0} sequences changed</value></data>
<data name="Archive.Availability.Offline" xml:space="preserve"><value>offline</value></data>
<data name="Archive.Availability.Online" xml:space="preserve"><value>online</value></data>
<data name="Archive.Availability.ReadOnly" xml:space="preserve"><value>read-only</value></data>
<data name="Archive.Backup.Failed" xml:space="preserve"><value>The database backup stopped</value><comment>long</comment></data>
<data name="Archive.Blocked.Applying" xml:space="preserve"><value>Wait until the changes are applied.</value><comment>long</comment></data>
<data name="Archive.Blocked.EmptySet" xml:space="preserve"><value>The set is empty: change the selection or the filter.</value><comment>long</comment></data>
<data name="Archive.Blocked.NoChanges" xml:space="preserve"><value>Nothing would change.</value><comment>long</comment></data>
<data name="Archive.Blocked.NotOnline" xml:space="preserve"><value>The archive must be online and writable.</value><comment>long</comment></data>
<data name="Archive.Blocked.Planning" xml:space="preserve"><value>Wait for the dry run.</value><comment>long</comment></data>
<data name="Archive.Blocked.Searching" xml:space="preserve"><value>A search is running; cancel it or wait.</value><comment>long</comment></data>
<data name="Archive.Chart.Cameras" xml:space="preserve"><value>By camera</value></data>
<data name="Archive.Chart.Formats" xml:space="preserve"><value>By format</value></data>
<data name="Archive.Chart.MonthTip" xml:space="preserve"><value>{0} · {1} · {2}</value><comment>invariant</comment></data>
@@ -25,6 +33,7 @@
<data name="Archive.Confirm.Remove" xml:space="preserve"><value>Remove row</value></data>
<data name="Archive.Confirm.RemoveHeading" xml:space="preserve"><value>Remove {0} from the index?</value><comment>long</comment></data>
<data name="Archive.Confirm.RemoveMessage" xml:space="preserve"><value>Its sidecar is gone. Only the index row is removed; no file is deleted.</value><comment>long</comment></data>
<data name="Archive.Copy.Title" xml:space="preserve"><value>Folder to copy into the archive</value><comment>long</comment></data>
<data name="Archive.Dialog.Cancel" xml:space="preserve"><value>Cancel</value></data>
<data name="Archive.Duplicates.Copies.one" xml:space="preserve"><value>{0:N0} copy</value></data>
<data name="Archive.Duplicates.Copies.other" xml:space="preserve"><value>{0:N0} copies</value></data>
@@ -45,6 +54,7 @@
<data name="Archive.Error.SourceChanged" xml:space="preserve"><value>{0} changed after the plan was made.</value><comment>long: error sentence</comment></data>
<data name="Archive.Error.SourceGone" xml:space="preserve"><value>The card or folder {0} is no longer available.</value><comment>long: error sentence</comment></data>
<data name="Archive.Error.StalePlan" xml:space="preserve"><value>The archive changed after this plan was made.</value><comment>long: error sentence</comment></data>
<data name="Archive.Find.Cancel" xml:space="preserve"><value>Cancel</value></data>
<data name="Archive.Find.None" xml:space="preserve"><value>None found</value></data>
<data name="Archive.Find.Run" xml:space="preserve"><value>Find</value></data>
<data name="Archive.Find.Searching" xml:space="preserve"><value>Searching…</value></data>
@@ -82,6 +92,7 @@
<data name="Archive.Log.ScanDone" xml:space="preserve"><value>{0} folders, {1} indexed, {2} adopted, {3} removed</value><comment>long: job log line</comment></data>
<data name="Archive.Log.SequenceMissing" xml:space="preserve"><value>Sequence not found: {0}</value><comment>long: job log line</comment></data>
<data name="Archive.Log.VerifyDone" xml:space="preserve"><value>{0} photos checked, {1} intact, {2} hashed, {3} with problems</value><comment>long: job log line</comment></data>
<data name="Archive.Maintenance.Backup" xml:space="preserve"><value>Back up database</value></data>
<data name="Archive.Maintenance.DryRun" xml:space="preserve"><value>Dry run</value></data>
<data name="Archive.Maintenance.Proxies" xml:space="preserve"><value>Rebuild proxies</value></data>
<data name="Archive.Maintenance.Relink" xml:space="preserve"><value>Relink moved archive…</value></data>
@@ -114,6 +125,7 @@
<data name="Archive.Rebuild.Sidecars" xml:space="preserve"><value>Sidecars</value></data>
<data name="Archive.Rebuild.Start" xml:space="preserve"><value>Rebuild</value></data>
<data name="Archive.Rebuild.State" xml:space="preserve"><value>State</value></data>
<data name="Archive.Recent.Empty" xml:space="preserve"><value>No maintenance yet.</value><comment>long</comment></data>
<data name="Archive.Recent.History" xml:space="preserve"><value>History</value></data>
<data name="Archive.Recent.Line" xml:space="preserve"><value>{0} · {1}</value><comment>invariant</comment></data>
<data name="Archive.Recent.Title" xml:space="preserve"><value>Recent maintenance</value></data>
@@ -139,8 +151,10 @@
<data name="Archive.Set.All.one" xml:space="preserve"><value>{0:N0} sequence · all</value></data>
<data name="Archive.Set.All.other" xml:space="preserve"><value>{0:N0} sequences · all</value></data>
<data name="Archive.Set.Analyse" xml:space="preserve"><value>Analyse</value></data>
<data name="Archive.Set.ClearFilter" xml:space="preserve"><value>Clear filter</value></data>
<data name="Archive.Set.Export" xml:space="preserve"><value>Export CSV</value></data>
<data name="Archive.Set.Label" xml:space="preserve"><value>Selected set</value></data>
<data name="Archive.Set.Filter" xml:space="preserve"><value>Set filter</value></data>
<data name="Archive.Set.Label" xml:space="preserve"><value>Filtered set</value></data>
<data name="Archive.Set.Move" xml:space="preserve"><value>Move…</value></data>
<data name="Archive.Set.Proxies" xml:space="preserve"><value>Proxies</value></data>
<data name="Archive.Set.Rename" xml:space="preserve"><value>Rename…</value></data>
@@ -159,6 +173,7 @@
<data name="Archive.Tile.Sequences.other" xml:space="preserve"><value>sequences</value></data>
<data name="Archive.Tile.YearRange" xml:space="preserve"><value>{0} – {1}</value><comment>invariant</comment></data>
<data name="Archive.Toolbar.Adopt" xml:space="preserve"><value>Adopt folder…</value></data>
<data name="Archive.Toolbar.AdoptMenu" xml:space="preserve"><value>Adopt folder</value></data>
<data name="Archive.Toolbar.Archive" xml:space="preserve"><value>Archive</value></data>
<data name="Archive.Toolbar.Duplicates" xml:space="preserve"><value>Duplicates</value></data>
<data name="Archive.Toolbar.Maintenance" xml:space="preserve"><value>Maintenance</value></data>
+19 -4
View File
@@ -4,12 +4,20 @@
<resheader name="version"><value>2.0</value></resheader>
<resheader name="reader"><value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
<resheader name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
<data name="Archive.Adopt.Copy" xml:space="preserve"><value>Copia nella struttura…</value></data>
<data name="Archive.Adopt.InPlace" xml:space="preserve"><value>Indicizza sul posto…</value></data>
<data name="Archive.Applied.one" xml:space="preserve"><value>{0:N0} sequenza modificata</value></data>
<data name="Archive.Applied.other" xml:space="preserve"><value>{0:N0} sequenze modificate</value></data>
<data name="Archive.Availability.Offline" xml:space="preserve"><value>offline</value></data>
<data name="Archive.Availability.Online" xml:space="preserve"><value>online</value></data>
<data name="Archive.Availability.ReadOnly" xml:space="preserve"><value>sola lettura</value></data>
<data name="Archive.Backup.Failed" xml:space="preserve"><value>La copia del database si è interrotta</value></data>
<data name="Archive.Blocked.Applying" xml:space="preserve"><value>Attendi che le modifiche siano applicate.</value></data>
<data name="Archive.Blocked.EmptySet" xml:space="preserve"><value>La selezione è vuota: cambia la selezione o il filtro.</value></data>
<data name="Archive.Blocked.NoChanges" xml:space="preserve"><value>Non cambierebbe nulla.</value></data>
<data name="Archive.Blocked.NotOnline" xml:space="preserve"><value>L'archivio deve essere raggiungibile e scrivibile.</value></data>
<data name="Archive.Blocked.Planning" xml:space="preserve"><value>Attendi la simulazione.</value></data>
<data name="Archive.Blocked.Searching" xml:space="preserve"><value>Una ricerca è in corso: annullala o attendi.</value></data>
<data name="Archive.Chart.Cameras" xml:space="preserve"><value>Per fotocamera</value></data>
<data name="Archive.Chart.Formats" xml:space="preserve"><value>Per formato</value></data>
<data name="Archive.Chart.Months" xml:space="preserve"><value>Foto al mese</value></data>
@@ -17,11 +25,12 @@
<data name="Archive.Chart.OtherCameras.other" xml:space="preserve"><value>{0:N0} altre</value></data>
<data name="Archive.Chart.OtherFormats" xml:space="preserve"><value>Altro</value></data>
<data name="Archive.Chart.Storage" xml:space="preserve"><value>Spazio per anno</value></data>
<data name="Archive.Chart.UnknownCamera" xml:space="preserve"><value>Fotocamera ignota</value></data>
<data name="Archive.Chart.UnknownCamera" xml:space="preserve"><value>Fotocamera sconosciuta</value></data>
<data name="Archive.Confirm.Keep" xml:space="preserve"><value>Mantieni riga</value></data>
<data name="Archive.Confirm.Remove" xml:space="preserve"><value>Rimuovi riga</value></data>
<data name="Archive.Confirm.RemoveHeading" xml:space="preserve"><value>Rimuovere {0} dall'indice?</value></data>
<data name="Archive.Confirm.RemoveMessage" xml:space="preserve"><value>Il suo sidecar non c'è più. Viene rimossa solo la riga dell'indice; nessun file viene eliminato.</value></data>
<data name="Archive.Copy.Title" xml:space="preserve"><value>Cartella da copiare nell'archivio</value></data>
<data name="Archive.Dialog.Cancel" xml:space="preserve"><value>Annulla</value></data>
<data name="Archive.Duplicates.Copies.one" xml:space="preserve"><value>{0:N0} copia</value></data>
<data name="Archive.Duplicates.Copies.other" xml:space="preserve"><value>{0:N0} copie</value></data>
@@ -41,6 +50,7 @@
<data name="Archive.Error.SourceChanged" xml:space="preserve"><value>{0} è cambiato dopo la creazione del piano.</value></data>
<data name="Archive.Error.SourceGone" xml:space="preserve"><value>La scheda o cartella {0} non è più disponibile.</value></data>
<data name="Archive.Error.StalePlan" xml:space="preserve"><value>L'archivio è cambiato dopo la creazione del piano.</value></data>
<data name="Archive.Find.Cancel" xml:space="preserve"><value>Annulla</value></data>
<data name="Archive.Find.None" xml:space="preserve"><value>Nessuno trovato</value></data>
<data name="Archive.Find.Run" xml:space="preserve"><value>Cerca</value></data>
<data name="Archive.Find.Searching" xml:space="preserve"><value>Ricerca…</value></data>
@@ -60,12 +70,12 @@
<data name="Archive.Health.NoProxies.other" xml:space="preserve"><value>{0:N0} sequenze senza proxy</value></data>
<data name="Archive.Health.NotAnalysed.one" xml:space="preserve"><value>{0:N0} sequenza non analizzata</value></data>
<data name="Archive.Health.NotAnalysed.other" xml:space="preserve"><value>{0:N0} sequenze non analizzate</value></data>
<data name="Archive.Health.ProxiesOk" xml:space="preserve"><value>Proxy pronti per tutte</value></data>
<data name="Archive.Health.ProxiesOk" xml:space="preserve"><value>Ogni sequenza ha i proxy</value></data>
<data name="Archive.Health.Title" xml:space="preserve"><value>Stato dell'indice</value></data>
<data name="Archive.Health.Unverified.one" xml:space="preserve"><value>{0:N0} sequenza non verificata</value></data>
<data name="Archive.Health.Unverified.other" xml:space="preserve"><value>{0:N0} sequenze non verificate</value></data>
<data name="Archive.LastScan" xml:space="preserve"><value>Ultima scansione {0} · {1}</value></data>
<data name="Archive.Log.DryRun" xml:space="preserve"><value>Prova: nulla è stato modificato.</value></data>
<data name="Archive.Log.DryRun" xml:space="preserve"><value>Simulazione: nulla è stato modificato.</value></data>
<data name="Archive.Log.FolderFailed" xml:space="preserve"><value>Non indicizzata: {0} ({1})</value></data>
<data name="Archive.Log.FrameChanged" xml:space="preserve"><value>Modificato: {0}</value></data>
<data name="Archive.Log.FrameCorrupt" xml:space="preserve"><value>Danneggiato: {0}</value></data>
@@ -78,6 +88,7 @@
<data name="Archive.Log.ScanDone" xml:space="preserve"><value>{0} cartelle, {1} indicizzate, {2} adottate, {3} rimosse</value></data>
<data name="Archive.Log.SequenceMissing" xml:space="preserve"><value>Sequenza non trovata: {0}</value></data>
<data name="Archive.Log.VerifyDone" xml:space="preserve"><value>{0} foto controllate, {1} integre, {2} con impronta nuova, {3} con problemi</value></data>
<data name="Archive.Maintenance.Backup" xml:space="preserve"><value>Copia del database</value></data>
<data name="Archive.Maintenance.DryRun" xml:space="preserve"><value>Simulazione</value></data>
<data name="Archive.Maintenance.Proxies" xml:space="preserve"><value>Ricrea proxy</value></data>
<data name="Archive.Maintenance.Relink" xml:space="preserve"><value>Ricollega archivio spostato…</value></data>
@@ -110,6 +121,7 @@
<data name="Archive.Rebuild.Sidecars" xml:space="preserve"><value>Sidecar</value></data>
<data name="Archive.Rebuild.Start" xml:space="preserve"><value>Ricostruisci</value></data>
<data name="Archive.Rebuild.State" xml:space="preserve"><value>Stato</value></data>
<data name="Archive.Recent.Empty" xml:space="preserve"><value>Ancora nessuna manutenzione.</value></data>
<data name="Archive.Recent.History" xml:space="preserve"><value>Cronologia</value></data>
<data name="Archive.Recent.Title" xml:space="preserve"><value>Manutenzione recente</value></data>
<data name="Archive.Relink.Done" xml:space="preserve"><value>{0} ricollegato</value></data>
@@ -134,8 +146,10 @@
<data name="Archive.Set.All.one" xml:space="preserve"><value>{0:N0} sequenza · tutte</value></data>
<data name="Archive.Set.All.other" xml:space="preserve"><value>{0:N0} sequenze · tutte</value></data>
<data name="Archive.Set.Analyse" xml:space="preserve"><value>Analizza</value></data>
<data name="Archive.Set.ClearFilter" xml:space="preserve"><value>Togli filtro</value></data>
<data name="Archive.Set.Export" xml:space="preserve"><value>Esporta CSV</value></data>
<data name="Archive.Set.Label" xml:space="preserve"><value>Insieme scelto</value></data>
<data name="Archive.Set.Filter" xml:space="preserve"><value>Filtro selezione</value></data>
<data name="Archive.Set.Label" xml:space="preserve"><value>Selezione</value></data>
<data name="Archive.Set.Move" xml:space="preserve"><value>Sposta…</value></data>
<data name="Archive.Set.Proxies" xml:space="preserve"><value>Proxy</value></data>
<data name="Archive.Set.Rename" xml:space="preserve"><value>Rinomina…</value></data>
@@ -153,6 +167,7 @@
<data name="Archive.Tile.Sequences.one" xml:space="preserve"><value>sequenza</value></data>
<data name="Archive.Tile.Sequences.other" xml:space="preserve"><value>sequenze</value></data>
<data name="Archive.Toolbar.Adopt" xml:space="preserve"><value>Adotta cartella…</value></data>
<data name="Archive.Toolbar.AdoptMenu" xml:space="preserve"><value>Adotta cartella</value></data>
<data name="Archive.Toolbar.Archive" xml:space="preserve"><value>Archivio</value></data>
<data name="Archive.Toolbar.Duplicates" xml:space="preserve"><value>Doppioni</value></data>
<data name="Archive.Toolbar.Maintenance" xml:space="preserve"><value>Manutenzione</value></data>
@@ -13,20 +13,29 @@ using Titano.Ui.Mvvm;
namespace Titano.App.Archiving;
/// <summary>An in-window dialog of the Archive screen: one primary action, one way out.</summary>
public abstract class ArchiveDialogViewModel(Action close) : LocalizedViewModel
/// <summary>
/// An in-window dialog of the Archive screen: one primary action, one way out. While its action runs it cannot be
/// closed; <paramref name="close"/> receives the dialog, so a late close never closes another one.
/// </summary>
public abstract class ArchiveDialogViewModel : LocalizedViewModel
{
private bool _isBusy;
private string? _busyText;
public ICommand CloseCommand { get; } = new RelayCommand(close);
protected ArchiveDialogViewModel(Action<ArchiveDialogViewModel> close) => CloseCommand = new RelayCommand(() => close(this), () => !IsBusy);
public ICommand CloseCommand { get; }
public string CloseToolTip => IsBusy ? Loc.L("Archive.Blocked.Applying") : Loc.L("Tooltips.Archive.CloseDialog");
public bool IsBusy
{
get => _isBusy;
protected set
{
if (Set(ref _isBusy, value)) CommandManager.InvalidateRequerySuggested();
if (!Set(ref _isBusy, value)) return;
OnPropertyChanged(nameof(CloseToolTip));
CommandManager.InvalidateRequerySuggested();
}
}
@@ -47,7 +56,8 @@ public sealed class RebuildDialogViewModel : ArchiveDialogViewModel
private readonly Func<Task> _rebuild;
private IReadOnlyList<DialogFact> _facts;
public RebuildDialogViewModel(Core.Model.Archive archive, ArchiveAvailability availability, int indexed, Func<Task> rebuild, Action close)
public RebuildDialogViewModel(Core.Model.Archive archive, ArchiveAvailability availability, int indexed, Func<Task> rebuild,
Action<ArchiveDialogViewModel> close)
: base(close)
{
_rebuild = rebuild;
@@ -137,7 +147,7 @@ public sealed class RenameDialogViewModel : ArchiveDialogViewModel
private CancellationTokenSource? _planning;
public RenameDialogViewModel(RenameMode mode, ArchiveService archives, Core.Model.Archive archive, IReadOnlyList<Sequence> set, Func<int, Task> applied,
Action close)
Action<ArchiveDialogViewModel> close)
: base(close)
{
Mode = mode;
@@ -159,9 +169,19 @@ public sealed class RenameDialogViewModel : ArchiveDialogViewModel
_delay.Stop();
_ = PlanAsync();
};
ApplyCommand = new AsyncRelayCommand(ApplyAsync, () => !IsBusy && _plan is { Steps.Count: > 0 } && !Template.HasErrors);
ApplyCommand = new AsyncRelayCommand(ApplyAsync, () => ApplyBlocker is null);
}
/// <summary>Why Apply is disabled; null when it can run.</summary>
private string? ApplyBlocker =>
IsBusy ? Loc.L("Archive.Blocked.Applying")
: Template.Error is { } error ? error
: _plan is null ? Loc.L("Archive.Blocked.Planning")
: _plan.Steps.Count == 0 ? Loc.L("Archive.Blocked.NoChanges")
: null;
public string ApplyToolTip => ApplyBlocker ?? Loc.L("Tooltips.Archive.RenameApply");
public RenameMode Mode { get; }
public string Heading => Loc.Plural(Mode == RenameMode.Folders ? "Archive.Rename.MoveHeading" : "Archive.Rename.Heading", _set.Count);
@@ -188,6 +208,7 @@ public sealed class RenameDialogViewModel : ArchiveDialogViewModel
_plan = null;
Rows = [];
OnPropertyChanged(nameof(SummaryText));
OnPropertyChanged(nameof(ApplyToolTip));
if (Template.HasErrors) return;
var cts = _planning = new CancellationTokenSource();
var template = Template.Text;
@@ -200,6 +221,7 @@ public sealed class RenameDialogViewModel : ArchiveDialogViewModel
_plan = plan;
Rows = MassRename.Rows(plan, Mode);
OnPropertyChanged(nameof(SummaryText));
OnPropertyChanged(nameof(ApplyToolTip));
CommandManager.InvalidateRequerySuggested();
}
catch (OperationCanceledException) when (cts.IsCancellationRequested)
@@ -242,7 +264,7 @@ public sealed class RetagDialogViewModel : ArchiveDialogViewModel
private readonly IReadOnlyList<Sequence> _set;
private readonly Func<int, Task> _applied;
public RetagDialogViewModel(ArchiveService archives, IReadOnlyList<Sequence> set, Func<int, Task> applied, Action close)
public RetagDialogViewModel(ArchiveService archives, IReadOnlyList<Sequence> set, Func<int, Task> applied, Action<ArchiveDialogViewModel> close)
: base(close)
{
_archives = archives;
@@ -250,11 +272,19 @@ public sealed class RetagDialogViewModel : ArchiveDialogViewModel
_applied = applied;
Add = new EditableField(string.Empty, Retag.Validate, _ => OnPropertyChanged(nameof(SummaryText)), () => Loc.L("Tooltips.Archive.TagsAdd"));
Remove = new EditableField(string.Empty, Retag.Validate, _ => OnPropertyChanged(nameof(SummaryText)), () => Loc.L("Tooltips.Archive.TagsRemove"));
Add.PropertyChanged += (_, _) => OnPropertyChanged(nameof(SummaryText));
Remove.PropertyChanged += (_, _) => OnPropertyChanged(nameof(SummaryText));
ApplyCommand = new AsyncRelayCommand(ApplyAsync, () => !IsBusy && Changes().Count > 0);
Add.PropertyChanged += (_, _) => OnTagsTyped();
Remove.PropertyChanged += (_, _) => OnTagsTyped();
ApplyCommand = new AsyncRelayCommand(ApplyAsync, () => ApplyBlocker is null);
}
/// <summary>Why Apply is disabled; null when it can run.</summary>
private string? ApplyBlocker =>
IsBusy ? Loc.L("Archive.Blocked.Applying")
: Add.Error ?? Remove.Error
?? (Changes().Count == 0 ? Loc.L("Archive.Blocked.NoChanges") : null);
public string ApplyToolTip => ApplyBlocker ?? Loc.L("Tooltips.Archive.RetagApply");
public string Heading => Loc.Plural("Archive.Retag.Heading", _set.Count);
public EditableField Add { get; }
@@ -265,6 +295,14 @@ public sealed class RetagDialogViewModel : ArchiveDialogViewModel
public ICommand ApplyCommand { get; }
/// <summary>Typing changes the dry run, and with it whether Apply can run.</summary>
private void OnTagsTyped()
{
OnPropertyChanged(nameof(SummaryText));
OnPropertyChanged(nameof(ApplyToolTip));
CommandManager.InvalidateRequerySuggested();
}
private IReadOnlyList<(Sequence Sequence, IReadOnlyList<string> Tags)> Changes() =>
Add.HasErrors || Remove.HasErrors ? [] : Retag.Changes(_set, Retag.Parse(Add.Text), Retag.Parse(Remove.Text));
@@ -24,6 +24,9 @@ public sealed class ArchiveTreeRowViewModel(ArchiveTreeNode node, ArchiveAvailab
public string ToggleToolTip => Loc.L(Node.IsExpanded ? "Tooltips.Archive.Collapse" : "Tooltips.Archive.Expand");
/// <summary>The row's figures; a year also says how the keyboard opens and closes it.</summary>
public string RowToolTip => IsYear ? Loc.L("Tooltips.Archive.YearRow", Detail) : Detail;
public ICommand ToggleCommand { get; } = new RelayCommand(() => toggle(node));
/// <summary>The archive's availability (BRIEF §7: online, read-only, offline) on the archive row.</summary>
@@ -71,3 +74,6 @@ public sealed class OrphanRowViewModel(OrphanRow row, ICommand fix) : Observable
public string FixText => Loc.L("Archive.Orphans.Fix." + Row.Kind);
public string FixToolTip => Loc.L("Tooltips.Archive.Orphans." + Row.Kind);
}
/// <summary>A value of a set filter menu (camera, status, tag): checked while chosen; choosing it again clears it.</summary>
public sealed record FilterChoice(string Label, bool IsChecked, ICommand Command);
+12 -3
View File
@@ -4,12 +4,12 @@ namespace Titano.App.Archiving;
/// <summary>
/// The Archive views that <c>--capture</c> renders (<c>archive-&lt;view&gt;-&lt;theme&gt;.png</c>) and the screen smoke
/// tests check, on the sample archive: the tree with figures and charts, the maintenance view with its reports, and
/// the rebuild dialog.
/// tests check, on the sample archive: the tree with figures and charts, the maintenance view with its reports, the
/// rebuild dialog, and the Move dialog with its dry run.
/// </summary>
public static class ArchiveScenes
{
public static readonly IReadOnlyList<string> Views = ["overview", "maintenance", "rebuild"];
public static readonly IReadOnlyList<string> Views = ["overview", "maintenance", "rebuild", "move"];
public static async Task ShowAsync(ShellViewModel shell, string view)
{
@@ -32,6 +32,15 @@ public static class ArchiveScenes
archive.ViewIndex = 0;
(await archive.OpenRebuildDialogAsync())?.ShowFolders(SampleReports.Folders(locations));
break;
case "move":
archive.ViewIndex = 0;
await archive.OpenRenameDialogAsync(RenameMode.Folders);
if (archive.Dialog is RenameDialogViewModel move)
{
move.Template.Text = "{year}/{date} {title}";
await move.PlanAsync();
}
break;
default:
throw new ArgumentOutOfRangeException(nameof(view), view, "Unknown Archive view.");
}
+32
View File
@@ -1,3 +1,4 @@
using Titano.App.Library;
using Titano.App.Settings;
using Titano.Core.Archiving;
using Titano.Core.Localization;
@@ -80,3 +81,34 @@ public static class Retag
.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);
}
+115 -49
View File
@@ -18,6 +18,25 @@
<Style x:Key="Button.Tool" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Margin" Value="0,0,8,8" />
</Style>
<Style TargetType="MenuItem" BasedOn="{StaticResource {x:Type MenuItem}}">
<Setter Property="ToolTipService.ShowOnDisabled" Value="True" />
</Style>
<!-- Rows that only show text: focusable, so the arrow keys move through a long list. -->
<Style x:Key="ListBoxItem.Preview" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem.Row}">
<Setter Property="Padding" Value="0" />
<Setter Property="AutomationProperties.Name" Value="{Binding To}" />
</Style>
<!-- Report rows with their own buttons: Tab reaches every button. -->
<Style x:Key="ListBoxItem.Duplicate" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem.PlainRow}">
<Setter Property="AutomationProperties.Name" Value="{Binding Row.Title}" />
</Style>
<!-- A filter menu: its values, each checked while chosen. -->
<Style x:Key="MenuItem.Choice" TargetType="MenuItem" BasedOn="{StaticResource {x:Type MenuItem}}">
<Setter Property="Header" Value="{Binding Label}" />
<Setter Property="IsChecked" Value="{Binding IsChecked, Mode=OneWay}" />
<Setter Property="Command" Value="{Binding Command}" />
<Setter Property="ToolTip" Value="{l:Loc Tooltips.Archive.FilterChoice}" />
</Style>
<!-- Dialog card (DESIGN §4: Surface, Stroke, radius 12, 24 px shadow, two buttons). -->
<Style x:Key="Border.Dialog" TargetType="Border">
@@ -51,7 +70,7 @@
</ItemsControl>
<TextBlock Text="{Binding BusyText}" Foreground="{DynamicResource Brush.TextMuted}" Visibility="{Binding BusyText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,18,0,0">
<Button Content="{l:Loc Archive.Dialog.Cancel}" Command="{Binding CloseCommand}" ToolTip="{l:Loc Tooltips.Archive.CloseDialog}" IsDefault="True" IsCancel="True"
<Button Content="{l:Loc Archive.Dialog.Cancel}" Command="{Binding CloseCommand}" ToolTip="{Binding CloseToolTip}" IsDefault="True" IsCancel="True"
MinWidth="96" />
<Button Style="{StaticResource Button.Primary}" Content="{l:Loc Archive.Rebuild.Start}" Command="{Binding RebuildCommand}" ToolTip="{Binding RebuildToolTip}"
MinWidth="96" Margin="8,0,0,0" />
@@ -81,7 +100,7 @@
shell:EditBehavior.Field="{Binding Template}" ToolTip="{Binding Template.ToolTip}" AutomationProperties.Name="{l:Loc Archive.Rename.Template}" />
</Grid>
<TextBlock Grid.Row="2" Text="{Binding SummaryText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,12,0,6" Typography.NumeralAlignment="Tabular" />
<ListBox Grid.Row="3" ItemsSource="{Binding Rows}" ItemContainerStyle="{StaticResource ListBoxItem.PlainRow}" MinHeight="120"
<ListBox Grid.Row="3" ItemsSource="{Binding Rows}" ItemContainerStyle="{StaticResource ListBoxItem.Preview}" MinHeight="120"
AutomationProperties.Name="{l:Loc Archive.Rename.Preview}">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type ar:RenameRow}">
@@ -100,8 +119,8 @@
</ListBox>
<DockPanel Grid.Row="4" Margin="0,16,0,0">
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Primary}" Content="{l:Loc Archive.Rename.Apply}" Command="{Binding ApplyCommand}"
ToolTip="{l:Loc Tooltips.Archive.RenameApply}" MinWidth="96" Margin="8,0,0,0" />
<Button DockPanel.Dock="Right" Content="{l:Loc Archive.Dialog.Cancel}" Command="{Binding CloseCommand}" ToolTip="{l:Loc Tooltips.Archive.CloseDialog}" IsCancel="True"
ToolTip="{Binding ApplyToolTip}" MinWidth="96" Margin="8,0,0,0" />
<Button DockPanel.Dock="Right" Content="{l:Loc Archive.Dialog.Cancel}" Command="{Binding CloseCommand}" ToolTip="{Binding CloseToolTip}" IsCancel="True"
MinWidth="96" />
<TextBlock Text="{Binding BusyText}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" />
</DockPanel>
@@ -132,8 +151,8 @@
<TextBlock Text="{Binding SummaryText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,12,0,0" Typography.NumeralAlignment="Tabular" />
<DockPanel Margin="0,18,0,0">
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Primary}" Content="{l:Loc Archive.Retag.Apply}" Command="{Binding ApplyCommand}"
ToolTip="{l:Loc Tooltips.Archive.RetagApply}" MinWidth="96" Margin="8,0,0,0" />
<Button DockPanel.Dock="Right" Content="{l:Loc Archive.Dialog.Cancel}" Command="{Binding CloseCommand}" ToolTip="{l:Loc Tooltips.Archive.CloseDialog}" IsCancel="True"
ToolTip="{Binding ApplyToolTip}" MinWidth="96" Margin="8,0,0,0" />
<Button DockPanel.Dock="Right" Content="{l:Loc Archive.Dialog.Cancel}" Command="{Binding CloseCommand}" ToolTip="{Binding CloseToolTip}" IsCancel="True"
MinWidth="96" />
<TextBlock Text="{Binding BusyText}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" />
</DockPanel>
@@ -143,22 +162,16 @@
</UserControl.Resources>
<Grid>
<Grid Margin="20,16">
<Grid Margin="20,16" IsEnabled="{Binding IsContentEnabled}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- ===================== Toolbar ===================== -->
<DockPanel Margin="0,0,0,6">
<v:SegmentedControl DockPanel.Dock="Right" SelectedIndex="{Binding ViewIndex}" VerticalAlignment="Top" AutomationProperties.Name="{l:Loc Archive.View.Name}">
<v:SegmentedItem Content="{l:Loc Archive.View.Overview}" ToolTip="{l:Loc Tooltips.Archive.Overview}" AutomationProperties.Name="{l:Loc Archive.View.Overview}" />
<v:SegmentedItem Content="{l:Loc Archive.View.Maintenance}" ToolTip="{l:Loc Tooltips.Archive.MaintenanceView}"
AutomationProperties.Name="{l:Loc Archive.View.Maintenance}" />
</v:SegmentedControl>
<TextBlock DockPanel.Dock="Right" Text="{Binding LastScanText}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Top" Margin="0,8,14,0"
Typography.NumeralAlignment="Tabular" ToolTip="{l:Loc Tooltips.Archive.LastScan}" />
<!-- ===================== Toolbar (Archive.html: one row) ===================== -->
<DockPanel Margin="0,0,0,4">
<ComboBox DockPanel.Dock="Left" Width="220" VerticalAlignment="Top" ItemsSource="{Binding Archives}" SelectedItem="{Binding SelectedArchive}" DisplayMemberPath="Name"
ToolTip="{Binding ArchiveToolTip}" AutomationProperties.Name="{l:Loc Archive.Toolbar.Archive}" Margin="0,0,8,8" />
<Border DockPanel.Dock="Left" Width="1" Height="22" Background="{DynamicResource Brush.Stroke}" Margin="4,5,12,0" VerticalAlignment="Top" />
@@ -167,9 +180,20 @@
<Button Style="{StaticResource Button.Tool}" Content="{l:Loc Archive.Toolbar.Rebuild}" Command="{Binding RebuildCommand}" ToolTip="{l:Loc Tooltips.Archive.Rebuild}" />
<Button Style="{StaticResource Button.Tool}" Content="{l:Loc Archive.Toolbar.Verify}" Command="{Binding VerifyCommand}" ToolTip="{Binding VerifyToolTip}" />
<Button Style="{StaticResource Button.Tool}" Content="{l:Loc Archive.Toolbar.Duplicates}" Command="{Binding FindDuplicatesCommand}"
ToolTip="{l:Loc Tooltips.Archive.Duplicates}" />
ToolTip="{Binding DuplicatesToolTip}" />
<Button Style="{StaticResource Button.Tool}" Content="{l:Loc Archive.Toolbar.Orphans}" Command="{Binding FindOrphansCommand}" ToolTip="{Binding OrphansToolTip}" />
<Button Style="{StaticResource Button.Tool}" Content="{l:Loc Archive.Toolbar.Adopt}" Command="{Binding AdoptCommand}" ToolTip="{l:Loc Tooltips.Archive.Adopt}" />
<Button Style="{StaticResource Button.Tool}" Click="OnOpenMenu" ToolTip="{l:Loc Tooltips.Archive.Adopt}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{l:Loc Archive.Toolbar.AdoptMenu}" />
<ui:Icon Glyph="{StaticResource Icon.ChevronDown}" Margin="6,0,0,0" />
</StackPanel>
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="{l:Loc Archive.Adopt.InPlace}" Command="{Binding AdoptCommand}" ToolTip="{l:Loc Tooltips.Archive.AdoptInPlace}" />
<MenuItem Header="{l:Loc Archive.Adopt.Copy}" Command="{Binding CopyFolderCommand}" ToolTip="{l:Loc Tooltips.Archive.AdoptCopy}" />
</ContextMenu>
</Button.ContextMenu>
</Button>
<Button x:Name="MaintenanceButton" Style="{StaticResource Button.Tool}" Click="OnOpenMenu" ToolTip="{l:Loc Tooltips.Archive.Maintenance}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{l:Loc Archive.Toolbar.Maintenance}" />
@@ -177,9 +201,10 @@
</StackPanel>
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="{l:Loc Archive.Maintenance.Run}" Command="{Binding MaintenanceCommand}" ToolTip="{l:Loc Tooltips.Archive.MaintenanceRun}" />
<MenuItem Header="{l:Loc Archive.Maintenance.Run}" Command="{Binding MaintenanceCommand}" ToolTip="{Binding MaintenanceRunToolTip}" />
<MenuItem Header="{l:Loc Archive.Maintenance.DryRun}" Command="{Binding MaintenanceDryRunCommand}" ToolTip="{l:Loc Tooltips.Archive.MaintenanceDryRun}" />
<MenuItem Header="{l:Loc Archive.Maintenance.Proxies}" Command="{Binding RebuildProxiesCommand}" ToolTip="{l:Loc Tooltips.Archive.MaintenanceProxies}" />
<MenuItem Header="{l:Loc Archive.Maintenance.Proxies}" Command="{Binding RebuildProxiesCommand}" ToolTip="{Binding RebuildProxiesToolTip}" />
<MenuItem Header="{l:Loc Archive.Maintenance.Backup}" Command="{Binding BackupCommand}" ToolTip="{l:Loc Tooltips.Archive.Backup}" />
<Separator />
<MenuItem Header="{l:Loc Archive.Maintenance.Relink}" Command="{Binding RelinkCommand}" ToolTip="{l:Loc Tooltips.Archive.Relink}" />
</ContextMenu>
@@ -188,21 +213,34 @@
</WrapPanel>
</DockPanel>
<!-- Overview or maintenance, and when the archive was last scanned. -->
<DockPanel Grid.Row="1" Margin="0,0,0,12" Visibility="{Binding HasArchive, Converter={StaticResource BoolToVisibility}}">
<v:SegmentedControl DockPanel.Dock="Left" SelectedIndex="{Binding ViewIndex}" AutomationProperties.Name="{l:Loc Archive.View.Name}">
<v:SegmentedItem Content="{l:Loc Archive.View.Overview}" ToolTip="{l:Loc Tooltips.Archive.Overview}" AutomationProperties.Name="{l:Loc Archive.View.Overview}" />
<v:SegmentedItem Content="{l:Loc Archive.View.Maintenance}" ToolTip="{l:Loc Tooltips.Archive.MaintenanceView}"
AutomationProperties.Name="{l:Loc Archive.View.Maintenance}" />
</v:SegmentedControl>
<TextBlock Text="{Binding LastScanText}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="14,0,0,0"
TextTrimming="CharacterEllipsis" Typography.NumeralAlignment="Tabular" ToolTip="{l:Loc Tooltips.Archive.LastScan}" />
</DockPanel>
<!-- ===================== Overview: tree, figures, charts ===================== -->
<Grid Grid.Row="1" Visibility="{Binding IsOverview, Converter={StaticResource BoolToVisibility}}">
<Grid Grid.Row="2" Visibility="{Binding IsOverview, Converter={StaticResource BoolToVisibility}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.34*" MinWidth="220" MaxWidth="320" />
<ColumnDefinition Width="0.3*" MinWidth="200" MaxWidth="320" />
<ColumnDefinition Width="14" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Style="{StaticResource Border.Panel}" Padding="6,8">
<ListBox x:Name="Tree" ItemsSource="{Binding TreeRows}" SelectionMode="Extended" SelectionChanged="OnTreeSelectionChanged"
<ListBox x:Name="Tree" ItemsSource="{Binding TreeRows}" SelectionMode="Extended" SelectionChanged="OnTreeSelectionChanged" PreviewKeyDown="OnTreeKeyDown"
AutomationProperties.Name="{l:Loc Archive.Tree.Name}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="MinHeight" Value="32" />
<Setter Property="Padding" Value="6,0" />
<Setter Property="ToolTip" Value="{Binding Detail}" />
<Setter Property="ToolTip" Value="{Binding RowToolTip}" />
<Setter Property="AutomationProperties.Name" Value="{Binding Title}" />
<Setter Property="AutomationProperties.HelpText" Value="{Binding Detail}" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
@@ -214,7 +252,8 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button x:Name="Toggle" Style="{StaticResource Button.IconSubtle}" Width="22" Height="22" MinWidth="22" ui:ButtonIcon.Glyph="{StaticResource Icon.ChevronRight}"
Command="{Binding ToggleCommand}" ToolTip="{Binding ToggleToolTip}" AutomationProperties.Name="{Binding ToggleToolTip}" Visibility="Hidden" />
Command="{Binding ToggleCommand}" ToolTip="{Binding ToggleToolTip}" AutomationProperties.Name="{Binding ToggleToolTip}" Visibility="Hidden"
Focusable="False" />
<TextBlock x:Name="Title" Grid.Column="1" Text="{Binding Title}" TextTrimming="CharacterEllipsis" VerticalAlignment="Center" />
<TextBlock x:Name="Detail" Grid.Column="2" Text="{Binding Detail}" Style="{StaticResource Text.Secondary}" VerticalAlignment="Center" Margin="8,0,0,0"
Visibility="Collapsed" Typography.NumeralAlignment="Tabular" />
@@ -250,7 +289,7 @@
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Figure tiles (Archive.html). -->
<ItemsControl ItemsSource="{Binding Tiles}" Focusable="False">
<ItemsControl ItemsSource="{Binding Tiles}" Focusable="False" Margin="0,0,-10,0">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1" />
@@ -260,8 +299,11 @@
<DataTemplate DataType="{x:Type ar:ArchiveTile}">
<Border Style="{StaticResource Border.Panel}" Padding="14,8" Margin="0,0,10,0" ToolTip="{Binding Caption}">
<StackPanel>
<TextBlock Text="{Binding Value}" FontSize="22" FontWeight="SemiBold" TextTrimming="CharacterEllipsis" Typography.NumeralAlignment="Tabular" />
<TextBlock Text="{Binding Caption}" Style="{StaticResource Text.Secondary}" TextTrimming="CharacterEllipsis" />
<!-- A narrow tile (the window at its minimum width) shrinks the figure rather than cutting it. -->
<Viewbox StretchDirection="DownOnly" HorizontalAlignment="Left" Height="32">
<TextBlock Text="{Binding Value}" FontSize="24" FontWeight="SemiBold" Typography.NumeralAlignment="Tabular" />
</Viewbox>
<TextBlock Text="{Binding Caption}" Style="{StaticResource Text.Secondary}" TextWrapping="Wrap" />
</StackPanel>
</Border>
</DataTemplate>
@@ -315,7 +357,7 @@
</Grid>
<!-- ===================== Maintenance: health, recent runs, duplicates, orphans ===================== -->
<Grid Grid.Row="1" Visibility="{Binding IsMaintenance, Converter={StaticResource BoolToVisibility}}">
<Grid Grid.Row="2" Visibility="{Binding IsMaintenance, Converter={StaticResource BoolToVisibility}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="14" />
@@ -349,6 +391,8 @@
ToolTip="{l:Loc Tooltips.Archive.History}" />
<TextBlock Text="{l:Loc Archive.Recent.Title}" Style="{StaticResource Text.PanelHeading}" />
</DockPanel>
<TextBlock DockPanel.Dock="Top" Text="{l:Loc Archive.Recent.Empty}" Foreground="{DynamicResource Brush.TextMuted}"
Visibility="{Binding HasRecent, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
<ItemsControl ItemsSource="{Binding Recent}" Focusable="False">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type ar:MaintenanceRow}">
@@ -378,13 +422,16 @@
<DockPanel>
<DockPanel DockPanel.Dock="Top" Margin="0,0,0,8">
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Row}" Margin="8,0,0,0" Content="{l:Loc Archive.Duplicates.Mark}"
Command="{Binding MarkDuplicatesCommand}" ToolTip="{l:Loc Tooltips.Archive.MarkDuplicates}" />
Command="{Binding MarkDuplicatesCommand}" ToolTip="{Binding MarkDuplicatesToolTip}" />
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Row}" Margin="0" Content="{l:Loc Archive.Find.Run}" Command="{Binding FindDuplicatesCommand}"
ToolTip="{l:Loc Tooltips.Archive.Duplicates}" />
ToolTip="{Binding DuplicatesToolTip}" Visibility="{Binding IsSearching, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Row}" Margin="0" Content="{l:Loc Archive.Find.Cancel}" Command="{Binding CancelSearchCommand}"
ToolTip="{l:Loc Tooltips.Archive.CancelSearch}" Visibility="{Binding IsSearching, Converter={StaticResource BoolToVisibility}}" />
<TextBlock Text="{l:Loc Archive.Duplicates.Title}" Style="{StaticResource Text.PanelHeading}" />
<TextBlock Text="{Binding DuplicatesText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0" VerticalAlignment="Center" />
</DockPanel>
<ListBox ItemsSource="{Binding Duplicates}" ItemContainerStyle="{StaticResource ListBoxItem.PlainRow}" AutomationProperties.Name="{l:Loc Archive.Duplicates.Title}">
<ListBox ItemsSource="{Binding Duplicates}" ItemContainerStyle="{StaticResource ListBoxItem.Duplicate}" AutomationProperties.Name="{l:Loc Archive.Duplicates.Title}"
KeyboardNavigation.TabNavigation="Continue">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type ar:DuplicateRowViewModel}">
<DockPanel Height="44">
@@ -409,11 +456,14 @@
<DockPanel>
<DockPanel DockPanel.Dock="Top" Margin="0,0,0,8">
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Row}" Margin="0" Content="{l:Loc Archive.Find.Run}" Command="{Binding FindOrphansCommand}"
ToolTip="{Binding OrphansToolTip}" />
ToolTip="{Binding OrphansToolTip}" Visibility="{Binding IsSearching, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Row}" Margin="0" Content="{l:Loc Archive.Find.Cancel}" Command="{Binding CancelSearchCommand}"
ToolTip="{l:Loc Tooltips.Archive.CancelSearch}" Visibility="{Binding IsSearching, Converter={StaticResource BoolToVisibility}}" />
<TextBlock Text="{l:Loc Archive.Orphans.Title}" Style="{StaticResource Text.PanelHeading}" />
<TextBlock Text="{Binding OrphansText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0" VerticalAlignment="Center" />
</DockPanel>
<ListBox ItemsSource="{Binding Orphans}" ItemContainerStyle="{StaticResource ListBoxItem.PlainRow}" AutomationProperties.Name="{l:Loc Archive.Orphans.Title}">
<ListBox ItemsSource="{Binding Orphans}" ItemContainerStyle="{StaticResource ListBoxItem.Duplicate}" AutomationProperties.Name="{l:Loc Archive.Orphans.Title}"
KeyboardNavigation.TabNavigation="Continue">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type ar:OrphanRowViewModel}">
<DockPanel Height="44">
@@ -431,37 +481,53 @@
</Grid>
</Grid>
<!-- ===================== Mass operations on the selected set ===================== -->
<Border Grid.Row="2" Style="{StaticResource Border.Panel}" Padding="14,8,6,0" Margin="0,14,0,0" MinHeight="48"
<!-- ===================== Mass operations on the selected, filtered set ===================== -->
<Border Grid.Row="3" Style="{StaticResource Border.Panel}" Padding="14,8,6,0" Margin="0,14,0,0" MinHeight="48"
Visibility="{Binding IsOverview, Converter={StaticResource BoolToVisibility}}">
<WrapPanel VerticalAlignment="Center">
<TextBlock Text="{l:Loc Archive.Set.Label}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" Margin="0,0,10,8" />
<Border BorderBrush="{DynamicResource Brush.Accent}" BorderThickness="1" CornerRadius="{StaticResource Radius.Control}" Padding="12,0" Height="30"
Margin="0,0,8,8" ToolTip="{l:Loc Tooltips.Archive.Set}">
<TextBlock Text="{Binding SetText}" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" MaxWidth="220" TextTrimming="CharacterEllipsis" />
</Border>
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" BorderBrush="{DynamicResource Brush.Accent}" Click="OnOpenMenu" ToolTip="{l:Loc Tooltips.Archive.Set}"
AutomationProperties.Name="{l:Loc Archive.Set.Filter}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding SetText}" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" MaxWidth="260" TextTrimming="CharacterEllipsis" />
<ui:Icon Glyph="{StaticResource Icon.ChevronDown}" Margin="6,0,0,0" />
</StackPanel>
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="{l:Loc Library.Filter.Camera}" ItemsSource="{Binding CameraChoices}" ItemContainerStyle="{StaticResource MenuItem.Choice}"
ToolTip="{l:Loc Tooltips.Archive.FilterCamera}" />
<MenuItem Header="{l:Loc Library.Filter.Status}" ItemsSource="{Binding StatusChoices}" ItemContainerStyle="{StaticResource MenuItem.Choice}"
ToolTip="{l:Loc Tooltips.Archive.FilterStatus}" />
<MenuItem Header="{l:Loc Library.Filter.Tags}" ItemsSource="{Binding TagChoices}" ItemContainerStyle="{StaticResource MenuItem.Choice}"
ToolTip="{l:Loc Tooltips.Archive.FilterTag}" />
<Separator />
<MenuItem Header="{l:Loc Archive.Set.ClearFilter}" Command="{Binding ClearFilterCommand}" ToolTip="{l:Loc Tooltips.Archive.ClearFilter}" />
</ContextMenu>
</Button.ContextMenu>
</Button>
<Border Width="1" Height="22" Background="{DynamicResource Brush.Stroke}" Margin="4,0,12,8" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Analyse}" Command="{Binding AnalyseSetCommand}" ToolTip="{l:Loc Tooltips.Archive.SetAnalyse}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Proxies}" Command="{Binding ProxiesSetCommand}" ToolTip="{l:Loc Tooltips.Archive.SetProxies}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Analyse}" Command="{Binding AnalyseSetCommand}" ToolTip="{Binding AnalyseSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Proxies}" Command="{Binding ProxiesSetCommand}" ToolTip="{Binding ProxiesSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Thumbnails}" Command="{Binding ThumbnailsSetCommand}"
ToolTip="{l:Loc Tooltips.Archive.SetThumbnails}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Verify}" Command="{Binding VerifySetCommand}" ToolTip="{l:Loc Tooltips.Archive.SetVerify}" />
ToolTip="{Binding ThumbnailsSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Verify}" Command="{Binding VerifySetCommand}" ToolTip="{Binding VerifySetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Rename}" Command="{Binding RenameSetCommand}" ToolTip="{Binding RenameSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Move}" Command="{Binding MoveSetCommand}" ToolTip="{Binding MoveSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Retag}" Command="{Binding RetagSetCommand}" ToolTip="{Binding RetagSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Export}" Command="{Binding ExportSetCommand}" ToolTip="{l:Loc Tooltips.Archive.SetExport}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Export}" Command="{Binding ExportSetCommand}" ToolTip="{Binding ExportSetToolTip}" />
</WrapPanel>
</Border>
<ui:EmptyState Grid.Row="1" Message="{l:Loc Archive.Empty}" Visibility="{Binding IsEmpty, Converter={StaticResource BoolToVisibility}}">
<ui:EmptyState Grid.Row="2" Message="{l:Loc Archive.Empty}" Visibility="{Binding IsEmpty, Converter={StaticResource BoolToVisibility}}">
<Button Style="{StaticResource Button.Primary}" Content="{l:Loc Archive.Toolbar.Adopt}" Command="{Binding AdoptCommand}" ToolTip="{l:Loc Tooltips.Archive.Adopt}" />
</ui:EmptyState>
</Grid>
<!-- In-window dialogs (rebuild, rename, retag) over a scrim. -->
<Grid Visibility="{Binding IsDialogOpen, Converter={StaticResource BoolToVisibility}}">
<!-- In-window dialogs (rebuild, rename, retag) over a scrim; the keyboard stays inside the dialog. -->
<Grid Visibility="{Binding IsDialogOpen, Converter={StaticResource BoolToVisibility}}" KeyboardNavigation.TabNavigation="Cycle"
KeyboardNavigation.ControlTabNavigation="Cycle" KeyboardNavigation.DirectionalNavigation="Contained">
<Border Background="{DynamicResource Brush.Scrim}" />
<ContentPresenter Content="{Binding Dialog}" Margin="20" />
<ContentPresenter x:Name="DialogHost" Content="{Binding Dialog}" Margin="20" />
</Grid>
</Grid>
</UserControl>
+80 -3
View File
@@ -1,15 +1,31 @@
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Threading;
using Titano.App.Archiving;
namespace Titano.App.Sections;
public partial class ArchiveView : UserControl
{
public ArchiveView() => InitializeComponent();
private bool _restoring;
private string? _focusKey;
/// <summary>"Maintenance ▾" opens its menu under itself.</summary>
public ArchiveView()
{
InitializeComponent();
DataContextChanged += OnDataContextChanged;
Tree.GotKeyboardFocus += (_, e) =>
{
if (e.NewFocus is ListBoxItem { DataContext: ArchiveTreeRowViewModel row }) _focusKey = row.Node.Key;
};
}
private ArchiveViewModel? Model => DataContext as ArchiveViewModel;
/// <summary>"Adopt folder ▾", "Maintenance ▾" and the set filter open their menu under themselves.</summary>
private void OnOpenMenu(object sender, RoutedEventArgs e)
{
if (sender is not Button { ContextMenu: { } menu } button) return;
@@ -19,9 +35,70 @@ public partial class ArchiveView : UserControl
menu.IsOpen = true;
}
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (e.OldValue is ArchiveViewModel old)
{
old.RowsRebuilt -= RestoreSelection;
old.PropertyChanged -= OnModelChanged;
}
if (e.NewValue is ArchiveViewModel model)
{
model.RowsRebuilt += RestoreSelection;
model.PropertyChanged += OnModelChanged;
}
}
/// <summary>The selected tree rows are the set the mass operations act on.</summary>
private void OnTreeSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (DataContext is ArchiveViewModel model) model.SetSelection(Tree.SelectedItems.OfType<ArchiveTreeRowViewModel>());
if (!_restoring) Model?.SetSelection(Tree.SelectedItems.OfType<ArchiveTreeRowViewModel>());
}
/// <summary>The rows were rebuilt (a reload, a year opened or closed): the list shows the same selection and keeps the keyboard where it was.</summary>
private void RestoreSelection()
{
if (Model is not { } model) return;
// The rebuild removed the focused row's container; the keyboard goes back to the row with the same key.
var refocus = Tree.IsKeyboardFocusWithin || Keyboard.FocusedElement is null ? _focusKey : null;
_restoring = true;
try
{
Tree.SelectedItems.Clear();
foreach (var row in model.TreeRows.Where(model.IsSelectedRow)) Tree.SelectedItems.Add(row);
}
finally
{
_restoring = false;
}
if (refocus is null || model.TreeRows.FirstOrDefault(r => r.Node.Key == refocus) is not { } again) return;
Dispatcher.BeginInvoke(DispatcherPriority.Input, () =>
{
Tree.ScrollIntoView(again);
(Tree.ItemContainerGenerator.ContainerFromItem(again) as ListBoxItem)?.Focus();
});
}
/// <summary>On a year: Right opens it, Left closes it, Enter toggles it.</summary>
private void OnTreeKeyDown(object sender, KeyEventArgs e)
{
if (Model is not { } model || Keyboard.FocusedElement is not ListBoxItem { DataContext: ArchiveTreeRowViewModel row } || !row.HasChildren || row.IsArchive) return;
var toggle = e.Key switch
{
Key.Right => !row.IsExpanded,
Key.Left => row.IsExpanded,
Key.Enter => true,
_ => false,
};
if (!toggle) return;
model.Toggle(row);
e.Handled = true;
}
/// <summary>A dialog that opens takes the keyboard: its first field or button.</summary>
private void OnModelChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName != nameof(ArchiveViewModel.Dialog) || Model?.Dialog is null || !IsVisible) return;
Dispatcher.BeginInvoke(DispatcherPriority.Input, () => DialogHost.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)));
}
}
+285 -53
View File
@@ -1,9 +1,11 @@
using System.Collections.ObjectModel;
using System.IO;
using System.Windows.Input;
using System.Windows.Threading;
using Titano.App.Archiving;
using Titano.App.Infrastructure;
using Titano.App.Jobs;
using Titano.App.Library;
using Titano.App.Shell;
using Titano.Core.Archiving;
using Titano.Core.Diagnostics;
@@ -22,16 +24,24 @@ namespace Titano.App.Sections;
/// <summary>
/// Archive manager (BRIEF §12.5, Archive.html): the archive's tree (years, sequences) with its availability, its
/// figures and charts, mass operations on the selected set (analyse, proxies, thumbnails, verify, rename, move,
/// retag, CSV), and the operations on the whole archive as jobs (scan, rebuild with its dialog, verify,
/// maintenance), plus the maintenance view: index health, duplicates and orphans with safe fixes, recent runs.
/// figures and charts, mass operations on the selected and filtered set (analyse, proxies, thumbnails, verify, rename,
/// move, retag, CSV), and the operations on the whole archive as jobs (scan, rebuild with its dialog, verify,
/// maintenance), plus the maintenance view: index health, duplicates and orphans with safe fixes, recent runs. The
/// tree selection is only ever changed by the user: reloads and expanding keep it.
/// </summary>
public sealed class ArchiveViewModel : SectionViewModel
{
private const int RecentCount = 6;
private const int PageSize = 1000;
private static readonly TimeSpan ReloadDelay = TimeSpan.FromSeconds(2);
private readonly HashSet<ArchiveTreeNode> _selection = [];
/// <summary>Keys of the selected tree nodes (stable across reloads).</summary>
private readonly HashSet<string> _selection = new(StringComparer.Ordinal);
private readonly DispatcherTimer _reloadDelay;
private HashSet<Guid> _sequenceIds = [];
private ArchiveSetFilter _filter = new();
private bool _rebuildingRows;
private CancellationTokenSource? _search;
private IReadOnlyList<Core.Model.Archive> _archives = [];
private Core.Model.Archive? _archive;
private ArchiveAvailability _availability = ArchiveAvailability.Offline;
@@ -59,13 +69,22 @@ public sealed class ArchiveViewModel : SectionViewModel
: base(SectionKey.Archive, "Icon.Archive")
{
Shell = shell;
_reloadDelay = new DispatcherTimer { Interval = ReloadDelay };
_reloadDelay.Tick += (_, _) =>
{
_reloadDelay.Stop();
_ = LoadAsync();
};
ScanCommand = new AsyncRelayCommand(() => QueueAsync(a => ArchiveJobs.Scan(a)), IsOnline);
RebuildCommand = new AsyncRelayCommand(() => OpenRebuildDialogAsync(), () => _archive is not null);
VerifyCommand = new AsyncRelayCommand(() => QueueAsync(a => ArchiveJobs.Verify(a)), IsOnline);
AdoptCommand = new AsyncRelayCommand(AdoptAsync);
CopyFolderCommand = new RelayCommand(CopyFolder, () => _archive is not null);
BackupCommand = new AsyncRelayCommand(BackupAsync, () => Services.Database is not null);
MaintenanceCommand = new AsyncRelayCommand(() => QueueAsync(a => ArchiveJobs.Maintenance(a)), IsOnline);
MaintenanceDryRunCommand = new AsyncRelayCommand(() => QueueAsync(a => ArchiveJobs.Maintenance(a, dryRun: true)), () => _archive is not null);
RebuildProxiesCommand = new AsyncRelayCommand(() => QueueSetAsync(ids => ArchiveJobs.Proxies(ids, _archive!.Name, force: true), All()), IsOnline);
ClearFilterCommand = new RelayCommand(() => Filter = new ArchiveSetFilter(), () => !_filter.IsEmpty);
RelinkCommand = new AsyncRelayCommand(RelinkAsync);
HistoryCommand = new RelayCommand(() => Shell.Navigate(SectionKey.Jobs));
@@ -73,13 +92,14 @@ public sealed class ArchiveViewModel : SectionViewModel
ProxiesSetCommand = new AsyncRelayCommand(() => QueueSetAsync(ids => ArchiveJobs.Proxies(ids, SetLabel()), Set()), HasSet);
ThumbnailsSetCommand = new AsyncRelayCommand(() => QueueSetAsync(ids => ArchiveJobs.Thumbnails(ids, SetLabel()), Set()), HasSet);
VerifySetCommand = new AsyncRelayCommand(() => QueueSetAsync(ids => ArchiveJobs.Verify(_archive!, ids), Set()), HasSet);
RenameSetCommand = new RelayCommand(() => OpenRename(RenameMode.Titles), () => HasSet() && IsOnline());
MoveSetCommand = new RelayCommand(() => OpenRename(RenameMode.Folders), () => HasSet() && IsOnline());
RenameSetCommand = new AsyncRelayCommand(() => OpenRenameDialogAsync(RenameMode.Titles), () => HasSet() && IsOnline());
MoveSetCommand = new AsyncRelayCommand(() => OpenRenameDialogAsync(RenameMode.Folders), () => HasSet() && IsOnline());
RetagSetCommand = new RelayCommand(OpenRetag, () => HasSet() && IsOnline());
ExportSetCommand = new AsyncRelayCommand(ExportAsync, HasSet);
FindDuplicatesCommand = new AsyncRelayCommand(FindDuplicatesAsync, () => _archive is not null && !_findingDuplicates);
FindOrphansCommand = new AsyncRelayCommand(FindOrphansAsync, () => IsOnline() && !_findingOrphans);
FindDuplicatesCommand = new AsyncRelayCommand(FindDuplicatesAsync, () => _archive is not null && _search is null);
FindOrphansCommand = new AsyncRelayCommand(FindOrphansAsync, () => IsOnline() && _search is null);
CancelSearchCommand = new RelayCommand(() => _search?.Cancel(), () => _search is not null);
MarkDuplicatesCommand = new AsyncRelayCommand(() => QueueAsync(a => ArchiveJobs.Maintenance(a)), IsOnline);
}
@@ -128,15 +148,29 @@ public sealed class ArchiveViewModel : SectionViewModel
public string ScanToolTip => WhenOnline("Tooltips.Archive.Scan");
public string VerifyToolTip => WhenOnline("Tooltips.Archive.Verify");
public string OrphansToolTip => WhenOnline("Tooltips.Archive.Orphans");
public string RenameSetToolTip => WhenOnline("Tooltips.Archive.SetRename");
public string MoveSetToolTip => WhenOnline("Tooltips.Archive.SetMove");
public string RetagSetToolTip => WhenOnline("Tooltips.Archive.SetRetag");
public string MaintenanceRunToolTip => WhenOnline("Tooltips.Archive.MaintenanceRun");
public string RebuildProxiesToolTip => WhenOnline("Tooltips.Archive.MaintenanceProxies");
public string MarkDuplicatesToolTip => WhenOnline("Tooltips.Archive.MarkDuplicates");
public string DuplicatesToolTip => _search is not null ? Loc.L("Archive.Blocked.Searching") : Loc.L("Tooltips.Archive.Duplicates");
public string OrphansToolTip => _search is not null ? Loc.L("Archive.Blocked.Searching") : WhenOnline("Tooltips.Archive.Orphans");
public string AnalyseSetToolTip => WhenSet("Tooltips.Archive.SetAnalyse");
public string ProxiesSetToolTip => WhenSet("Tooltips.Archive.SetProxies");
public string ThumbnailsSetToolTip => WhenSet("Tooltips.Archive.SetThumbnails");
public string VerifySetToolTip => WhenSet("Tooltips.Archive.SetVerify");
public string ExportSetToolTip => WhenSet("Tooltips.Archive.SetExport");
public string RenameSetToolTip => WhenSet("Tooltips.Archive.SetRename", needsOnline: true);
public string MoveSetToolTip => WhenSet("Tooltips.Archive.SetMove", needsOnline: true);
public string RetagSetToolTip => WhenSet("Tooltips.Archive.SetRetag", needsOnline: true);
public ICommand ScanCommand { get; }
public ICommand RebuildCommand { get; }
public ICommand VerifyCommand { get; }
public ICommand AdoptCommand { get; }
/// <summary>"Adopt folder ▾ › Copy into the layout": the Import screen copies the folder into the archive with its templates.</summary>
public ICommand CopyFolderCommand { get; }
public ICommand BackupCommand { get; }
public ICommand MaintenanceCommand { get; }
public ICommand MaintenanceDryRunCommand { get; }
public ICommand RebuildProxiesCommand { get; }
@@ -157,17 +191,45 @@ public sealed class ArchiveViewModel : SectionViewModel
/// <summary>Photos per month in the culture's digits.</summary>
public Func<double, string> CountFormatter { get; } = v => Formatting.Count((long)v);
/// <summary>"412 sequences · all", "36 sequences · 2025", "Harbour sunset".</summary>
/// <summary>"412 sequences · all", "36 sequences", "Harbour sunset", each followed by the filter ("· Canon EOS R5").</summary>
public string SetText
{
get
{
var set = Set();
if (_selection.Count == 0 || _selection.Any(n => n.Kind == TreeNodeKind.Archive)) return Loc.Plural("Archive.Set.All", set.Count);
return set.Count == 1 ? set[0].DisplayTitle : Loc.Plural("Shell.Status.Sequences", set.Count);
var selected = SelectedNodes().ToList();
var text = selected.Count == 0 || selected.Any(n => n.Kind == TreeNodeKind.Archive)
? Loc.Plural("Archive.Set.All", set.Count)
: set.Count == 1 ? set[0].DisplayTitle : Loc.Plural("Shell.Status.Sequences", set.Count);
return _filter.IsEmpty ? text : text + " · " + _filter.Describe();
}
}
/// <summary>Camera, status and tag on top of the tree selection.</summary>
public ArchiveSetFilter Filter
{
get => _filter;
private set
{
if (!Set(ref _filter, value)) return;
OnSetChanged();
}
}
public IReadOnlyList<FilterChoice> CameraChoices => Choices(
(_tree?.Root.Sequences() ?? []).Select(ArchiveSetFilter.CameraOf).Distinct(StringComparer.Ordinal).Order(StringComparer.CurrentCultureIgnoreCase),
c => c, c => _filter.Camera == c, c => _filter with { Camera = c });
public IReadOnlyList<FilterChoice> StatusChoices => Choices(
Enum.GetValues<StatusFilter>().Where(f => f != StatusFilter.Any), ArchiveSetFilter.StatusLabel, f => _filter.Status == f,
f => _filter with { Status = f });
public IReadOnlyList<FilterChoice> TagChoices => Choices(
(_tree?.Root.Sequences() ?? []).SelectMany(q => q.Tags).Distinct(StringComparer.OrdinalIgnoreCase).Order(StringComparer.CurrentCultureIgnoreCase),
t => t, t => string.Equals(_filter.Tag, t, StringComparison.OrdinalIgnoreCase), t => _filter with { Tag = t });
public ICommand ClearFilterCommand { get; }
public ICommand AnalyseSetCommand { get; }
public ICommand ProxiesSetCommand { get; }
public ICommand ThumbnailsSetCommand { get; }
@@ -177,19 +239,37 @@ public sealed class ArchiveViewModel : SectionViewModel
public ICommand RetagSetCommand { get; }
public ICommand ExportSetCommand { get; }
/// <summary>The view reports the selected tree rows.</summary>
/// <summary>The view reports the rows the user selected; the list's own clearing while rows are rebuilt is not a choice.</summary>
public void SetSelection(IEnumerable<ArchiveTreeRowViewModel> rows)
{
if (_rebuildingRows) return;
_selection.Clear();
foreach (var row in rows) _selection.Add(row.Node);
OnPropertyChanged(nameof(SetText));
CommandManager.InvalidateRequerySuggested();
foreach (var row in rows) _selection.Add(row.Node.Key);
OnSetChanged();
}
/// <summary>Whether a visible row is part of the selection (the view restores the list's selection after a rebuild).</summary>
public bool IsSelectedRow(ArchiveTreeRowViewModel row) => _selection.Contains(row.Node.Key);
/// <summary>Raised after the rows were rebuilt; the view selects the rows of <see cref="IsSelectedRow"/> again.</summary>
public event Action? RowsRebuilt;
/// <summary>Expands or collapses a year (Right/Left/Enter on its row, or its arrow).</summary>
public void Toggle(ArchiveTreeRowViewModel row) => Toggle(row.Node);
// ---------------- Maintenance view ----------------
public IReadOnlyList<HealthLineViewModel> Health { get => _health; private set => Set(ref _health, value); }
public IReadOnlyList<MaintenanceRow> Recent { get => _recent; private set => Set(ref _recent, value); }
public IReadOnlyList<MaintenanceRow> Recent
{
get => _recent;
private set
{
if (Set(ref _recent, value)) OnPropertyChanged(nameof(HasRecent));
}
}
public bool HasRecent => _recent.Count > 0;
public IReadOnlyList<DuplicateRowViewModel>? Duplicates
{
@@ -209,6 +289,9 @@ public sealed class ArchiveViewModel : SectionViewModel
}
}
/// <summary>A duplicates or orphans search runs; it can be cancelled.</summary>
public bool IsSearching => _search is not null;
/// <summary>"3 groups", "None found", or empty before the first search.</summary>
public string DuplicatesText => _findingDuplicates ? Loc.L("Archive.Find.Searching")
: _duplicates is null ? string.Empty
@@ -222,6 +305,7 @@ public sealed class ArchiveViewModel : SectionViewModel
public ICommand FindDuplicatesCommand { get; }
public ICommand FindOrphansCommand { get; }
public ICommand CancelSearchCommand { get; }
public ICommand MarkDuplicatesCommand { get; }
// ---------------- Dialogs ----------------
@@ -232,12 +316,17 @@ public sealed class ArchiveViewModel : SectionViewModel
get => _dialog;
private set
{
if (Set(ref _dialog, value)) OnPropertyChanged(nameof(IsDialogOpen));
if (!Set(ref _dialog, value)) return;
OnPropertyChanged(nameof(IsDialogOpen));
OnPropertyChanged(nameof(IsContentEnabled));
}
}
public bool IsDialogOpen => _dialog is not null;
/// <summary>The screen behind an open dialog takes neither clicks nor keyboard focus.</summary>
public bool IsContentEnabled => _dialog is null;
public bool IsEmpty => _loaded && _archive is null;
// ---------------- Lifecycle ----------------
@@ -292,7 +381,7 @@ public sealed class ArchiveViewModel : SectionViewModel
await engine.EnqueueAsync(request);
Queued(request.Kind, archive.Name);
}, CloseDialog);
Dialog = dialog;
OpenDialog(dialog);
await dialog.CountAsync();
return dialog;
}
@@ -306,6 +395,8 @@ public sealed class ArchiveViewModel : SectionViewModel
public override void Dispose()
{
_reloadDelay.Stop();
_search?.Cancel();
if (_jobEvents && Services.Jobs is { } jobs) jobs.JobChanged -= OnJobChanged;
_dialog?.Dispose();
base.Dispose();
@@ -349,22 +440,41 @@ public sealed class ArchiveViewModel : SectionViewModel
private static IReadOnlyList<ChartItem> Bars(IReadOnlyList<BarValue> values) =>
[.. values.Select(v => new ChartItem(v.Label, v.Value, v.ValueText, v.ToolTip))];
/// <summary>A reloaded tree keeps the open years and the selection (nodes that still exist).</summary>
private void ShowTree(ArchiveTree tree)
{
var expanded = _tree?.ExpandedKeys();
var expanded = _tree?.Root.Key == tree.Root.Key ? _tree.ExpandedKeys() : null;
if (expanded is not null) tree.Expand(expanded);
else if (tree.Root.Children.Count > 0) tree.Root.Children[0].IsExpanded = true;
else
{
_selection.Clear();
if (tree.Root.Children.Count > 0) tree.Root.Children[0].IsExpanded = true;
}
_tree = tree;
_selection.Clear();
_sequenceIds = [.. tree.Root.Sequences().Select(q => q.Id)];
RebuildRows();
}
/// <summary>
/// The visible rows again (after a reload or a toggle). Selected rows that are now hidden — the user collapsed their
/// year — leave the selection, so the set is always what the list shows selected.
/// </summary>
private void RebuildRows()
{
TreeRows.Clear();
if (_tree is null) return;
foreach (var node in _tree.Visible()) TreeRows.Add(new ArchiveTreeRowViewModel(node, _tree.Availability, Toggle));
OnPropertyChanged(nameof(SetText));
_rebuildingRows = true;
try
{
TreeRows.Clear();
if (_tree is null) return;
foreach (var node in _tree.Visible()) TreeRows.Add(new ArchiveTreeRowViewModel(node, _tree.Availability, Toggle));
_selection.IntersectWith(TreeRows.Select(r => r.Node.Key));
}
finally
{
_rebuildingRows = false;
}
RowsRebuilt?.Invoke();
OnSetChanged();
}
private void Toggle(ArchiveTreeNode node)
@@ -374,6 +484,36 @@ public sealed class ArchiveViewModel : SectionViewModel
RebuildRows();
}
/// <summary>The set changed (selection, filter or tree): its text, the filter menus and the mass commands follow.</summary>
private void OnSetChanged()
{
OnPropertyChanged(nameof(SetText));
OnPropertyChanged(nameof(CameraChoices));
OnPropertyChanged(nameof(StatusChoices));
OnPropertyChanged(nameof(TagChoices));
OnPropertyChanged(nameof(AnalyseSetToolTip));
OnPropertyChanged(nameof(ProxiesSetToolTip));
OnPropertyChanged(nameof(ThumbnailsSetToolTip));
OnPropertyChanged(nameof(VerifySetToolTip));
OnPropertyChanged(nameof(ExportSetToolTip));
OnPropertyChanged(nameof(RenameSetToolTip));
OnPropertyChanged(nameof(MoveSetToolTip));
OnPropertyChanged(nameof(RetagSetToolTip));
CommandManager.InvalidateRequerySuggested();
}
private IEnumerable<ArchiveTreeNode> SelectedNodes() => TreeRows.Where(r => _selection.Contains(r.Node.Key)).Select(r => r.Node);
/// <summary>One filter menu: each value checked when chosen; choosing it again clears it.</summary>
private IReadOnlyList<FilterChoice> Choices<T>(IEnumerable<T> values, Func<T, string> label, Func<T, bool> isChosen, Func<T?, ArchiveSetFilter> choose) =>
[
.. values.Select(v =>
{
var chosen = isChosen(v);
return new FilterChoice(label(v), chosen, new RelayCommand(() => Filter = choose(chosen ? default : v)));
}),
];
private async Task LoadRecentAsync(TitanoDatabase db, Core.Model.Archive archive)
{
var jobs = new List<Job>();
@@ -394,16 +534,25 @@ public sealed class ArchiveViewModel : SectionViewModel
_jobEvents = true;
}
/// <summary>A finished archive job changes the figures: read them again.</summary>
/// <summary>
/// A finished job on this archive or its sequences changes the figures: read them again once the jobs settle (a
/// burst of analyses after an import reloads once). Jobs of other archives are none of this screen's business.
/// </summary>
private void OnJobChanged(Job job)
{
if (job.State is not (JobState.Done or JobState.Failed) || _archive is null) return;
if (job.State is not (JobState.Done or JobState.Failed)) return;
if (job.Kind is not (JobKind.Scan or JobKind.Rebuild or JobKind.Verify or JobKind.Maintenance or JobKind.Import or JobKind.Proxies or JobKind.Thumbs
or JobKind.LightAnalyse or JobKind.DeepAnalyse)) return;
System.Windows.Application.Current?.Dispatcher.BeginInvoke(() =>
{
if (IsSelected) _ = LoadAsync();
else _loaded = false;
if (_archive is not { } archive || !job.TargetIds.Any(id => id == archive.Id || _sequenceIds.Contains(id))) return;
if (!IsSelected)
{
_loaded = false;
return;
}
_reloadDelay.Stop();
_reloadDelay.Start();
});
}
@@ -416,7 +565,14 @@ public sealed class ArchiveViewModel : SectionViewModel
private bool HasSet() => _archive is not null && _tree is not null && Set().Count > 0;
private IReadOnlyList<Sequence> Set() => _tree is null ? [] : ArchiveTree.SetOf(_tree, _selection);
/// <summary>A mass command's tooltip, or why it is disabled (an empty set; for writes, an archive that is not online).</summary>
private string WhenSet(string key, bool needsOnline = false) =>
_tree is not null && !HasSet() ? Loc.L("Archive.Blocked.EmptySet")
: needsOnline ? WhenOnline(key)
: Loc.L(key);
/// <summary>The set the mass operations act on: the selected rows' sequences (all when nothing is selected), filtered.</summary>
private IReadOnlyList<Sequence> Set() => _tree is null ? [] : [.. ArchiveTree.SetOf(_tree, SelectedNodes()).Where(_filter.Matches)];
private IReadOnlyList<Sequence> All() => _tree is null ? [] : ArchiveTree.SetOf(_tree, []);
@@ -438,12 +594,20 @@ public sealed class ArchiveViewModel : SectionViewModel
Queued(request.Kind, request.Label ?? SetLabel());
}
/// <summary>Health fixes act on the sequences that miss a status (never verified, no proxies).</summary>
/// <summary>Health fixes act on every sequence that misses a status (never verified, no proxies), page by page.</summary>
private async Task QueueStatusAsync(SequenceStatus missing, Func<IReadOnlyList<Guid>, ArchiveJobRequest> build)
{
if (Services.Database is not { } db || _archive is not { } archive) return;
var page = await db.Sequences.ListAsync(new SequenceQuery { ArchiveId = archive.Id, WithoutStatus = missing, Limit = PageSize });
await QueueSetAsync(build, page.Items);
var all = new List<Sequence>();
string? cursor = null;
do
{
var page = await db.Sequences.ListAsync(new SequenceQuery { ArchiveId = archive.Id, WithoutStatus = missing, Limit = PageSize, Cursor = cursor });
all.AddRange(page.Items);
cursor = page.NextCursor;
}
while (cursor is not null);
await QueueSetAsync(build, all);
}
private static string CountLabel(IReadOnlyList<Guid> ids) => Loc.Plural("Shell.Status.Sequences", ids.Count);
@@ -452,18 +616,25 @@ public sealed class ArchiveViewModel : SectionViewModel
Shell.Notify(Loc.L("Library.Queued", JobText.Kind(kind), label), actionText: Loc.L("Shell.Nav.Jobs"), actionToolTip: Loc.L("Tooltips.Nav.Jobs"),
action: () => Shell.Navigate(SectionKey.Jobs));
private void OpenRename(RenameMode mode)
/// <summary>Opens Rename or Move on the set and waits for its dry run.</summary>
public async Task OpenRenameDialogAsync(RenameMode mode)
{
if (Services.Archives is not { } archives || _archive is not { } archive) return;
var dialog = new RenameDialogViewModel(mode, archives, archive, Set(), Applied, CloseDialog);
Dialog = dialog;
_ = dialog.PlanAsync();
OpenDialog(dialog);
await dialog.PlanAsync();
}
private void OpenRetag()
{
if (Services.Archives is not { } archives) return;
Dialog = new RetagDialogViewModel(archives, Set(), Applied, CloseDialog);
OpenDialog(new RetagDialogViewModel(archives, Set(), Applied, CloseDialog));
}
private void OpenDialog(ArchiveDialogViewModel dialog)
{
_dialog?.Dispose();
Dialog = dialog;
}
private async Task Applied(int changed)
@@ -473,9 +644,11 @@ public sealed class ArchiveViewModel : SectionViewModel
await Shell.Library.RefreshAsync();
}
private void CloseDialog()
/// <summary>Closes <paramref name="dialog"/> if it is still the open one (an apply that finishes late closes nothing else).</summary>
private void CloseDialog(ArchiveDialogViewModel dialog)
{
_dialog?.Dispose();
if (!ReferenceEquals(_dialog, dialog)) return;
dialog.Dispose();
Dialog = null;
}
@@ -490,6 +663,32 @@ public sealed class ArchiveViewModel : SectionViewModel
}
}
/// <summary>Copies a folder tree into the archive's layout: the Import screen plans it with the archive's templates.</summary>
private void CopyFolder()
{
var folder = Services.Dialogs.PickFolder(Loc.L("Archive.Copy.Title"));
if (folder is null) return;
Shell.Navigate(SectionKey.Import);
_ = Shell.Import.ImportFolderAsync(folder);
}
/// <summary>A consistent copy of the index next to the data folder (the same backup as Settings › Advanced).</summary>
private async Task BackupAsync()
{
if (Services.Database is not { } db) return;
try
{
var path = await db.BackupAsync(Services.Environment.BackupDirectory);
Shell.Notify(Loc.L("Settings.Advanced.BackupDone"), Path.GetFileName(path), Loc.L("Library.Export.Show"), Loc.L("Tooltips.Library.ShowExport"),
() => ShellActions.Reveal(path));
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or DatabaseException or NotSupportedException)
{
Log.Warning("archive", "Database backup failed", ex);
Shell.Notify(Loc.L("Archive.Backup.Failed"), ex.Message);
}
}
/// <summary>A moved archive keeps its id: opening it at the new root relinks every sequence (BRIEF §12.5 Move archive).</summary>
private async Task RelinkAsync()
{
@@ -525,16 +724,21 @@ public sealed class ArchiveViewModel : SectionViewModel
() => ShellActions.Reveal(path));
}
/// <summary>Duplicates by hash across the archive (a read of the index); cancellable.</summary>
private async Task FindDuplicatesAsync()
{
if (Services.Archives is not { } archives || Services.Database is not { } db || _archive is not { } archive) return;
ViewIndex = 1;
_findingDuplicates = true;
OnPropertyChanged(nameof(DuplicatesText));
var search = StartSearch();
try
{
var groups = await Task.Run(() => archives.FindDuplicatesAsync(archive.Id));
Duplicates = DuplicateRows(groups, await db.Sequences.ListLocationsAsync(archive.Id));
var groups = await Task.Run(() => archives.FindDuplicatesAsync(archive.Id, search.Token), search.Token);
Duplicates = DuplicateRows(groups, await db.Sequences.ListLocationsAsync(archive.Id, search.Token));
Log.Info("archive", $"Duplicates search in {archive.RootPath}: {groups.Count} group(s)");
}
catch (OperationCanceledException) when (search.IsCancellationRequested)
{
}
catch (DatabaseException ex)
{
@@ -543,21 +747,26 @@ public sealed class ArchiveViewModel : SectionViewModel
finally
{
_findingDuplicates = false;
OnPropertyChanged(nameof(DuplicatesText));
CommandManager.InvalidateRequerySuggested();
EndSearch(search);
}
}
/// <summary>Orphans: every sequence folder against its sidecar and the index (a walk of the archive); cancellable.</summary>
private async Task FindOrphansAsync()
{
if (Services.Archives is not { } archives || Services.Database is not { } db || _archive is not { } archive) return;
ViewIndex = 1;
_findingOrphans = true;
OnPropertyChanged(nameof(OrphansText));
var search = StartSearch();
try
{
var report = await Task.Run(() => archives.FindOrphansAsync(archive.Id));
Orphans = OrphanRows(report, await db.Sequences.ListLocationsAsync(archive.Id));
var report = await Task.Run(() => archives.FindOrphansAsync(archive.Id, search.Token), search.Token);
Orphans = OrphanRows(report, await db.Sequences.ListLocationsAsync(archive.Id, search.Token));
Log.Info("archive", $"Orphans search in {archive.RootPath}: {report.UnindexedFiles} unlisted, {report.MissingFiles} missing, "
+ $"{report.MissingSequences.Count} rows without sidecar, {report.UnindexedFolders.Count} new folders");
}
catch (OperationCanceledException) when (search.IsCancellationRequested)
{
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or ArchiveOfflineException or DatabaseException)
{
@@ -567,11 +776,34 @@ public sealed class ArchiveViewModel : SectionViewModel
finally
{
_findingOrphans = false;
OnPropertyChanged(nameof(OrphansText));
CommandManager.InvalidateRequerySuggested();
EndSearch(search);
}
}
private CancellationTokenSource StartSearch()
{
_search = new CancellationTokenSource();
OnSearchChanged();
return _search;
}
private void EndSearch(CancellationTokenSource search)
{
if (ReferenceEquals(_search, search)) _search = null;
search.Dispose();
OnSearchChanged();
}
private void OnSearchChanged()
{
OnPropertyChanged(nameof(IsSearching));
OnPropertyChanged(nameof(DuplicatesText));
OnPropertyChanged(nameof(OrphansText));
OnPropertyChanged(nameof(DuplicatesToolTip));
OnPropertyChanged(nameof(OrphansToolTip));
CommandManager.InvalidateRequerySuggested();
}
private IReadOnlyList<DuplicateRowViewModel> DuplicateRows(IReadOnlyList<DuplicateGroup> groups, IReadOnlyList<SequenceLocation> locations) =>
[
.. MaintenanceReports.Duplicates(groups, locations).Select(row => new DuplicateRowViewModel(row,