diff --git a/i18n/en/Tooltips.resx b/i18n/en/Tooltips.resx index 0ab3d0ba..d4dfb9d8 100644 --- a/i18n/en/Tooltips.resx +++ b/i18n/en/Tooltips.resx @@ -74,6 +74,7 @@ Add or remove tags on the whole set Generate or refresh thumbnails Re-hash the originals of the set + Stop after the current sequence; the changes made so far stay Bytes of originals per capture year Tags to add, separated by commas Tags to remove, separated by commas diff --git a/i18n/it/Tooltips.it.resx b/i18n/it/Tooltips.it.resx index 854b4914..0dbddec5 100644 --- a/i18n/it/Tooltips.it.resx +++ b/i18n/it/Tooltips.it.resx @@ -74,6 +74,7 @@ Aggiungi o rimuovi tag su tutta la selezione Crea o aggiorna le miniature Ricalcola l'hash degli originali della selezione + Fermati dopo la sequenza in corso; le modifiche già fatte restano Spazio degli originali per anno di scatto Tag da aggiungere, separati da virgole Tag da rimuovere, separati da virgole diff --git a/src/Titano.App/Archive/ArchiveDialogViewModels.cs b/src/Titano.App/Archive/ArchiveDialogViewModels.cs index 2ac3c6d0..98f9c303 100644 --- a/src/Titano.App/Archive/ArchiveDialogViewModels.cs +++ b/src/Titano.App/Archive/ArchiveDialogViewModels.cs @@ -14,19 +14,39 @@ using Titano.Ui.Mvvm; namespace Titano.App.Archiving; /// -/// An in-window dialog of the Archive screen: one primary action, one way out. While its action runs it cannot be -/// closed; receives the dialog, so a late close never closes another one. +/// An in-window dialog of the Archive screen: one primary action, one way out. While its action runs, the way out +/// stops it when it can be stopped, and is disabled otherwise; the close callback receives the dialog, so a late close +/// never closes another one. /// public abstract class ArchiveDialogViewModel : LocalizedViewModel { + private readonly Action _close; private bool _isBusy; private string? _busyText; - protected ArchiveDialogViewModel(Action close) => CloseCommand = new RelayCommand(() => close(this), () => !IsBusy); + protected ArchiveDialogViewModel(Action close) + { + _close = close; + CloseCommand = new RelayCommand(() => + { + if (IsBusy) Stop(); + else Close(); + }, () => !IsBusy || CanStop); + } + /// Cancel: closes the dialog, or stops its running action. public ICommand CloseCommand { get; } - public string CloseToolTip => IsBusy ? Loc.L("Archive.Blocked.Applying") : Loc.L("Tooltips.Archive.CloseDialog"); + public string CloseToolTip => !IsBusy ? Loc.L("Tooltips.Archive.CloseDialog") + : CanStop ? Loc.L("Tooltips.Archive.StopApply") + : Loc.L("Archive.Blocked.Applying"); + + /// The running action can stop between two steps. + protected virtual bool CanStop => false; + + protected virtual void Stop() + { + } public bool IsBusy { @@ -41,7 +61,7 @@ public abstract class ArchiveDialogViewModel : LocalizedViewModel public string? BusyText { get => _busyText; protected set => Set(ref _busyText, value); } - protected void Close() => CloseCommand.Execute(null); + protected void Close() => _close(this); } /// A fact of the rebuild dialog ("Sidecars · 412"). @@ -242,6 +262,7 @@ public sealed class RenameDialogViewModel : ArchiveDialogViewModel try { await Task.Run(() => _archives.ApplyRenameAsync(plan, progress)); + Log.Info("archive", $"{Mode} applied to {plan.Steps.Count} sequence(s)"); await _applied(plan.Steps.Count); Close(); } @@ -263,6 +284,7 @@ public sealed class RetagDialogViewModel : ArchiveDialogViewModel private readonly ArchiveService _archives; private readonly IReadOnlyList _set; private readonly Func _applied; + private CancellationTokenSource? _run; public RetagDialogViewModel(ArchiveService archives, IReadOnlyList set, Func applied, Action close) : base(close) @@ -306,19 +328,27 @@ public sealed class RetagDialogViewModel : ArchiveDialogViewModel private IReadOnlyList<(Sequence Sequence, IReadOnlyList Tags)> Changes() => Add.HasErrors || Remove.HasErrors ? [] : Retag.Changes(_set, Retag.Parse(Add.Text), Retag.Parse(Remove.Text)); + protected override bool CanStop => _run is not null; + + /// Stops after the sequence being written; each sequence is changed completely or not at all. + protected override void Stop() => _run?.Cancel(); + private async Task ApplyAsync() { var changes = Changes(); + var run = _run = new CancellationTokenSource(); + var done = 0; IsBusy = true; try { - for (var i = 0; i < changes.Count; i++) + for (; done < changes.Count && !run.IsCancellationRequested; done++) { - var (s, tags) = changes[i]; - BusyText = Loc.L("Archive.Rename.Applying", Formatting.Count(i + 1), Formatting.Count(changes.Count)); + var (s, tags) = changes[done]; + BusyText = Loc.L("Archive.Rename.Applying", Formatting.Count(done + 1), Formatting.Count(changes.Count)); await Task.Run(() => _archives.SetSequenceInfoAsync(s.Id, s.Title, tags, s.Rating, s.Notes)); } - await _applied(changes.Count); + Log.Info("archive", $"Retag: {done} of {changes.Count} sequence(s) changed"); + await _applied(done); Close(); } catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException or DatabaseException or ArchiveOfflineException) @@ -328,6 +358,8 @@ public sealed class RetagDialogViewModel : ArchiveDialogViewModel } finally { + _run = null; + run.Dispose(); IsBusy = false; } } diff --git a/src/Titano.App/Sections/ArchiveView.xaml b/src/Titano.App/Sections/ArchiveView.xaml index 42a18f7b..1a2b240c 100644 --- a/src/Titano.App/Sections/ArchiveView.xaml +++ b/src/Titano.App/Sections/ArchiveView.xaml @@ -18,9 +18,6 @@ - @@ -189,8 +187,8 @@ - - + + @@ -201,12 +199,12 @@ - - - - + + + + - + @@ -501,7 +499,7 @@ - + diff --git a/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs b/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs index a305524a..9db10c3f 100644 --- a/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs +++ b/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs @@ -1,5 +1,6 @@ using System.Globalization; using Titano.App.Archiving; +using Titano.App.Library; using Titano.Core.Archiving; using Titano.Core.Imaging; using Titano.Core.Localization; @@ -98,6 +99,34 @@ public sealed class ArchiveLogicTests ], Health: new ArchiveHealth(Unverified: 3, WithWarnings: 1, WithErrors: 0, NotAnalyzed: 2, MissingFrames: 0, CorruptFrames: 0, DuplicateFrames: 5)); + [Test] + public void TheSetFilterNarrowsByCameraStatusAndTag() + { + var canon = Seq("Harbour", new DateTime(2026, 9, 28), tags: "sunset") with + { + CameraMake = "Canon", + CameraModel = "Canon EOS R5", + Status = SequenceStatus.AnalyzedLight | SequenceStatus.ProxiesBuilt, + }; + var sony = Seq("Comet", new DateTime(2026, 8, 13), tags: "night") with { CameraMake = "SONY", CameraModel = "ILCE-7M4" }; + var unknown = Seq("Old", null); + + Assert.True(new ArchiveSetFilter().IsEmpty); + Assert.True(new ArchiveSetFilter().Matches(unknown), "no filter keeps everything"); + var byCamera = new ArchiveSetFilter(Camera: ArchiveSetFilter.CameraOf(canon)); + Assert.True(byCamera.Matches(canon)); + Assert.False(byCamera.Matches(sony)); + Assert.Equal(Loc.L("Archive.Chart.UnknownCamera"), ArchiveSetFilter.CameraOf(unknown)); + Assert.True(new ArchiveSetFilter(Status: StatusFilter.NotAnalysed).Matches(sony)); + Assert.False(new ArchiveSetFilter(Status: StatusFilter.NotAnalysed).Matches(canon)); + Assert.True(new ArchiveSetFilter(Status: StatusFilter.Proxies).Matches(canon)); + Assert.True(new ArchiveSetFilter(Tag: "SUNSET").Matches(canon), "tags compare without case"); + Assert.False(new ArchiveSetFilter(Tag: "sunset").Matches(sony)); + Assert.Equal(ArchiveSetFilter.CameraOf(canon) + " · Not analysed · sunset", + new ArchiveSetFilter(ArchiveSetFilter.CameraOf(canon), StatusFilter.NotAnalysed, "sunset").Describe()); + Assert.Equal(string.Empty, new ArchiveSetFilter().Describe()); + } + [Test] public void ChartsAggregateYearsCamerasAndFormats() {