fix(app): retag stops on Cancel between sequences; menu tooltips show while disabled

Rename and retag log what they changed; the set filter has its own test.

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:51:13 +00:00
1 parent 58ae096061
commit 385c7267f6
5 files changed
+81 -20

No files matched your search

@@ -14,19 +14,39 @@ using Titano.Ui.Mvvm;
namespace Titano.App.Archiving;
/// <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.
/// 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.
/// </summary>
public abstract class ArchiveDialogViewModel : LocalizedViewModel
{
private readonly Action<ArchiveDialogViewModel> _close;
private bool _isBusy;
private string? _busyText;
protected ArchiveDialogViewModel(Action<ArchiveDialogViewModel> close) => CloseCommand = new RelayCommand(() => close(this), () => !IsBusy);
protected ArchiveDialogViewModel(Action<ArchiveDialogViewModel> close)
{
_close = close;
CloseCommand = new RelayCommand(() =>
{
if (IsBusy) Stop();
else Close();
}, () => !IsBusy || CanStop);
}
/// <summary>Cancel: closes the dialog, or stops its running action.</summary>
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");
/// <summary>The running action can stop between two steps.</summary>
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);
}
/// <summary>A fact of the rebuild dialog ("Sidecars · 412").</summary>
@@ -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<Sequence> _set;
private readonly Func<int, Task> _applied;
private CancellationTokenSource? _run;
public RetagDialogViewModel(ArchiveService archives, IReadOnlyList<Sequence> set, Func<int, Task> applied, Action<ArchiveDialogViewModel> close)
: base(close)
@@ -306,19 +328,27 @@ public sealed class RetagDialogViewModel : ArchiveDialogViewModel
private IReadOnlyList<(Sequence Sequence, IReadOnlyList<string> 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;
/// <summary>Stops after the sequence being written; each sequence is changed completely or not at all.</summary>
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;
}
}
+9 -11
View File
@@ -18,9 +18,6 @@
<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" />
@@ -36,6 +33,7 @@
<Setter Property="IsChecked" Value="{Binding IsChecked, Mode=OneWay}" />
<Setter Property="Command" Value="{Binding Command}" />
<Setter Property="ToolTip" Value="{l:Loc Tooltips.Archive.FilterChoice}" />
<Setter Property="ToolTipService.ShowOnDisabled" Value="True" />
</Style>
<!-- Dialog card (DESIGN §4: Surface, Stroke, radius 12, 24 px shadow, two buttons). -->
@@ -189,8 +187,8 @@
</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}" />
<MenuItem Header="{l:Loc Archive.Adopt.InPlace}" Command="{Binding AdoptCommand}" ToolTip="{l:Loc Tooltips.Archive.AdoptInPlace}" ToolTipService.ShowOnDisabled="True" />
<MenuItem Header="{l:Loc Archive.Adopt.Copy}" Command="{Binding CopyFolderCommand}" ToolTip="{l:Loc Tooltips.Archive.AdoptCopy}" ToolTipService.ShowOnDisabled="True" />
</ContextMenu>
</Button.ContextMenu>
</Button>
@@ -201,12 +199,12 @@
</StackPanel>
<Button.ContextMenu>
<ContextMenu>
<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="{Binding RebuildProxiesToolTip}" />
<MenuItem Header="{l:Loc Archive.Maintenance.Backup}" Command="{Binding BackupCommand}" ToolTip="{l:Loc Tooltips.Archive.Backup}" />
<MenuItem Header="{l:Loc Archive.Maintenance.Run}" Command="{Binding MaintenanceCommand}" ToolTip="{Binding MaintenanceRunToolTip}" ToolTipService.ShowOnDisabled="True" />
<MenuItem Header="{l:Loc Archive.Maintenance.DryRun}" Command="{Binding MaintenanceDryRunCommand}" ToolTip="{l:Loc Tooltips.Archive.MaintenanceDryRun}" ToolTipService.ShowOnDisabled="True" />
<MenuItem Header="{l:Loc Archive.Maintenance.Proxies}" Command="{Binding RebuildProxiesCommand}" ToolTip="{Binding RebuildProxiesToolTip}" ToolTipService.ShowOnDisabled="True" />
<MenuItem Header="{l:Loc Archive.Maintenance.Backup}" Command="{Binding BackupCommand}" ToolTip="{l:Loc Tooltips.Archive.Backup}" ToolTipService.ShowOnDisabled="True" />
<Separator />
<MenuItem Header="{l:Loc Archive.Maintenance.Relink}" Command="{Binding RelinkCommand}" ToolTip="{l:Loc Tooltips.Archive.Relink}" />
<MenuItem Header="{l:Loc Archive.Maintenance.Relink}" Command="{Binding RelinkCommand}" ToolTip="{l:Loc Tooltips.Archive.Relink}" ToolTipService.ShowOnDisabled="True" />
</ContextMenu>
</Button.ContextMenu>
</Button>
@@ -501,7 +499,7 @@
<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}" />
<MenuItem Header="{l:Loc Archive.Set.ClearFilter}" Command="{Binding ClearFilterCommand}" ToolTip="{l:Loc Tooltips.Archive.ClearFilter}" ToolTipService.ShowOnDisabled="True" />
</ContextMenu>
</Button.ContextMenu>
</Button>