feat(app): matches list, compare dialog, settings rows, library and picker surfaces (owner review 6, P6)
Server > Matches shows the pairs the copy engine found (same sequence on the server and this PC, or twice here), attention first, with the design 8.1 actions; Keep apart and Unlink toast with Undo. The in-window Compare dialog walks photos, details, projects and the plan, blocks until details are chosen, and confirms only what replaces or merges (typed count for a merge). Sync rows of an unanswered pair read "match found" and offer Compare first; Upload all local skips suspected copies and says why. Settings > Server gains Link matches, Integrate photos and Integrate projects. Library cards carry the match status with Compare..., the sequence picker marks twins, and Jobs opens Integrate and Merge targets. The sample engine and capture scenes render every state; tests cover the text rules and the screens. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
283d04d9cd
commit
06b826e39d
34 files changed
+3762
-43
No files matched your search
@@ -0,0 +1,59 @@
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>
|
||||
/// A detail that differs (the Details part): its label, this PC's and the other side's value, and the side both take
|
||||
/// (nothing preselected: <see cref="ChoiceIndex"/> -1 until the user picks).
|
||||
/// </summary>
|
||||
public sealed class CopyDetailRow(DetailLine line, bool isMerge, Action changed) : ObservableObject
|
||||
{
|
||||
private int _choiceIndex = -1;
|
||||
|
||||
public DetailLine Line { get; } = line;
|
||||
public string Path => Line.Path;
|
||||
public string Label => SyncText.DetailLabel(Line.Path);
|
||||
public string HereText => Value(Line.Here);
|
||||
public string ThereText => Value(Line.There);
|
||||
public string HereToolTip => Line.Here ?? Loc.L("Server.Sync.None");
|
||||
public string ThereToolTip => Line.There ?? Loc.L("Server.Sync.None");
|
||||
|
||||
public string HereWord => Loc.L(isMerge ? "Server.Copies.Detail.Kept" : "Server.Copies.Detail.ThisPc");
|
||||
public string ThereWord => Loc.L(isMerge ? "Server.Copies.Detail.Other" : "Server.Copies.Detail.Server");
|
||||
|
||||
/// <summary>"Deflicker window: This PC/Server": the line's one tab stop.</summary>
|
||||
public string AccessibleName => Loc.L("Server.Copies.ControlFor", Label, HereWord + "/" + ThereWord);
|
||||
|
||||
public string ToolTip => Loc.L("Tooltips.Server.Copies.Detail");
|
||||
|
||||
/// <summary>0 this PC (or the kept one), 1 the other side, -1 not chosen.</summary>
|
||||
public int ChoiceIndex
|
||||
{
|
||||
get => _choiceIndex;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _choiceIndex, value)) return;
|
||||
OnPropertyChanged(nameof(Chosen));
|
||||
changed();
|
||||
}
|
||||
}
|
||||
|
||||
public CopySide? Chosen => _choiceIndex switch
|
||||
{
|
||||
0 => CopySide.ThisPc,
|
||||
1 => CopySide.Other,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
internal void SetQuietly(int index)
|
||||
{
|
||||
_choiceIndex = index;
|
||||
OnPropertyChanged(nameof(ChoiceIndex));
|
||||
OnPropertyChanged(nameof(Chosen));
|
||||
}
|
||||
|
||||
private static string Value(string? value) => string.IsNullOrWhiteSpace(value) ? Loc.L("Server.Sync.None")
|
||||
: value.Length <= 40 ? value : string.Concat(value.AsSpan(0, 39), "…");
|
||||
}
|
||||
@@ -0,0 +1,801 @@
|
||||
using System.Windows.Input;
|
||||
using Chronos.App.Archiving;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Settings;
|
||||
using Chronos.App.Shell;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>The four parts of the Compare dialog, in the order of its SegmentedControl.</summary>
|
||||
public enum CopyDialogPart
|
||||
{
|
||||
Photos,
|
||||
Details,
|
||||
Projects,
|
||||
Plan,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compare sequences / Merge sequences (owner review 6, #73, design §8.2): both sides of a pair, photo by photo (classes and
|
||||
/// the photos of one, with per-photo choices under Choose each), detail by detail (nothing preselected), projects (copied
|
||||
/// across or left), and the plan the engine computes from those choices (debounced 300 ms) with its blocks and their one
|
||||
/// action. Two footer buttons: Cancel and Integrate (Merge); a destructive plan confirms first, then the job is queued
|
||||
/// and the dialog closes. UI thread.
|
||||
/// </summary>
|
||||
public sealed class CopyDialogViewModel : ArchiveDialogViewModel
|
||||
{
|
||||
/// <summary>How long a choice waits before the plan is computed again.</summary>
|
||||
internal static TimeSpan PlanDelay { get; set; } = TimeSpan.FromMilliseconds(300);
|
||||
|
||||
private readonly ShellViewModel _shell;
|
||||
private readonly ICopyEngine _engine;
|
||||
private readonly FoundCopyView _pair;
|
||||
private readonly CopyRights _rights;
|
||||
private readonly bool _integrate;
|
||||
private readonly PhotoClass? _startClass;
|
||||
private readonly Dictionary<string, PhotoChoice> _perPhoto = [];
|
||||
private readonly AsyncRelayCommand _apply;
|
||||
private readonly AsyncRelayCommand _linkOnly;
|
||||
private readonly AsyncRelayCommand _trash;
|
||||
private readonly AsyncRelayCommand _deleteThere;
|
||||
private CancellationTokenSource? _planning;
|
||||
private CopyReview? _review;
|
||||
private IntegratePlan? _plan;
|
||||
private MergePlan? _merge;
|
||||
private CopyDialogPart _part;
|
||||
private SettingsOption<CopyPhotoPolicy> _policy;
|
||||
private int _projectsIndex;
|
||||
private Guid? _keepId;
|
||||
private CopyClassRow? _class;
|
||||
private IReadOnlyList<CopyClassRow> _classes = [];
|
||||
private IReadOnlyList<CopyPhotoRow> _photos = [];
|
||||
private IReadOnlyList<CopyDetailRow> _details = [];
|
||||
private IReadOnlyList<CopyProjectRow> _hereProjects = [];
|
||||
private IReadOnlyList<CopyProjectRow> _thereProjects = [];
|
||||
private IReadOnlyList<CopyKeepOption> _keep = [];
|
||||
private IReadOnlyList<CopyPlanLine> _hereLines = [];
|
||||
private IReadOnlyList<CopyPlanLine> _thereLines = [];
|
||||
private IReadOnlyList<CopyBlockLine> _blocks = [];
|
||||
private bool _isPlanning;
|
||||
private bool _isLoaded;
|
||||
|
||||
public CopyDialogViewModel(ShellViewModel shell, ICopyEngine engine, FoundCopyView pair, CopyRights rights, CopyDialogPart part,
|
||||
PhotoClass? photos, bool integrate, Action<ArchiveDialogViewModel> close)
|
||||
: base(close)
|
||||
{
|
||||
_shell = shell;
|
||||
_engine = engine;
|
||||
_pair = pair;
|
||||
_rights = rights;
|
||||
_part = part;
|
||||
_startClass = photos;
|
||||
_integrate = integrate;
|
||||
Policies = PolicyOptions(IsMerge);
|
||||
var wanted = shell.Services.Settings.CopyPhotos;
|
||||
_policy = Policies.FirstOrDefault(o => o.Value == wanted) ?? Policies[0];
|
||||
_projectsIndex = !IsMerge && shell.Services.Settings.CopyProjects == CopyProjects.Leave ? 1 : 0;
|
||||
_apply = new AsyncRelayCommand(ApplyAsync, () => _isLoaded && !IsBusy && !_isPlanning && (_part != CopyDialogPart.Plan || CanApplyPlan));
|
||||
_linkOnly = new AsyncRelayCommand(LinkOnlyAsync, () => _isLoaded && !IsBusy && ShowLinkOnly);
|
||||
_trash = new AsyncRelayCommand(() => TrashHereAsync([.. _photos.Where(p => p.IsSelected).Select(p => p.Key)]),
|
||||
() => !IsBusy && _photos.Any(p => p.IsSelected));
|
||||
_deleteThere = new AsyncRelayCommand(() => TrashThereAsync([.. _photos.Where(p => p.IsSelected).Select(p => p.Key)]),
|
||||
() => !IsBusy && _photos.Any(p => p.IsSelected));
|
||||
BringAllCommand = new RelayCommand(() => SetAll(bring: true));
|
||||
BringNoneCommand = new RelayCommand(() => SetAll(bring: false));
|
||||
AllBothCommand = new RelayCommand(() => SetAll(bring: true, choice: PhotoChoice.KeepBoth));
|
||||
AllHereCommand = new RelayCommand(() => SetDetails(0));
|
||||
AllThereCommand = new RelayCommand(() => SetDetails(1));
|
||||
}
|
||||
|
||||
public FoundCopy Copy => _pair.Copy;
|
||||
public bool IsMerge => Copy.Kind == CopyKind.LocalLocal;
|
||||
|
||||
public string Heading => Loc.L(IsMerge ? "Server.Copies.Dialog.Merge" : "Server.Copies.Dialog.Compare");
|
||||
|
||||
/// <summary>"This PC · Lighthouse · 1,204 photos · 18.2 GB".</summary>
|
||||
public string HereText => Loc.L("Server.Copies.Where.ThisPc", CopyText.Facts(Here));
|
||||
|
||||
public string ThereText => IsMerge ? Loc.L("Server.Copies.Where.ThisPc", CopyText.Facts(There)) : CopyText.Facts(There);
|
||||
|
||||
private CopyFacts Here => _review?.Here ?? _pair.Here;
|
||||
private CopyFacts There => _review?.There ?? _pair.There;
|
||||
private string ServerName => _rights.ServerName ?? Copy.Server ?? There.Where;
|
||||
|
||||
public bool IsLoaded { get => _isLoaded; private set => Set(ref _isLoaded, value); }
|
||||
|
||||
public CopyReview? Review => _review;
|
||||
|
||||
// ---- Parts ----
|
||||
|
||||
public CopyDialogPart Part
|
||||
{
|
||||
get => _part;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _part, value)) return;
|
||||
OnPropertyChanged(nameof(PartIndex));
|
||||
OnPropertyChanged(nameof(IsPhotos));
|
||||
OnPropertyChanged(nameof(IsDetails));
|
||||
OnPropertyChanged(nameof(IsProjects));
|
||||
OnPropertyChanged(nameof(IsPlan));
|
||||
OnPropertyChanged(nameof(ApplyToolTip));
|
||||
if (value == CopyDialogPart.Plan) SchedulePlan(TimeSpan.Zero);
|
||||
_apply.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public int PartIndex
|
||||
{
|
||||
get => (int)_part;
|
||||
set
|
||||
{
|
||||
if (value is >= 0 and <= 3) Part = (CopyDialogPart)value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsPhotos => _part == CopyDialogPart.Photos;
|
||||
public bool IsDetails => _part == CopyDialogPart.Details;
|
||||
public bool IsProjects => _part == CopyDialogPart.Projects;
|
||||
public bool IsPlan => _part == CopyDialogPart.Plan;
|
||||
|
||||
// ---- Photos ----
|
||||
|
||||
public IReadOnlyList<SettingsOption<CopyPhotoPolicy>> Policies { get; }
|
||||
|
||||
public SettingsOption<CopyPhotoPolicy> Policy
|
||||
{
|
||||
get => _policy;
|
||||
set
|
||||
{
|
||||
if (value is null || !Set(ref _policy, value)) return;
|
||||
OnPropertyChanged(nameof(PolicyToolTip));
|
||||
OnPropertyChanged(nameof(IsChoosing));
|
||||
BuildPhotos();
|
||||
Changed();
|
||||
}
|
||||
}
|
||||
|
||||
public string PolicyToolTip => string.Join(Environment.NewLine, Loc.L("Tooltips.Server.Copies.Policy"), _policy.ToolTip);
|
||||
|
||||
/// <summary>Choose each: the photo lists take ticks and version choices.</summary>
|
||||
public bool IsChoosing => _policy.Value == CopyPhotoPolicy.ChoosePerPhoto;
|
||||
|
||||
public IReadOnlyList<CopyClassRow> Classes { get => _classes; private set => Set(ref _classes, value); }
|
||||
|
||||
public CopyClassRow? SelectedClass
|
||||
{
|
||||
get => _class;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _class, value)) return;
|
||||
BuildPhotos();
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyList<CopyPhotoRow> Photos { get => _photos; private set => Set(ref _photos, value); }
|
||||
|
||||
public bool HasPhotos => _photos.Count > 0;
|
||||
|
||||
/// <summary>"No photos differ.": the selected class holds nothing (or the two sides hold the same photos).</summary>
|
||||
public string? PhotosEmptyText => HasPhotos ? null : Loc.L("Server.Copies.Class.None");
|
||||
|
||||
public bool CanBringAll => _photos.Any(p => p.CanBring);
|
||||
public bool CanKeepAllBoth => _photos.Any(p => p.CanChoose);
|
||||
public bool CanTrashHere => _class?.Class == PhotoClass.DeletedThere && _photos.Count > 0;
|
||||
public bool CanDeleteThere => !IsMerge && _class?.Class == PhotoClass.DeletedHere && _photos.Count > 0 && _review?.Can.DeleteThere == true;
|
||||
|
||||
public ICommand BringAllCommand { get; }
|
||||
public ICommand BringNoneCommand { get; }
|
||||
public ICommand AllBothCommand { get; }
|
||||
public ICommand TrashCommand => _trash;
|
||||
public ICommand DeleteThereCommand => _deleteThere;
|
||||
|
||||
// ---- Details ----
|
||||
|
||||
public IReadOnlyList<CopyDetailRow> Details { get => _details; private set => Set(ref _details, value); }
|
||||
public bool HasDetails => _details.Count > 0;
|
||||
public string? DetailsEmptyText => HasDetails ? null : Loc.L("Server.Copies.Detail.None");
|
||||
public int Unchosen => _details.Count(d => d.Chosen is null);
|
||||
public ICommand AllHereCommand { get; }
|
||||
public ICommand AllThereCommand { get; }
|
||||
public string AllHereText => Loc.L("Server.Copies.Detail.AllThisPc");
|
||||
public string AllThereText => Loc.L("Server.Copies.Detail.AllServer");
|
||||
|
||||
// ---- Projects ----
|
||||
|
||||
/// <summary>0 Copy across, 1 Leave them (a merge always copies: its other home goes to the trash).</summary>
|
||||
public int ProjectsIndex
|
||||
{
|
||||
get => _projectsIndex;
|
||||
set
|
||||
{
|
||||
if (IsMerge || value is < 0 or > 1 || !Set(ref _projectsIndex, value)) return;
|
||||
OnPropertyChanged(nameof(ProjectsToolTip));
|
||||
Changed();
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanChooseProjects => !IsMerge && _review?.Projects.ThereKeepsProjects != false;
|
||||
|
||||
public string ProjectsToolTip => IsMerge ? Loc.L("Tooltips.Server.Copies.Projects.MergeAlways")
|
||||
: Loc.L(_projectsIndex == 0 ? "Tooltips.Server.Copies.Projects.CopyAcross" : "Tooltips.Server.Copies.Projects.Leave");
|
||||
|
||||
public IReadOnlyList<CopyProjectRow> HereProjects { get => _hereProjects; private set => Set(ref _hereProjects, value); }
|
||||
public IReadOnlyList<CopyProjectRow> ThereProjects { get => _thereProjects; private set => Set(ref _thereProjects, value); }
|
||||
|
||||
/// <summary>"nas keeps no projects: they stay." or "No other projects."; null when there are projects to show.</summary>
|
||||
public string? ProjectsNote => _review is not { } review ? null
|
||||
: !review.Projects.ThereKeepsProjects ? Loc.L("Server.Copies.Projects.NoneThere", ServerName)
|
||||
: _hereProjects.Count + _thereProjects.Count == 0 ? Loc.L("Server.Copies.Projects.None")
|
||||
: null;
|
||||
|
||||
// ---- Plan ----
|
||||
|
||||
public IReadOnlyList<CopyKeepOption> KeepOptions { get => _keep; private set => Set(ref _keep, value); }
|
||||
public bool HasKeepOptions => _keep.Count > 0;
|
||||
public IReadOnlyList<CopyPlanLine> HereLines { get => _hereLines; private set => Set(ref _hereLines, value); }
|
||||
public IReadOnlyList<CopyPlanLine> ThereLines { get => _thereLines; private set => Set(ref _thereLines, value); }
|
||||
public IReadOnlyList<CopyBlockLine> Blocks { get => _blocks; private set => Set(ref _blocks, value); }
|
||||
|
||||
/// <summary>"On this PC", or for a merge "Into {kept}".</summary>
|
||||
public string HereHeading => IsMerge ? Loc.L("Server.Copies.Plan.Into", KeptFacts?.Where ?? Loc.L("Server.Copies.Plan.KeptCopy"))
|
||||
: Loc.L("Server.Copies.Plan.OnThisPc");
|
||||
|
||||
public string ThereHeading => IsMerge ? DroppedFacts?.Where ?? There.Where : Loc.L("Server.Copies.Plan.OnServer", ServerName);
|
||||
|
||||
public bool IsPlanning
|
||||
{
|
||||
get => _isPlanning;
|
||||
private set
|
||||
{
|
||||
if (!Set(ref _isPlanning, value)) return;
|
||||
OnPropertyChanged(nameof(PlanningText));
|
||||
_apply.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string? PlanningText => _isPlanning ? Loc.L("Server.Copies.Planning") : null;
|
||||
|
||||
public IntegratePlan? Plan => _plan;
|
||||
public MergePlan? MergePlan => _merge;
|
||||
|
||||
private bool CanApplyPlan => IsMerge ? _merge?.CanApply == true : _plan?.CanApply == true;
|
||||
|
||||
/// <summary>Link only: a pair with a server not linked yet; links the two without moving photos.</summary>
|
||||
public bool ShowLinkOnly => !IsMerge && Copy.State == CopyState.Candidate && _review?.Can.LinkOnly == true;
|
||||
|
||||
public ICommand LinkOnlyCommand => _linkOnly;
|
||||
public string LinkOnlyText => Loc.L("Server.Copies.Action.LinkOnly");
|
||||
public string LinkOnlyToolTip => Loc.L("Tooltips.Server.Copies.LinkOnly");
|
||||
|
||||
// ---- Footer ----
|
||||
|
||||
public ICommand ApplyCommand => _apply;
|
||||
public string ApplyText => Loc.L(IsMerge ? "Server.Copies.Action.Merge" : "Server.Copies.Action.IntegrateNow");
|
||||
|
||||
/// <summary>What Integrate (Merge) does, or the first reason it cannot.</summary>
|
||||
public string ApplyToolTip => _part == CopyDialogPart.Plan && _blocks.Count > 0 ? _blocks[0].Text
|
||||
: Loc.L(IsMerge ? "Tooltips.Server.Copies.Merge" : "Tooltips.Server.Copies.Integrate");
|
||||
|
||||
public string CancelToolTip => Loc.L("Tooltips.Server.Copies.Cancel");
|
||||
|
||||
/// <summary>Reads both sides, then opens on the part asked for (Integrate…: Details while any line is unchosen, else Plan).</summary>
|
||||
public async Task LoadAsync()
|
||||
{
|
||||
IsLoaded = false;
|
||||
BusyText = Loc.L("Server.Copies.Planning");
|
||||
try
|
||||
{
|
||||
_review = await _engine.CompareAsync(Copy.Id, Copy.Kind == CopyKind.LocalServer ? _shell.Services.Sync.Remote : null, CancellationToken.None);
|
||||
if (IsClosed) return;
|
||||
Build(_review);
|
||||
IsLoaded = true;
|
||||
if (_integrate && _part == CopyDialogPart.Plan && Unchosen > 0) _part = CopyDialogPart.Details;
|
||||
OnAllPropertiesChanged();
|
||||
if (_part == CopyDialogPart.Plan) SchedulePlan(TimeSpan.Zero);
|
||||
}
|
||||
catch (Exception ex) when (Expected(ex))
|
||||
{
|
||||
ShowError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
BusyText = null;
|
||||
_apply.RaiseCanExecuteChanged();
|
||||
_linkOnly.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Computes the plan of the current choices now (tests, captures).</summary>
|
||||
internal async Task PlanNowAsync()
|
||||
{
|
||||
_planning?.Cancel();
|
||||
await PlanAsync(CancellationToken.None);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
_planning?.Cancel();
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
protected override void OnLanguageChanged()
|
||||
{
|
||||
if (_review is { } review) Build(review);
|
||||
BuildPlanLines();
|
||||
base.OnLanguageChanged();
|
||||
}
|
||||
|
||||
private void Build(CopyReview review)
|
||||
{
|
||||
Classes = [.. review.Photos.Totals.Where(t => t.Count > 0).Select(t => new CopyClassRow(t))];
|
||||
_class = _classes.FirstOrDefault(c => c.Class == _startClass)
|
||||
?? _classes.FirstOrDefault(c => c.Class is not (PhotoClass.Same or PhotoClass.Converted))
|
||||
?? _classes.FirstOrDefault();
|
||||
BuildPhotos();
|
||||
var chosen = _details.ToDictionary(d => d.Path, d => d.ChoiceIndex);
|
||||
Details = [.. review.Details.Select(line => new CopyDetailRow(line, IsMerge, Changed))];
|
||||
foreach (var row in _details) row.SetQuietly(chosen.GetValueOrDefault(row.Path, -1));
|
||||
HereProjects = [.. review.Projects.Here.Select(p => new CopyProjectRow(p))];
|
||||
ThereProjects = [.. review.Projects.There.Select(p => new CopyProjectRow(p))];
|
||||
if (IsMerge)
|
||||
{
|
||||
KeepOptions = [new CopyKeepOption(Copy.LocalId, review.Here, Keep), new CopyKeepOption(Copy.OtherId ?? Guid.Empty, review.There, Keep)];
|
||||
foreach (var option in _keep) option.SetQuietly(option.SequenceId == _keepId);
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildPhotos()
|
||||
{
|
||||
var review = _review;
|
||||
var cls = _class?.Class;
|
||||
var choosing = IsChoosing;
|
||||
var choices = VersionChoices(IsMerge);
|
||||
Func<CopyPhotoRow, Task>? drop = cls == PhotoClass.Versions ? DropAsync : null;
|
||||
Photos = review is null || cls is null ? []
|
||||
: [.. review.Photos.Of(cls.Value).Select(p => new CopyPhotoRow(p, IsMerge,
|
||||
choosing && !IsMerge && cls is PhotoClass.OnlyHere or PhotoClass.OnlyThere,
|
||||
choosing && cls == PhotoClass.Differs, choices, _perPhoto.TryGetValue(p.Key, out var c) ? c : null, () => OnPhotoChanged(p.Key), drop))];
|
||||
foreach (var row in _photos) row.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.PropertyName != nameof(CopyPhotoRow.IsSelected)) return;
|
||||
_trash.RaiseCanExecuteChanged();
|
||||
_deleteThere.RaiseCanExecuteChanged();
|
||||
};
|
||||
OnPropertyChanged(nameof(HasPhotos));
|
||||
OnPropertyChanged(nameof(PhotosEmptyText));
|
||||
OnPropertyChanged(nameof(CanBringAll));
|
||||
OnPropertyChanged(nameof(CanKeepAllBoth));
|
||||
OnPropertyChanged(nameof(CanTrashHere));
|
||||
OnPropertyChanged(nameof(CanDeleteThere));
|
||||
OnPropertyChanged(nameof(SelectedClass));
|
||||
}
|
||||
|
||||
private void OnPhotoChanged(string key)
|
||||
{
|
||||
if (_photos.FirstOrDefault(p => p.Key == key)?.Chosen is { } chosen) _perPhoto[key] = chosen;
|
||||
else _perPhoto.Remove(key);
|
||||
Changed();
|
||||
}
|
||||
|
||||
private void SetAll(bool bring, PhotoChoice? choice = null)
|
||||
{
|
||||
foreach (var row in _photos)
|
||||
{
|
||||
if (row.CanBring) row.SetQuietly(bring, null);
|
||||
else if (row.CanChoose && choice is { } c) row.SetQuietly(false, row.Choices.FirstOrDefault(o => o.Value == c));
|
||||
else continue;
|
||||
if (row.Chosen is { } chosen) _perPhoto[row.Key] = chosen;
|
||||
else _perPhoto.Remove(row.Key);
|
||||
}
|
||||
Changed();
|
||||
}
|
||||
|
||||
private void SetDetails(int index)
|
||||
{
|
||||
foreach (var row in _details) row.SetQuietly(index);
|
||||
Changed();
|
||||
}
|
||||
|
||||
private void Keep(CopyKeepOption option)
|
||||
{
|
||||
_keepId = option.SequenceId;
|
||||
foreach (var other in _keep.Where(o => !ReferenceEquals(o, option))) other.SetQuietly(false);
|
||||
OnPropertyChanged(nameof(HereHeading));
|
||||
OnPropertyChanged(nameof(ThereHeading));
|
||||
Changed();
|
||||
}
|
||||
|
||||
/// <summary>A choice changed: the plan follows once the user pauses.</summary>
|
||||
private void Changed()
|
||||
{
|
||||
OnPropertyChanged(nameof(Unchosen));
|
||||
if (_plan is not null || _merge is not null || _part == CopyDialogPart.Plan) SchedulePlan(PlanDelay);
|
||||
}
|
||||
|
||||
private void SchedulePlan(TimeSpan delay)
|
||||
{
|
||||
if (!_isLoaded) return;
|
||||
_planning?.Cancel();
|
||||
var run = _planning = new CancellationTokenSource();
|
||||
_ = Delayed();
|
||||
|
||||
async Task Delayed()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (delay > TimeSpan.Zero) await Task.Delay(delay, run.Token);
|
||||
await PlanAsync(run.Token);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// A newer choice planned instead.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IntegrateChoices IntegrateChoices() => new(_policy.Value, IsChoosing ? new Dictionary<string, PhotoChoice>(_perPhoto) : new Dictionary<string, PhotoChoice>(),
|
||||
DetailChoices(), _projectsIndex == 0 ? CopyProjects.CopyAcross : CopyProjects.Leave);
|
||||
|
||||
private MergeChoices MergeChoices() => new(_policy.Value, IsChoosing ? new Dictionary<string, PhotoChoice>(_perPhoto) : new Dictionary<string, PhotoChoice>(),
|
||||
DetailChoices());
|
||||
|
||||
private Dictionary<string, CopySide> DetailChoices() =>
|
||||
_details.Where(d => d.Chosen is not null).ToDictionary(d => d.Path, d => d.Chosen!.Value, StringComparer.Ordinal);
|
||||
|
||||
private async Task PlanAsync(CancellationToken ct)
|
||||
{
|
||||
IsPlanning = true;
|
||||
ClearError();
|
||||
try
|
||||
{
|
||||
if (IsMerge)
|
||||
{
|
||||
var merge = await _engine.PlanMergeAsync(Copy.Id, _keepId, MergeChoices(), ct);
|
||||
ct.ThrowIfCancellationRequested();
|
||||
_merge = merge;
|
||||
if (_keepId is null && !merge.Blocks.Contains(CopyBlock.KeptUnchosen) && merge.KeepId != Guid.Empty)
|
||||
{
|
||||
_keepId = merge.KeepId;
|
||||
foreach (var option in _keep) option.SetQuietly(option.SequenceId == _keepId);
|
||||
}
|
||||
}
|
||||
else if (_shell.Services.Sync.Remote is { } remote && string.Equals(_shell.Services.Sync.Server, Copy.Server, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var plan = await _engine.PlanIntegrateAsync(Copy.Id, remote, IntegrateChoices(), ct);
|
||||
ct.ThrowIfCancellationRequested();
|
||||
_plan = plan;
|
||||
}
|
||||
else
|
||||
{
|
||||
_plan = null;
|
||||
ShowMessage(Loc.L("Tooltips.Server.Copies.SignIn", Copy.Server ?? string.Empty));
|
||||
}
|
||||
BuildPlanLines();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex) when (Expected(ex))
|
||||
{
|
||||
ShowError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!ct.IsCancellationRequested) IsPlanning = false;
|
||||
}
|
||||
}
|
||||
|
||||
private CopyFacts? KeptFacts => _keepId is { } keep ? keep == Copy.LocalId ? Here : There : null;
|
||||
private CopyFacts? DroppedFacts => _keepId is { } keep ? keep == Copy.LocalId ? There : Here : null;
|
||||
|
||||
/// <summary>The lines of the Plan part, last copies first; the blocks with their one action.</summary>
|
||||
private void BuildPlanLines()
|
||||
{
|
||||
var here = new List<CopyPlanLine>();
|
||||
var there = new List<CopyPlanLine>();
|
||||
var blocks = new List<CopyBlockLine>();
|
||||
if (_plan is { } plan)
|
||||
{
|
||||
Lasts(plan.LastCopies, here, there);
|
||||
Photos(plan.Photos, PhotoAction.Fetch, PhotoAction.FetchVersion, "Server.Copies.Plan.Receives", here);
|
||||
Photos(plan.Photos, PhotoAction.Send, PhotoAction.SendVersion, "Server.Copies.Plan.Receives", there);
|
||||
Trash(plan.Photos, PhotoAction.TrashHere, here);
|
||||
Trash(plan.Photos, PhotoAction.TrashThere, there);
|
||||
var versions = plan.Photos.Count(p => p.Action == PhotoAction.SendVersion);
|
||||
if (versions > 0) there.Add(new(Loc.Plural("Server.Copies.Plan.ServerUsesOurs", versions, ServerName), Loc.L("Tooltips.Server.Copies.Plan.ServerUsesOurs")));
|
||||
if (plan.DetailChanges > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Details", plan.DetailChanges)));
|
||||
var fromHere = plan.Projects.Count(p => p.From == CopySide.ThisPc);
|
||||
var fromThere = plan.Projects.Count - fromHere;
|
||||
if (fromThere > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Projects", fromThere)));
|
||||
if (fromHere > 0) there.Add(new(Loc.Plural("Server.Copies.Plan.Projects", fromHere)));
|
||||
here.Add(new(Loc.L("Server.Copies.Plan.Free", Formatting.Bytes(plan.FreeBytes)), Loc.L("Tooltips.Server.Copies.Plan.Free")));
|
||||
if (plan.QuotaLeftBytes is { } quota) there.Add(new(Loc.L("Server.Copies.Plan.Quota", Formatting.Bytes(quota)), Loc.L("Tooltips.Server.Copies.Plan.Quota")));
|
||||
if (plan.LeftOut > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.LeftOut", plan.LeftOut), Loc.L("Tooltips.Server.Copies.Plan.LeftOut")));
|
||||
foreach (var row in _hereProjects.Concat(_thereProjects))
|
||||
row.SetTarget(plan.Projects.FirstOrDefault(p => p.SourceProjectId == row.Project.Id)?.TargetName);
|
||||
blocks.AddRange(plan.Blocks.Select(Block));
|
||||
}
|
||||
else if (_merge is { } merge)
|
||||
{
|
||||
Lasts(merge.LastCopies, here, there);
|
||||
Photos(merge.Photos, PhotoAction.Fetch, PhotoAction.FetchVersion, "Server.Copies.Plan.Receives", here);
|
||||
if (merge.DetailChanges > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Details", merge.DetailChanges)));
|
||||
if (merge.Renders.Count > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Renders", merge.Renders.Count)));
|
||||
if (merge.Projects.Count > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Projects", merge.Projects.Count)));
|
||||
if (merge.SessionKeys.Count > 0)
|
||||
here.Add(new(Loc.L("Server.Copies.Plan.SessionKeys", Formatting.Count(merge.SessionKeys.Count)),
|
||||
string.Join(Environment.NewLine, [Loc.L("Tooltips.Server.Copies.Plan.SessionKeys"), .. merge.SkippedSessionKeys])));
|
||||
foreach (var link in merge.Links) here.Add(new(Loc.L("Server.Copies.Plan.Relink", link), Loc.L("Tooltips.Server.Copies.Plan.Relink")));
|
||||
here.Add(new(Loc.L("Server.Copies.Plan.Free", Formatting.Bytes(merge.FreeBytes)), Loc.L("Tooltips.Server.Copies.Plan.Free")));
|
||||
if (DroppedFacts is { } dropped)
|
||||
there.Add(new(Loc.Plural("Server.Copies.Plan.DropToTrash", dropped.Photos, Formatting.Bytes(dropped.Bytes)), IsWarning: true));
|
||||
blocks.AddRange(merge.Blocks.Select(Block));
|
||||
}
|
||||
if (here.Count + there.Count == 0 && blocks.Count == 0 && (_plan ?? (object?)_merge) is not null) here.Add(new(Loc.L("Server.Copies.Plan.Nothing")));
|
||||
HereLines = here;
|
||||
ThereLines = there;
|
||||
Blocks = blocks;
|
||||
OnPropertyChanged(nameof(HereHeading));
|
||||
OnPropertyChanged(nameof(ThereHeading));
|
||||
OnPropertyChanged(nameof(ApplyToolTip));
|
||||
_apply.RaiseCanExecuteChanged();
|
||||
|
||||
void Lasts(IReadOnlyList<LastCopy> lasts, List<CopyPlanLine> h, List<CopyPlanLine> t)
|
||||
{
|
||||
var mine = lasts.Count(l => l.Side == CopySide.ThisPc);
|
||||
var theirs = lasts.Count - mine;
|
||||
if (mine > 0) h.Add(new(Loc.Plural("Server.Copies.Plan.LastCopies", mine), Loc.L("Tooltips.Server.Copies.Plan.LastCopies"), true));
|
||||
if (theirs > 0) t.Add(new(Loc.Plural("Server.Copies.Plan.LastCopies", theirs), Loc.L("Tooltips.Server.Copies.Plan.LastCopies"), true));
|
||||
}
|
||||
|
||||
static void Photos(IReadOnlyList<PhotoStep> steps, PhotoAction a, PhotoAction b, string key, List<CopyPlanLine> lines)
|
||||
{
|
||||
var moving = steps.Where(s => s.Action == a || s.Action == b).ToList();
|
||||
if (moving.Count > 0) lines.Add(new(Loc.Plural(key, moving.Count, Formatting.Bytes(moving.Sum(s => s.Bytes)))));
|
||||
var kept = steps.Count(s => s.Action == b);
|
||||
if (kept > 0) lines.Add(new(Loc.Plural("Server.Copies.Plan.Versions", kept)));
|
||||
}
|
||||
|
||||
static void Trash(IReadOnlyList<PhotoStep> steps, PhotoAction a, List<CopyPlanLine> lines)
|
||||
{
|
||||
var n = steps.Count(s => s.Action == a);
|
||||
if (n > 0) lines.Add(new(Loc.Plural("Server.Copies.Plan.Trash", n), IsWarning: true));
|
||||
}
|
||||
}
|
||||
|
||||
private CopyBlockLine Block(CopyBlock block)
|
||||
{
|
||||
var need = _plan is { } plan ? Formatting.Bytes(plan.FetchBytes) : _merge is { } merge ? Formatting.Bytes(merge.CopyBytes) : null;
|
||||
var text = CopyText.Block(block, Here.Title, ServerName, need, Unchosen);
|
||||
Action? choose = block switch
|
||||
{
|
||||
CopyBlock.DetailsUnchosen => () => Part = CopyDialogPart.Details,
|
||||
CopyBlock.KeptUnchosen => () => Part = CopyDialogPart.Plan,
|
||||
_ => null,
|
||||
};
|
||||
return new CopyBlockLine(block, text, choose);
|
||||
}
|
||||
|
||||
/// <summary>Integrate (Merge): from another part, on to the part still waiting for a choice; on the plan, confirm and queue.</summary>
|
||||
private async Task ApplyAsync()
|
||||
{
|
||||
if (_part != CopyDialogPart.Plan)
|
||||
{
|
||||
Part = Unchosen > 0 && _part != CopyDialogPart.Details ? CopyDialogPart.Details : CopyDialogPart.Plan;
|
||||
return;
|
||||
}
|
||||
if (_shell.Services.Engine is not { } jobs) return;
|
||||
try
|
||||
{
|
||||
if (_plan is { CanApply: true } plan)
|
||||
{
|
||||
if (plan.Destructive && !_shell.Services.Dialogs.Confirm(ReplaceRequest(plan))) return;
|
||||
IsBusy = true;
|
||||
await _engine.EnqueueIntegrateAsync(jobs, plan, CancellationToken.None);
|
||||
}
|
||||
else if (_merge is { CanApply: true } merge)
|
||||
{
|
||||
if (!_shell.Services.Dialogs.Confirm(MergeRequest(merge))) return;
|
||||
IsBusy = true;
|
||||
await _engine.EnqueueMergeAsync(jobs, merge, CancellationToken.None);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
Close();
|
||||
}
|
||||
catch (StaleCopyPlanException ex)
|
||||
{
|
||||
ShowMessage(ex.Message);
|
||||
SchedulePlan(TimeSpan.Zero);
|
||||
}
|
||||
catch (Exception ex) when (Expected(ex))
|
||||
{
|
||||
ShowError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LinkOnlyAsync()
|
||||
{
|
||||
if (_shell.Services.Sync.Remote is not { } remote) return;
|
||||
IsBusy = true;
|
||||
try
|
||||
{
|
||||
await _engine.LinkAsync(Copy.Id, remote, CancellationToken.None);
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex) when (Expected(ex))
|
||||
{
|
||||
ShowError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Drop…: this version of a Two versions photo goes to the trash of each side that holds it, after a confirmed plan.</summary>
|
||||
private async Task DropAsync(CopyPhotoRow row)
|
||||
{
|
||||
if (row.Photo.Here is not null) await TrashHereAsync([row.Key]);
|
||||
if (row.Photo.There is not null && !IsMerge) await TrashThereAsync([row.Key]);
|
||||
}
|
||||
|
||||
/// <summary>To trash…: the dry run of moving these photos of this PC's copy to its archive trash, the confirmation, then the move.</summary>
|
||||
private async Task TrashHereAsync(IReadOnlyCollection<string> keys)
|
||||
{
|
||||
if (keys.Count == 0) return;
|
||||
IsBusy = true;
|
||||
try
|
||||
{
|
||||
var plan = await _engine.PlanTrashHereAsync(Copy.Id, keys, CancellationToken.None);
|
||||
if (plan.Frames.Count == 0)
|
||||
{
|
||||
ShowMessage(Loc.L("Errors.Copies.NotThere"));
|
||||
return;
|
||||
}
|
||||
var request = TrashRequest(plan.Frames.Count, plan.Frames.Select(f => f.FileName), Loc.L("Tooltips.Server.Copies.ToTrash"), []);
|
||||
if (!_shell.Services.Dialogs.Confirm(request)) return;
|
||||
await _engine.TrashHereAsync(Copy.Id, plan, Copy.Kind == CopyKind.LocalServer ? _shell.Services.Sync.Remote : null, CancellationToken.None);
|
||||
}
|
||||
catch (Exception ex) when (Expected(ex))
|
||||
{
|
||||
ShowError(ex);
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
/// <summary>Delete on server…: the server's dry run, the confirmation, then the move to the server's trash.</summary>
|
||||
private async Task TrashThereAsync(IReadOnlyCollection<string> keys)
|
||||
{
|
||||
if (keys.Count == 0 || _shell.Services.Sync.Remote is not { } remote) return;
|
||||
IsBusy = true;
|
||||
try
|
||||
{
|
||||
var plan = await _engine.PlanTrashThereAsync(Copy.Id, remote, keys, CancellationToken.None);
|
||||
if (plan.Photos == 0)
|
||||
{
|
||||
ShowMessage(Loc.L("Errors.Copies.NotThere"));
|
||||
return;
|
||||
}
|
||||
var names = _review?.Photos.Photos.Where(p => plan.Keys.Contains(p.Key)).Select(p => (p.There ?? p.Here)?.FileName ?? p.Key) ?? plan.Keys;
|
||||
var request = TrashRequest(plan.Photos, names, Loc.L("Tooltips.Server.Copies.DeleteOnServer"), plan.LastCopies);
|
||||
if (!_shell.Services.Dialogs.Confirm(request)) return;
|
||||
await _engine.TrashThereAsync(plan, remote, CancellationToken.None);
|
||||
}
|
||||
catch (Exception ex) when (Expected(ex))
|
||||
{
|
||||
ShowError(ex);
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
/// <summary>"Replace photos?" (design §8.5): the losing versions per side, the last copies named first.</summary>
|
||||
internal static ConfirmRequest ReplaceRequest(IntegratePlan plan)
|
||||
{
|
||||
var trashed = plan.Photos.Where(p => p.Action is PhotoAction.TrashHere or PhotoAction.TrashThere).ToList();
|
||||
return new ConfirmRequest
|
||||
{
|
||||
Heading = Loc.L("Server.Copies.Confirm.Replace.Title"),
|
||||
Message = Loc.Plural("Server.Copies.Confirm.Replace.Message", trashed.Count),
|
||||
Detail = Lines(plan.LastCopies, trashed.Select(p => p.FileName)),
|
||||
SafeText = Loc.L("Archive.Dialog.Cancel"),
|
||||
SafeToolTip = Loc.L("Tooltips.Server.Copies.Confirm.Safe"),
|
||||
ActionText = Loc.L("Server.Copies.Action.IntegrateNow"),
|
||||
ActionToolTip = Loc.L("Tooltips.Server.Copies.Confirm.Replace.Action"),
|
||||
IsDestructive = true,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>"Merge sequences?" (design §8.5): the dropped sequence's facts, the last copies first, the typed photo count.</summary>
|
||||
internal ConfirmRequest MergeRequest(MergePlan plan)
|
||||
{
|
||||
var keep = plan.KeepId == Copy.LocalId ? Here : There;
|
||||
var drop = plan.KeepId == Copy.LocalId ? There : Here;
|
||||
var only = _review?.Photos.Of(plan.KeepId == Copy.LocalId ? PhotoClass.OnlyThere : PhotoClass.OnlyHere).Count() ?? 0;
|
||||
var facts = new List<string> { Loc.Plural("Server.Copies.Plan.DropToTrash", drop.Photos, Formatting.Bytes(drop.Bytes)) };
|
||||
if (only > 0) facts.Add(Loc.Plural("Server.Copies.Confirm.Merge.OnlyHere", only, drop.Where));
|
||||
if (plan.Renders.Count > 0) facts.Add(Loc.Plural("Server.Copies.Plan.Renders", plan.Renders.Count));
|
||||
if (plan.Projects.Count > 0) facts.Add(Loc.Plural("Server.Copies.Plan.Projects", plan.Projects.Count));
|
||||
return new ConfirmRequest
|
||||
{
|
||||
Heading = Loc.L("Server.Copies.Confirm.Merge.Title"),
|
||||
Message = Loc.L("Server.Copies.Confirm.Merge.Message", drop.Title, drop.Where, keep.Where),
|
||||
Detail = Lines(plan.LastCopies, facts),
|
||||
SafeText = Loc.L("Archive.Dialog.Cancel"),
|
||||
SafeToolTip = Loc.L("Tooltips.Server.Copies.Confirm.Safe"),
|
||||
ActionText = Loc.L("Server.Copies.Action.Merge"),
|
||||
ActionToolTip = Loc.L("Tooltips.Server.Copies.Confirm.Merge.Action"),
|
||||
IsDestructive = true,
|
||||
TypedConfirmation = drop.Photos.ToString(Loc.Culture),
|
||||
TypedPrompt = Loc.L("Server.Copies.Confirm.Merge.TypedPrompt", drop.Title),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>To trash… and Delete on server…: as the Library's delete confirmation, with the last copies named first.</summary>
|
||||
private static ConfirmRequest TrashRequest(int photos, IEnumerable<string> names, string message, IReadOnlyList<LastCopy> lasts) => new()
|
||||
{
|
||||
Heading = Loc.Plural("Server.Copies.Plan.Trash", photos),
|
||||
Message = message,
|
||||
Detail = Lines(lasts, names),
|
||||
DetailToolTip = Loc.L("Tooltips.Archive.DeletePlan"),
|
||||
SafeText = Loc.L("Archive.Delete.Keep"),
|
||||
SafeToolTip = Loc.L("Tooltips.Archive.DeleteKeep"),
|
||||
ActionText = Loc.L("Archive.Delete.Action"),
|
||||
ActionToolTip = message,
|
||||
IsDestructive = true,
|
||||
};
|
||||
|
||||
private static string Lines(IReadOnlyList<LastCopy> lasts, IEnumerable<string> rest)
|
||||
{
|
||||
const int Listed = 10;
|
||||
var all = lasts.Select(l => Loc.L("Server.Copies.Confirm.LastCopy", l.FileName)).Concat(rest).ToList();
|
||||
var lines = all.Take(Listed).ToList();
|
||||
if (all.Count > Listed) lines.Add(Loc.Plural("Archive.Delete.More", all.Count - Listed));
|
||||
return string.Join(Environment.NewLine, lines);
|
||||
}
|
||||
|
||||
/// <summary>The policies of the Photos ComboBox: a merge's two "wins" name the kept and the other sequence.</summary>
|
||||
internal static IReadOnlyList<SettingsOption<CopyPhotoPolicy>> PolicyOptions(bool merge) =>
|
||||
[
|
||||
new(CopyPhotoPolicy.Union, Loc.L("Server.Copies.Policy.Union"), Loc.L("Tooltips.Server.Copies.Policy.Union")),
|
||||
new(CopyPhotoPolicy.ChoosePerPhoto, Loc.L("Server.Copies.Policy.ChoosePerPhoto"), Loc.L("Tooltips.Server.Copies.Policy.ChoosePerPhoto")),
|
||||
new(CopyPhotoPolicy.ThisPcWins, Loc.L(merge ? "Server.Copies.Policy.KeptWins" : "Server.Copies.Policy.ThisPcWins"),
|
||||
Loc.L(merge ? "Tooltips.Server.Copies.Policy.KeptWins" : "Tooltips.Server.Copies.Policy.ThisPcWins")),
|
||||
new(CopyPhotoPolicy.OtherWins, Loc.L(merge ? "Server.Copies.Policy.OtherCopyWins" : "Server.Copies.Policy.OtherWins"),
|
||||
Loc.L(merge ? "Tooltips.Server.Copies.Policy.OtherCopyWins" : "Tooltips.Server.Copies.Policy.OtherWins")),
|
||||
];
|
||||
|
||||
/// <summary>The choices of a Different photo under Choose each.</summary>
|
||||
internal static IReadOnlyList<SettingsOption<PhotoChoice>> VersionChoices(bool merge) =>
|
||||
[
|
||||
new(PhotoChoice.KeepBoth, Loc.L("Server.Copies.Version.Both"), Loc.L("Tooltips.Server.Copies.Version")),
|
||||
new(PhotoChoice.TakeHere, Loc.L(merge ? "Server.Copies.Detail.Kept" : "Server.Copies.Version.Here"), Loc.L("Tooltips.Server.Copies.Version")),
|
||||
new(PhotoChoice.TakeThere, Loc.L(merge ? "Server.Copies.Detail.Other" : "Server.Copies.Version.There"), Loc.L("Tooltips.Server.Copies.Version")),
|
||||
new(PhotoChoice.Leave, Loc.L("Server.Copies.Version.Leave"), Loc.L("Tooltips.Server.Copies.Version")),
|
||||
];
|
||||
|
||||
private static bool Expected(Exception ex) =>
|
||||
ex is Data.DatabaseException or InvalidOperationException or System.Net.Http.HttpRequestException or System.IO.IOException or UnauthorizedAccessException;
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Chronos.Ui.Controls;assembly=Chronos.Ui"
|
||||
xmlns:v="clr-namespace:Chronos.Ui.Visuals;assembly=Chronos.Ui"
|
||||
xmlns:l="clr-namespace:Chronos.Ui.Localization;assembly=Chronos.Ui"
|
||||
xmlns:infra="clr-namespace:Chronos.App.Infrastructure"
|
||||
xmlns:cp="clr-namespace:Chronos.App.Server.Copies">
|
||||
<!-- Compare sequences / Merge sequences (owner review 6, #73, design §8.2): Photos · Details · Projects · Plan, two footer buttons. -->
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/Chronos;component/Archive/ArchiveDialogs.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<BooleanToVisibilityConverter x:Key="CopyBoolToVisibility" />
|
||||
|
||||
<!-- A choice of a dropdown says what it does in its tooltip. -->
|
||||
<Style x:Key="ComboBoxItem.Option" TargetType="ComboBoxItem" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
|
||||
<Setter Property="ToolTip" Value="{Binding ToolTip}" />
|
||||
</Style>
|
||||
|
||||
<!-- Rows of the dialog's lists read as their text; Tab goes to their controls. -->
|
||||
<Style x:Key="ListBoxItem.CopyPhoto" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem.Row}">
|
||||
<Setter Property="AutomationProperties.Name" Value="{Binding Name}" />
|
||||
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
|
||||
</Style>
|
||||
<Style x:Key="ListBoxItem.CopyClass" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem.Row}">
|
||||
<Setter Property="AutomationProperties.Name" Value="{Binding Text}" />
|
||||
<Setter Property="ToolTip" Value="{Binding ToolTip}" />
|
||||
</Style>
|
||||
|
||||
<DataTemplate DataType="{x:Type cp:CopyDialogViewModel}">
|
||||
<Border Style="{StaticResource Border.Dialog}" Width="920" MaxHeight="600">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="{Binding Heading}" Style="{StaticResource Text.Title}" TextTrimming="CharacterEllipsis" ToolTip="{Binding Heading}" />
|
||||
<!-- Both sides: this PC, then the server (or the other archive). -->
|
||||
<Grid Grid.Row="1" Margin="0,10,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding HereText}" ToolTip="{Binding HereText}" TextTrimming="CharacterEllipsis" Typography.NumeralAlignment="Tabular" />
|
||||
<TextBlock Grid.Column="1" Text="▸" Foreground="{DynamicResource Brush.TextFaint}" Margin="10,0" />
|
||||
<TextBlock Grid.Column="2" Text="{Binding ThereText}" ToolTip="{Binding ThereText}" TextTrimming="CharacterEllipsis" Typography.NumeralAlignment="Tabular" />
|
||||
</Grid>
|
||||
<v:SegmentedControl Grid.Row="2" HorizontalAlignment="Left" Margin="0,12,0,10" SelectedIndex="{Binding PartIndex}"
|
||||
IsEnabled="{Binding IsLoaded}" AutomationProperties.Name="{Binding Heading}">
|
||||
<v:SegmentedItem Content="{l:Loc Server.Copies.Part.Photos}" ToolTip="{l:Loc Tooltips.Server.Copies.Compare}" AutomationProperties.Name="{l:Loc Server.Copies.Part.Photos}" />
|
||||
<v:SegmentedItem Content="{l:Loc Server.Copies.Part.Details}" ToolTip="{l:Loc Tooltips.Server.Copies.Detail}" AutomationProperties.Name="{l:Loc Server.Copies.Part.Details}" />
|
||||
<v:SegmentedItem Content="{l:Loc Server.Copies.Part.Projects}" ToolTip="{Binding ProjectsToolTip}" AutomationProperties.Name="{l:Loc Server.Copies.Part.Projects}" />
|
||||
<v:SegmentedItem Content="{l:Loc Server.Copies.Part.Plan}" ToolTip="{Binding ApplyToolTip}" AutomationProperties.Name="{l:Loc Server.Copies.Part.Plan}" />
|
||||
</v:SegmentedControl>
|
||||
|
||||
<Grid Grid.Row="3" MinHeight="240">
|
||||
<!-- Photos: the policy, the class table and the photos of the selected class. -->
|
||||
<Grid Visibility="{Binding IsPhotos, Converter={StaticResource CopyBoolToVisibility}}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="300" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,8">
|
||||
<TextBlock Text="{l:Loc Server.Copies.Policy.Label}" Style="{StaticResource Text.DialogLabel}" VerticalAlignment="Center" Margin="0,0,10,0" />
|
||||
<ComboBox Width="170" ItemsSource="{Binding Policies}" SelectedItem="{Binding Policy}" DisplayMemberPath="Label" ToolTip="{Binding PolicyToolTip}"
|
||||
ItemContainerStyle="{StaticResource ComboBoxItem.Option}" AutomationProperties.Name="{l:Loc Server.Copies.Policy.Label}" />
|
||||
</StackPanel>
|
||||
<ListBox Grid.Row="1" ItemsSource="{Binding Classes}" SelectedItem="{Binding SelectedClass}" ItemContainerStyle="{StaticResource ListBoxItem.CopyClass}"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled" AutomationProperties.Name="{l:Loc Server.Copies.Part.Photos}" Margin="0,0,14,0">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyClassRow}">
|
||||
<Grid Height="28">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="56" />
|
||||
<ColumnDefinition Width="70" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:StatusGlyph Kind="{Binding Kind}" Text="{Binding Text}" FontSize="12" VerticalAlignment="Center" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding CountText}" TextAlignment="Right" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" />
|
||||
<TextBlock Grid.Column="2" Text="{Binding HereBytesText}" TextAlignment="Right" VerticalAlignment="Center" Foreground="{DynamicResource Brush.TextMuted}"
|
||||
Typography.NumeralAlignment="Tabular" FontSize="12" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<!-- Bring all / Bring none, All: keep both, To trash…, Delete on server…: above the list they act on. -->
|
||||
<WrapPanel Grid.Column="1" VerticalAlignment="Center" Margin="0,0,0,8">
|
||||
<Button Style="{StaticResource Button.Link}" Content="{l:Loc Server.Copies.Photo.BringAll}" Command="{Binding BringAllCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Server.Copies.BringAll}" Margin="0,0,14,0" Visibility="{Binding CanBringAll, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
<Button Style="{StaticResource Button.Link}" Content="{l:Loc Server.Copies.Photo.BringNone}" Command="{Binding BringNoneCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Server.Copies.BringNone}" Margin="0,0,14,0" Visibility="{Binding CanBringAll, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
<Button Style="{StaticResource Button.Link}" Content="{l:Loc Server.Copies.Photo.AllBoth}" Command="{Binding AllBothCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Server.Copies.AllBoth}" Margin="0,0,14,0" Visibility="{Binding CanKeepAllBoth, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
<Button Style="{StaticResource Button.Row}" Content="{l:Loc Server.Copies.Action.ToTrash}" Command="{Binding TrashCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Server.Copies.ToTrash}" ToolTipService.ShowOnDisabled="True" Margin="0,0,8,0"
|
||||
Visibility="{Binding CanTrashHere, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
<Button Style="{StaticResource Button.Row}" Content="{l:Loc Server.Copies.Action.DeleteOnServer}" Command="{Binding DeleteThereCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Server.Copies.DeleteOnServer}" ToolTipService.ShowOnDisabled="True"
|
||||
Visibility="{Binding CanDeleteThere, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
</WrapPanel>
|
||||
<ListBox Grid.Row="1" Grid.Column="1" ItemsSource="{Binding Photos}" ItemContainerStyle="{StaticResource ListBoxItem.CopyPhoto}" SelectionMode="Extended"
|
||||
VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling" VirtualizingPanel.ScrollUnit="Pixel"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled" KeyboardNavigation.TabNavigation="Continue"
|
||||
AutomationProperties.Name="{Binding SelectedClass.Text}" Visibility="{Binding HasPhotos, Converter={StaticResource CopyBoolToVisibility}}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyPhotoRow}">
|
||||
<Grid MinHeight="28" ToolTip="{Binding ToolTip}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="150" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="80" />
|
||||
<ColumnDefinition Width="110" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox IsChecked="{Binding Bring}" ToolTip="{l:Loc Tooltips.Server.Copies.Bring}" AutomationProperties.Name="{Binding BringAccessibleName}"
|
||||
VerticalAlignment="Center" Margin="0,0,8,0" Visibility="{Binding CanBring, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding TimeText}" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" FontSize="12" />
|
||||
<TextBlock Grid.Column="2" Text="{Binding Name}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" FlowDirection="LeftToRight" FontSize="12" />
|
||||
<TextBlock Grid.Column="3" Text="{Binding SizeText}" VerticalAlignment="Center" TextAlignment="Right" Typography.NumeralAlignment="Tabular" FontSize="12" />
|
||||
<TextBlock Grid.Column="4" Text="{Binding SideText}" VerticalAlignment="Center" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0"
|
||||
TextTrimming="CharacterEllipsis" FontSize="12" />
|
||||
<ComboBox Grid.Column="5" Width="120" ItemsSource="{Binding Choices}" SelectedItem="{Binding Choice}" DisplayMemberPath="Label"
|
||||
ItemContainerStyle="{StaticResource ComboBoxItem.Option}" ToolTip="{l:Loc Tooltips.Server.Copies.Version}"
|
||||
AutomationProperties.Name="{Binding ChoiceAccessibleName}" Visibility="{Binding CanChoose, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
<Button Grid.Column="5" Style="{StaticResource Button.Row}" Content="{l:Loc Server.Copies.Action.Drop}" Command="{Binding DropCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Server.Copies.Drop}" AutomationProperties.Name="{Binding DropAccessibleName}" FontSize="12"
|
||||
Visibility="{Binding CanDrop, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding PhotosEmptyText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,8,0,0"
|
||||
Visibility="{Binding PhotosEmptyText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
|
||||
</Grid>
|
||||
|
||||
<!-- Details: one line per difference, nothing preselected. -->
|
||||
<Grid Visibility="{Binding IsDetails, Converter={StaticResource CopyBoolToVisibility}}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,8" Visibility="{Binding HasDetails, Converter={StaticResource CopyBoolToVisibility}}">
|
||||
<Button Style="{StaticResource Button.Link}" Content="{Binding AllHereText}" Command="{Binding AllHereCommand}" ToolTip="{l:Loc Tooltips.Server.Copies.Detail.All}" Margin="0,0,14,0" />
|
||||
<Button Style="{StaticResource Button.Link}" Content="{Binding AllThereText}" Command="{Binding AllThereCommand}" ToolTip="{l:Loc Tooltips.Server.Copies.Detail.All}" />
|
||||
</StackPanel>
|
||||
<ItemsControl Grid.Row="1" ItemsSource="{Binding Details}" Focusable="False" Visibility="{Binding HasDetails, Converter={StaticResource CopyBoolToVisibility}}">
|
||||
<ItemsControl.Template>
|
||||
<ControlTemplate TargetType="ItemsControl">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" Focusable="False">
|
||||
<ItemsPresenter />
|
||||
</ScrollViewer>
|
||||
</ControlTemplate>
|
||||
</ItemsControl.Template>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyDetailRow}">
|
||||
<Grid Margin="0,0,0,6">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="180" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding Label}" Style="{StaticResource Text.DialogLabel}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" ToolTip="{Binding Label}" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding HereText}" ToolTip="{Binding HereToolTip}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" Margin="10,0,0,0" />
|
||||
<TextBlock Grid.Column="2" Text="{Binding ThereText}" ToolTip="{Binding ThereToolTip}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" Margin="10,0,0,0" />
|
||||
<v:SegmentedControl Grid.Column="3" SelectedIndex="{Binding ChoiceIndex}" ToolTip="{Binding ToolTip}" AutomationProperties.Name="{Binding AccessibleName}" Margin="10,0,0,0">
|
||||
<v:SegmentedItem Content="{Binding HereWord}" ToolTip="{Binding HereToolTip}" AutomationProperties.Name="{Binding HereWord}" />
|
||||
<v:SegmentedItem Content="{Binding ThereWord}" ToolTip="{Binding ThereToolTip}" AutomationProperties.Name="{Binding ThereWord}" />
|
||||
</v:SegmentedControl>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<TextBlock Grid.Row="1" Text="{Binding DetailsEmptyText}" Foreground="{DynamicResource Brush.TextMuted}"
|
||||
Visibility="{Binding DetailsEmptyText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
|
||||
</Grid>
|
||||
|
||||
<!-- Projects: Copy across or Leave them; each side's projects, and where each goes. -->
|
||||
<Grid Visibility="{Binding IsProjects, Converter={StaticResource CopyBoolToVisibility}}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<v:SegmentedControl Grid.ColumnSpan="2" HorizontalAlignment="Left" SelectedIndex="{Binding ProjectsIndex}" IsEnabled="{Binding CanChooseProjects}"
|
||||
ToolTip="{Binding ProjectsToolTip}" ToolTipService.ShowOnDisabled="True" AutomationProperties.Name="{l:Loc Server.Copies.Part.Projects}" Margin="0,0,0,10">
|
||||
<v:SegmentedItem Content="{l:Loc Server.Copies.Projects.CopyAcross}" ToolTip="{l:Loc Tooltips.Server.Copies.Projects.CopyAcross}" AutomationProperties.Name="{l:Loc Server.Copies.Projects.CopyAcross}" />
|
||||
<v:SegmentedItem Content="{l:Loc Server.Copies.Projects.Leave}" ToolTip="{l:Loc Tooltips.Server.Copies.Projects.Leave}" AutomationProperties.Name="{l:Loc Server.Copies.Projects.Leave}" />
|
||||
</v:SegmentedControl>
|
||||
<TextBlock Grid.Row="1" Grid.ColumnSpan="2" Text="{Binding ProjectsNote}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,0,0,8"
|
||||
Visibility="{Binding ProjectsNote, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
|
||||
<ItemsControl Grid.Row="2" ItemsSource="{Binding HereProjects}" Focusable="False" Margin="0,0,14,0">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyProjectRow}">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,6" ToolTip="{Binding ToolTip}">
|
||||
<TextBlock Text="{Binding Name}" FontWeight="SemiBold" />
|
||||
<TextBlock Text="{Binding VersionsText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0" />
|
||||
<TextBlock Text="{Binding ChangedText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0" />
|
||||
<TextBlock Text="{Binding TargetText}" Foreground="{DynamicResource Brush.Accent}" Margin="10,0,0,0" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<ItemsControl Grid.Row="2" Grid.Column="1" ItemsSource="{Binding ThereProjects}" Focusable="False">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyProjectRow}">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,6" ToolTip="{Binding ToolTip}">
|
||||
<TextBlock Text="{Binding Name}" FontWeight="SemiBold" />
|
||||
<TextBlock Text="{Binding VersionsText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0" />
|
||||
<TextBlock Text="{Binding ChangedText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0" />
|
||||
<TextBlock Text="{Binding TargetText}" Foreground="{DynamicResource Brush.Accent}" Margin="10,0,0,0" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
|
||||
<!-- Plan: the kept sequence (merge), what each side receives and loses, the blocks with their one action, Link only. -->
|
||||
<ScrollViewer Visibility="{Binding IsPlan, Converter={StaticResource CopyBoolToVisibility}}" VerticalScrollBarVisibility="Auto" Focusable="False">
|
||||
<StackPanel>
|
||||
<StackPanel Visibility="{Binding HasKeepOptions, Converter={StaticResource CopyBoolToVisibility}}" Margin="0,0,0,10">
|
||||
<TextBlock Text="{l:Loc Server.Copies.Plan.KeptCopy}" Style="{StaticResource Text.DialogLabel}" Margin="0,0,0,4" />
|
||||
<ItemsControl ItemsSource="{Binding KeepOptions}" Focusable="False">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyKeepOption}">
|
||||
<RadioButton GroupName="CopyKeep" Content="{Binding Text}" IsChecked="{Binding IsChecked}" ToolTip="{Binding ToolTip}"
|
||||
AutomationProperties.Name="{Binding AccessibleName}" Margin="0,2" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Margin="0,0,14,0">
|
||||
<TextBlock Text="{Binding HereHeading}" FontWeight="SemiBold" Margin="0,0,0,6" TextTrimming="CharacterEllipsis" ToolTip="{Binding HereHeading}" />
|
||||
<ItemsControl ItemsSource="{Binding HereLines}" Focusable="False">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyPlanLine}">
|
||||
<ui:StatusGlyph Kind="{Binding Kind}" Text="{Binding Text}" ToolTip="{Binding ShownToolTip}" FontSize="12" Margin="0,0,0,4" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="1">
|
||||
<TextBlock Text="{Binding ThereHeading}" FontWeight="SemiBold" Margin="0,0,0,6" TextTrimming="CharacterEllipsis" ToolTip="{Binding ThereHeading}" />
|
||||
<ItemsControl ItemsSource="{Binding ThereLines}" Focusable="False">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyPlanLine}">
|
||||
<ui:StatusGlyph Kind="{Binding Kind}" Text="{Binding Text}" ToolTip="{Binding ShownToolTip}" FontSize="12" Margin="0,0,0,4" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<ItemsControl ItemsSource="{Binding Blocks}" Focusable="False" Margin="0,10,0,0">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyBlockLine}">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,6">
|
||||
<ui:StatusGlyph Kind="Error" Text="{Binding Text}" ToolTip="{Binding Text}" FontSize="12" VerticalAlignment="Center"
|
||||
AutomationProperties.LiveSetting="Assertive" infra:LiveRegion.Text="{Binding Text}" />
|
||||
<Button Style="{StaticResource Button.Link}" Content="{Binding ChooseText}" Command="{Binding ChooseCommand}" ToolTip="{Binding ChooseToolTip}"
|
||||
Margin="10,0,0,0" Visibility="{Binding HasChoose, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<Button Style="{StaticResource Button.Row}" HorizontalAlignment="Left" Content="{Binding LinkOnlyText}" Command="{Binding LinkOnlyCommand}"
|
||||
ToolTip="{Binding LinkOnlyToolTip}" Margin="0,10,0,0" Visibility="{Binding ShowLinkOnly, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
|
||||
<!-- Footer: a failure (or Planning…), then Cancel and Integrate (Merge). -->
|
||||
<DockPanel Grid.Row="4" Margin="0,14,0,0" LastChildFill="True">
|
||||
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Primary}" Content="{Binding ApplyText}" Command="{Binding ApplyCommand}"
|
||||
ToolTip="{Binding ApplyToolTip}" ToolTipService.ShowOnDisabled="True" MinWidth="96" Margin="8,0,0,0" />
|
||||
<Button DockPanel.Dock="Right" Content="{l:Loc Archive.Dialog.Cancel}" Command="{Binding CloseCommand}" ToolTip="{Binding CancelToolTip}"
|
||||
IsDefault="True" IsCancel="True" MinWidth="96" />
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<ui:StatusGlyph Style="{StaticResource Status.DialogError}" />
|
||||
<TextBlock Style="{StaticResource Text.Live}" Text="{Binding PlanningText}" infra:LiveRegion.Text="{Binding PlanningText}"
|
||||
Visibility="{Binding PlanningText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
|
||||
<TextBlock Style="{StaticResource Text.Live}" Text="{Binding BusyText}" infra:LiveRegion.Text="{Binding BusyText}"
|
||||
Visibility="{Binding BusyText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,426 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using Chronos.App.Archiving;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Shell;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Ui.Controls;
|
||||
using Chronos.Ui.Mvvm;
|
||||
using Chronos.Ui.Visuals;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>
|
||||
/// Server › Matches (owner review 6, #73, design §8.1): the pairs of this server and of this PC's archives with both sides,
|
||||
/// their state and actions, Find matches, the toasts of detection runs (with Review), Unlink and Keep apart with Undo, the
|
||||
/// Library's "Also elsewhere" status and the Compare dialog. Reloads when the engine or a job of its kinds changes. UI thread.
|
||||
/// </summary>
|
||||
public sealed class CopyListViewModel : ObservableObject, IDisposable
|
||||
{
|
||||
private readonly ShellViewModel _shell;
|
||||
private readonly AsyncRelayCommand _find;
|
||||
private readonly SemaphoreSlim _reloading = new(1, 1);
|
||||
private readonly Dictionary<Guid, int> _deletedThere = [];
|
||||
private IReadOnlyList<FoundCopyView> _pairs = [];
|
||||
private ICopyEngine? _engine;
|
||||
private string _search = string.Empty;
|
||||
private int _reloadQueued;
|
||||
private bool _loaded;
|
||||
private bool _attached;
|
||||
|
||||
public CopyListViewModel(ShellViewModel shell)
|
||||
{
|
||||
_shell = shell;
|
||||
_find = new AsyncRelayCommand(FindAsync, () => Engine is not null && !IsFinding);
|
||||
}
|
||||
|
||||
public ObservableCollection<CopyRow> Rows { get; } = [];
|
||||
|
||||
/// <summary>Every listed pair of this server and of this PC's archives (the chip's count).</summary>
|
||||
public IReadOnlyList<FoundCopyView> Pairs => _pairs;
|
||||
|
||||
/// <summary>"Find matches": looks for pairs on the signed-in server and among this PC's archives now.</summary>
|
||||
public ICommand FindCommand => _find;
|
||||
|
||||
public string FindToolTip => Host.Server is not null
|
||||
? Loc.L("Tooltips.Server.Copies.Find", ServerName ?? Host.Server)
|
||||
: Loc.L("Tooltips.Server.Copies.FindLocal");
|
||||
|
||||
public bool IsFinding { get; private set; }
|
||||
|
||||
public int Count => _pairs.Count;
|
||||
|
||||
/// <summary>Pairs asking for a choice: the chip turns to the warning colours and the rail badge counts them.</summary>
|
||||
public int AttentionCount => _pairs.Count(p => p.Copy.NeedsAttention);
|
||||
|
||||
public bool HasRows => Rows.Count > 0;
|
||||
|
||||
/// <summary>"No matches found.": the empty list's one sentence (its one button is Find matches).</summary>
|
||||
public string? EmptyText => HasRows ? null : Loc.L(_pairs.Count == 0 ? "Server.Copies.Empty" : "Server.Sync.NoMatch");
|
||||
|
||||
public bool IsEmpty => !HasRows;
|
||||
|
||||
/// <summary>Opens a dialog over the Server section (set by <c>ServerViewModel</c>).</summary>
|
||||
internal Action<ArchiveDialogViewModel>? OpenDialog { get; set; }
|
||||
|
||||
/// <summary>Closes a dialog of the Server section.</summary>
|
||||
internal Action<ArchiveDialogViewModel>? CloseDialog { get; set; }
|
||||
|
||||
/// <summary>Shows the Matches chip (set by the sync table).</summary>
|
||||
internal Action<string?>? ShowList { get; set; }
|
||||
|
||||
/// <summary>The search text of the sync table, applied to both titles of a pair.</summary>
|
||||
public string SearchText
|
||||
{
|
||||
get => _search;
|
||||
set
|
||||
{
|
||||
if (Set(ref _search, value ?? string.Empty)) ApplyFilter();
|
||||
}
|
||||
}
|
||||
|
||||
internal ICopyEngine? Engine => Host.Copies;
|
||||
|
||||
private SyncHost Host => _shell.Services.Sync;
|
||||
|
||||
private string? ServerName => _shell.Services.Server.IsConnected ? _shell.Services.Server.Flow.Info?.Name : null;
|
||||
|
||||
/// <summary>The server announces what an Integrate needs (photo lookup and upload into a sequence).</summary>
|
||||
private bool CanIntegrate => _shell.Services.Server.IsConnected && _shell.Services.Server.Flow.Info?.Capabilities is { } capabilities
|
||||
&& capabilities.Contains(ServerCapabilities.PhotoLookup) && capabilities.Contains(ServerCapabilities.UploadInto);
|
||||
|
||||
private CopyRights Rights => new(Host.Server, ServerName, CanIntegrate, Host.CanUpload);
|
||||
|
||||
/// <summary>Raised after each reload (the chip count, the rail badge and the sync rows' marks follow it).</summary>
|
||||
public event Action? Changed;
|
||||
|
||||
public void Attach()
|
||||
{
|
||||
if (_attached) return;
|
||||
_attached = true;
|
||||
Host.CopiesChanged += OnEngineChanged;
|
||||
Host.Changed += OnHostChanged;
|
||||
Loc.CultureChanged += OnCultureChanged;
|
||||
if (_shell.Services.Jobs is { } jobs)
|
||||
{
|
||||
jobs.JobChanged += OnJobChanged;
|
||||
jobs.Progress += OnProgress;
|
||||
}
|
||||
Follow(Engine);
|
||||
_ = ReloadAsync();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_attached) return;
|
||||
_attached = false;
|
||||
Host.CopiesChanged -= OnEngineChanged;
|
||||
Host.Changed -= OnHostChanged;
|
||||
Loc.CultureChanged -= OnCultureChanged;
|
||||
if (_shell.Services.Jobs is { } jobs)
|
||||
{
|
||||
jobs.JobChanged -= OnJobChanged;
|
||||
jobs.Progress -= OnProgress;
|
||||
}
|
||||
Follow(null);
|
||||
}
|
||||
|
||||
/// <summary>The pair the sequence is in (this server's or a local one), the one asking for a choice first; null when none.</summary>
|
||||
public FoundCopy? PairOf(Guid sequenceId) => _pairs
|
||||
.Where(p => p.Copy.LocalId == sequenceId || p.Copy.OtherId == sequenceId || p.Copy.RemoteId == sequenceId)
|
||||
.OrderByDescending(p => p.Copy.NeedsAttention)
|
||||
.Select(p => p.Copy)
|
||||
.FirstOrDefault();
|
||||
|
||||
/// <summary>Reads the pairs again; requests made while a pass runs share the next one.</summary>
|
||||
public async Task ReloadAsync()
|
||||
{
|
||||
Interlocked.Exchange(ref _reloadQueued, 1);
|
||||
await _reloading.WaitAsync();
|
||||
try
|
||||
{
|
||||
while (Interlocked.Exchange(ref _reloadQueued, 0) == 1)
|
||||
{
|
||||
var server = Host.Server;
|
||||
var all = Engine is { } engine ? await engine.ListAsync(CancellationToken.None) : [];
|
||||
_pairs = [.. CopyText.Sorted(all.Where(p => p.Copy.Kind == CopyKind.LocalLocal
|
||||
|| string.Equals(p.Copy.Server, server, StringComparison.OrdinalIgnoreCase)))];
|
||||
AnnounceDeletions();
|
||||
ApplyFilter();
|
||||
UpdateLibrary();
|
||||
RaiseCounts();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is Data.DatabaseException or InvalidOperationException or System.Net.Http.HttpRequestException)
|
||||
{
|
||||
Log.Warning("copies", "The matches could not be read", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_reloading.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Opens the Compare dialog of the pair the sequence is in (Library › Compare…); false when it is in none.</summary>
|
||||
public bool Compare(Guid sequenceId)
|
||||
{
|
||||
if (_pairs.FirstOrDefault(p => p.Copy.Id == PairOf(sequenceId)?.Id) is not { } pair) return false;
|
||||
Open(pair, CopyDialogPart.Photos);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Opens the Compare dialog of <paramref name="pair"/> at <paramref name="part"/> (and a photo class).</summary>
|
||||
internal CopyDialogViewModel? Open(FoundCopyView pair, CopyDialogPart part, PhotoClass? photos = null, bool integrate = false)
|
||||
{
|
||||
if (Engine is not { } engine || OpenDialog is not { } open) return null;
|
||||
var dialog = new CopyDialogViewModel(_shell, engine, pair, Rights, part, photos, integrate, d => CloseDialog?.Invoke(d));
|
||||
open(dialog);
|
||||
_ = dialog.LoadAsync();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private void ApplyFilter()
|
||||
{
|
||||
var rights = Rights;
|
||||
var wanted = _pairs.Where(p => CopyText.Matches(p, _search.Trim())).ToList();
|
||||
var byId = Rows.ToDictionary(r => r.Id);
|
||||
Rows.Clear();
|
||||
foreach (var pair in wanted)
|
||||
{
|
||||
if (byId.TryGetValue(pair.Copy.Id, out var row)) row.Update(pair, rights);
|
||||
else row = new CopyRow(pair, rights, ActAsync);
|
||||
Rows.Add(row);
|
||||
}
|
||||
OnPropertyChanged(nameof(HasRows));
|
||||
OnPropertyChanged(nameof(IsEmpty));
|
||||
OnPropertyChanged(nameof(EmptyText));
|
||||
}
|
||||
|
||||
private void RaiseCounts()
|
||||
{
|
||||
OnPropertyChanged(nameof(Pairs));
|
||||
OnPropertyChanged(nameof(Count));
|
||||
OnPropertyChanged(nameof(AttentionCount));
|
||||
OnPropertyChanged(nameof(FindToolTip));
|
||||
_find.RaiseCanExecuteChanged();
|
||||
Changed?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>The Library's cards and rows of local sequences in pairs that ask for a choice take "Also elsewhere" or "Deleted there".</summary>
|
||||
private void UpdateLibrary()
|
||||
{
|
||||
foreach (var item in _shell.Library.Items)
|
||||
{
|
||||
var pair = _pairs.FirstOrDefault(p => p.Copy.NeedsAttention && (p.Copy.LocalId == item.Id || p.Copy.OtherId == item.Id));
|
||||
item.SetMatch(pair is null ? null : LibraryStatus(pair, item.Id));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The card status of a sequence of <paramref name="pair"/>.</summary>
|
||||
internal static CardStatus LibraryStatus(FoundCopyView pair, Guid sequenceId)
|
||||
{
|
||||
var copy = pair.Copy;
|
||||
if (copy.RemoteGone || copy.Score.DeletedThere > 0)
|
||||
return new CardStatus(StatusKind.Warning, Loc.L("Library.Status.DeletedThere"),
|
||||
Loc.L("Tooltips.Library.Status.DeletedThere", pair.There.Where));
|
||||
var other = copy.Kind == CopyKind.LocalLocal && copy.OtherId == sequenceId ? pair.Here : pair.There;
|
||||
return new CardStatus(StatusKind.Warning, Loc.L("Library.Status.CopyFound"), copy.Kind == CopyKind.LocalServer
|
||||
? Loc.L("Tooltips.Library.Status.CopyFound", other.Where, CopyText.SharedPercent(copy.Score))
|
||||
: Loc.L("Tooltips.Library.Status.CopyFoundLocal", other.Where));
|
||||
}
|
||||
|
||||
/// <summary>An integrated pair with newly deleted photos on the other side: "3 photos deleted on nas" · Review.</summary>
|
||||
private void AnnounceDeletions()
|
||||
{
|
||||
foreach (var pair in _pairs)
|
||||
{
|
||||
var now = pair.Copy.State == CopyState.Integrated ? pair.Copy.Score.DeletedThere : 0;
|
||||
var before = _deletedThere.GetValueOrDefault(pair.Copy.Id);
|
||||
_deletedThere[pair.Copy.Id] = now;
|
||||
if (!_loaded || now <= before) continue;
|
||||
var shown = pair;
|
||||
_shell.Notify(Loc.Plural("Server.Copies.DeletedToast", now - before, pair.There.Where), null, Loc.L("Server.Copies.Action.Review"),
|
||||
Loc.L("Tooltips.Server.Copies.Review"), () => Review(shown));
|
||||
}
|
||||
_loaded = true;
|
||||
}
|
||||
|
||||
private void Review(FoundCopyView pair)
|
||||
{
|
||||
_shell.Navigate(SectionKey.Server);
|
||||
ShowList?.Invoke(null);
|
||||
Open(pair, CopyDialogPart.Photos, PhotoClass.DeletedThere);
|
||||
}
|
||||
|
||||
private async Task FindAsync()
|
||||
{
|
||||
if (Engine is not { } engine) return;
|
||||
IsFinding = true;
|
||||
_find.RaiseCanExecuteChanged();
|
||||
try
|
||||
{
|
||||
var found = await engine.FindAsync(Host.Remote, CancellationToken.None);
|
||||
if (found.IsEmpty) _shell.Notify(Loc.L("Server.Copies.Empty"));
|
||||
else Announce(found);
|
||||
}
|
||||
catch (Exception ex) when (ex is Data.DatabaseException or InvalidOperationException or System.Net.Http.HttpRequestException)
|
||||
{
|
||||
_shell.Notify(ex.Message, isError: true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsFinding = false;
|
||||
_find.RaiseCanExecuteChanged();
|
||||
}
|
||||
await ReloadAsync();
|
||||
}
|
||||
|
||||
/// <summary>"2 matches found" · Review, and "3 sequences linked" · Show (design §8.4).</summary>
|
||||
internal void Announce(CopyFindResult found)
|
||||
{
|
||||
var asking = found.New.Count + found.AskedAgain.Count;
|
||||
if (asking > 0)
|
||||
_shell.Notify(Loc.Plural("Server.Copies.Found", asking), null, Loc.L("Server.Copies.Action.Review"), Loc.L("Tooltips.Server.Copies.ReviewFound"), ShowMatches);
|
||||
if (found.AutoLinked.Count > 0)
|
||||
_shell.Notify(Loc.Plural("Server.Copies.Linked", found.AutoLinked.Count), null, Loc.L("Server.Sync.Show"), Loc.L("Tooltips.Server.Sync.Show"), ShowMatches);
|
||||
}
|
||||
|
||||
private void ShowMatches()
|
||||
{
|
||||
_shell.Navigate(SectionKey.Server);
|
||||
ShowList?.Invoke(null);
|
||||
}
|
||||
|
||||
private async Task ActAsync(CopyRow row, CopyAction action)
|
||||
{
|
||||
if (Engine is not { } engine) return;
|
||||
var pair = row.View;
|
||||
var copy = pair.Copy;
|
||||
try
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case CopyAction.Compare:
|
||||
Open(pair, CopyDialogPart.Photos);
|
||||
return;
|
||||
case CopyAction.Integrate or CopyAction.Merge:
|
||||
Open(pair, CopyDialogPart.Plan, integrate: true);
|
||||
return;
|
||||
case CopyAction.Review:
|
||||
Open(pair, CopyDialogPart.Photos, PhotoClass.DeletedThere);
|
||||
return;
|
||||
case CopyAction.KeepApart:
|
||||
await engine.KeepApartAsync(copy.Id, CancellationToken.None);
|
||||
Toast(Loc.L("Server.Copies.KeptApartToast", row.Title), (Loc.L("Tooltips.Server.Copies.UndoKeepApart"), () => engine.AskAgainAsync(copy.Id, CancellationToken.None)));
|
||||
break;
|
||||
case CopyAction.AskAgain:
|
||||
await engine.AskAgainAsync(copy.Id, CancellationToken.None);
|
||||
break;
|
||||
case CopyAction.Unlink:
|
||||
await engine.UnlinkAsync(copy.Id, Host.Remote, CancellationToken.None);
|
||||
if (copy.Kind == CopyKind.LocalServer && Host.Remote is { } remote)
|
||||
Toast(Loc.L("Server.Copies.Unlinked", row.Title), (Loc.L("Tooltips.Server.Copies.UndoUnlink"), () => engine.LinkAsync(copy.Id, remote, CancellationToken.None)));
|
||||
break;
|
||||
case CopyAction.KeepHere:
|
||||
await engine.KeepHereAsync(copy.Id, CancellationToken.None);
|
||||
break;
|
||||
case CopyAction.UploadAgain:
|
||||
if (Host is { Service: { } service, Server: { } server } && _shell.Services.Engine is { } jobs
|
||||
&& await _shell.Services.Database!.Sequences.GetAsync(copy.LocalId) is { } sequence)
|
||||
await service.EnqueueUploadAsync(jobs, server, sequence);
|
||||
break;
|
||||
case CopyAction.ToTrash when OpenDialog is { } open:
|
||||
var delete = new DeleteDialogViewModel(_shell, [copy.LocalId], d => CloseDialog?.Invoke(d));
|
||||
open(delete);
|
||||
await delete.RunAsync();
|
||||
break;
|
||||
case CopyAction.Pause when copy.JobId is { } paused:
|
||||
await _shell.Services.Jobs!.PauseAsync(paused);
|
||||
break;
|
||||
case CopyAction.Resume when copy.JobId is { } resumed:
|
||||
await _shell.Services.Jobs!.ResumeAsync(resumed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is Data.DatabaseException or InvalidOperationException or System.Net.Http.HttpRequestException)
|
||||
{
|
||||
_shell.Notify(ex.Message, isError: true);
|
||||
}
|
||||
await ReloadAsync();
|
||||
}
|
||||
|
||||
/// <summary>A toast with Undo (Unlink and Keep apart ask no confirmation: design §8.5).</summary>
|
||||
private void Toast(string title, (string ToolTip, Func<Task> Undo) undo) =>
|
||||
_shell.Notify(title, null, Loc.L("Server.Copies.Action.Undo"), undo.ToolTip, async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await undo.Undo();
|
||||
}
|
||||
catch (Exception ex) when (ex is Data.DatabaseException or InvalidOperationException or System.Net.Http.HttpRequestException)
|
||||
{
|
||||
_shell.Notify(ex.Message, isError: true);
|
||||
}
|
||||
await ReloadAsync();
|
||||
});
|
||||
|
||||
private void Follow(ICopyEngine? engine)
|
||||
{
|
||||
if (ReferenceEquals(_engine, engine)) return;
|
||||
if (_engine is not null) _engine.Found -= OnFound;
|
||||
_engine = engine;
|
||||
if (_engine is not null) _engine.Found += OnFound;
|
||||
}
|
||||
|
||||
private void OnFound(CopyFindResult found) => Dispatch(() =>
|
||||
{
|
||||
if (!found.IsEmpty && !IsFinding) Announce(found);
|
||||
_ = ReloadAsync();
|
||||
});
|
||||
|
||||
private void OnEngineChanged() => Dispatch(() =>
|
||||
{
|
||||
Follow(Engine);
|
||||
_ = ReloadAsync();
|
||||
});
|
||||
|
||||
private void OnHostChanged() => Dispatch(() => _ = ReloadAsync());
|
||||
|
||||
private void OnCultureChanged(object? sender, EventArgs e) => Dispatch(() =>
|
||||
{
|
||||
foreach (var row in Rows) row.Relabel();
|
||||
UpdateLibrary();
|
||||
OnAllPropertiesChanged();
|
||||
});
|
||||
|
||||
private void OnJobChanged(Job job)
|
||||
{
|
||||
if (job.Kind is not (JobKind.Integrate or JobKind.MergeSequences)) return;
|
||||
Dispatch(() =>
|
||||
{
|
||||
foreach (var row in Rows.Where(r => r.Copy.JobId == job.Id)) row.UpdateJob(job.State, job.ProgressDone, job.ProgressTotal);
|
||||
if (job.State is JobState.Done or JobState.Failed or JobState.Cancelled or JobState.Queued) _ = ReloadAsync();
|
||||
});
|
||||
}
|
||||
|
||||
private void OnProgress(JobProgressInfo info)
|
||||
{
|
||||
if (info.Kind is not JobKind.Integrate) return;
|
||||
Dispatch(() =>
|
||||
{
|
||||
foreach (var row in Rows.Where(r => r.Copy.JobId == info.JobId)) row.UpdateJob(JobState.Running, info.Done, info.Total);
|
||||
});
|
||||
}
|
||||
|
||||
private static void Dispatch(Action action)
|
||||
{
|
||||
if (System.Windows.Application.Current?.Dispatcher is not { } dispatcher || dispatcher.CheckAccess()) action();
|
||||
else dispatcher.BeginInvoke(action);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
using System.Windows.Input;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Settings;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Ui.Controls;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>A line of the Photos part's class table: glyph and class, count, bytes on each side, what it means.</summary>
|
||||
public sealed class CopyClassRow(PhotoClassTotal total) : ObservableObject
|
||||
{
|
||||
public PhotoClass Class { get; } = total.Class;
|
||||
public StatusKind Kind => CopyText.ClassKind(Class);
|
||||
public string Text => CopyText.Class(Class);
|
||||
public string CountText => Formatting.Count(total.Count);
|
||||
public string HereBytesText => total.HereBytes > 0 ? Formatting.Bytes(total.HereBytes) : string.Empty;
|
||||
public string ThereBytesText => total.ThereBytes > 0 ? Formatting.Bytes(total.ThereBytes) : string.Empty;
|
||||
public string ToolTip => CopyText.ClassToolTip(Class);
|
||||
public int Count => total.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A photo of the Photos part's list: capture time, name, size, where it lies, and per policy a Bring tick (Only here,
|
||||
/// Only there under Choose each), a version choice (Different under Choose each) or Drop… (Two versions).
|
||||
/// </summary>
|
||||
public sealed class CopyPhotoRow : ObservableObject
|
||||
{
|
||||
private readonly Action _changed;
|
||||
private bool _bring;
|
||||
private bool _isSelected;
|
||||
private SettingsOption<PhotoChoice>? _choice;
|
||||
|
||||
public CopyPhotoRow(ComparedPhoto photo, bool isMerge, bool canBring, bool canChoose, IReadOnlyList<SettingsOption<PhotoChoice>> choices,
|
||||
PhotoChoice? current, Action changed, Func<CopyPhotoRow, Task>? drop)
|
||||
{
|
||||
Photo = photo;
|
||||
IsMerge = isMerge;
|
||||
CanBring = canBring;
|
||||
CanChoose = canChoose;
|
||||
Choices = choices;
|
||||
_changed = changed;
|
||||
_bring = current == PhotoChoice.Bring;
|
||||
_choice = current is { } c and not PhotoChoice.Bring ? choices.FirstOrDefault(o => o.Value == c) : null;
|
||||
if (drop is not null) DropCommand = new AsyncRelayCommand(() => drop(this));
|
||||
}
|
||||
|
||||
public ComparedPhoto Photo { get; }
|
||||
public bool IsMerge { get; }
|
||||
public string Key => Photo.Key;
|
||||
private CopyPhotoInput? Input => Photo.Here ?? Photo.There;
|
||||
|
||||
public string TimeText => Input?.CapturedAt is { } at ? Formatting.Date(at) + " " + at.ToString("T", Loc.Culture) : string.Empty;
|
||||
public string Name => Input?.FileName ?? Photo.Key;
|
||||
public string SizeText => Formatting.Bytes(Photo.Bytes);
|
||||
|
||||
/// <summary>"This PC", "Server" (Kept, Other for a merge), or both.</summary>
|
||||
public string SideText => (Photo.Here, Photo.There) switch
|
||||
{
|
||||
(not null, not null) => string.Join(Loc.Separator, Side(true), Side(false)),
|
||||
(not null, null) => Side(true),
|
||||
_ => Side(false),
|
||||
};
|
||||
|
||||
public string ToolTip => string.Join(Loc.Separator, Name, SizeText, SideText);
|
||||
|
||||
/// <summary>Only here or Only there under Choose each: a Bring tick.</summary>
|
||||
public bool CanBring { get; }
|
||||
|
||||
/// <summary>Different under Choose each: Keep both, This PC's, Server's, Leave.</summary>
|
||||
public bool CanChoose { get; }
|
||||
|
||||
public IReadOnlyList<SettingsOption<PhotoChoice>> Choices { get; }
|
||||
|
||||
public ICommand? DropCommand { get; }
|
||||
public bool CanDrop => DropCommand is not null;
|
||||
|
||||
public bool Bring
|
||||
{
|
||||
get => _bring;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _bring, value)) return;
|
||||
_changed();
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsOption<PhotoChoice>? Choice
|
||||
{
|
||||
get => _choice;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _choice, value)) return;
|
||||
OnPropertyChanged(nameof(ChoiceAccessibleName));
|
||||
_changed();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The row is selected in the list (To trash… acts on the selection).</summary>
|
||||
public bool IsSelected { get => _isSelected; set => Set(ref _isSelected, value); }
|
||||
|
||||
/// <summary>The user's choice for this photo, or null when none.</summary>
|
||||
public PhotoChoice? Chosen => CanBring ? (_bring ? PhotoChoice.Bring : null) : _choice?.Value;
|
||||
|
||||
public string BringAccessibleName => Loc.L("Server.Copies.ControlFor", Name, Loc.L("Server.Copies.Photo.Bring"));
|
||||
public string ChoiceAccessibleName => Loc.L("Server.Copies.ControlFor", Name, _choice?.Label ?? Loc.L("Server.Copies.Version.Leave"));
|
||||
public string DropAccessibleName => Loc.L("Server.Copies.ControlFor", Name, Loc.L("Server.Copies.Action.Drop"));
|
||||
|
||||
/// <summary>Sets the tick or the choice without raising one change per row (Bring all, All: keep both).</summary>
|
||||
internal void SetQuietly(bool bring, SettingsOption<PhotoChoice>? choice)
|
||||
{
|
||||
_bring = bring;
|
||||
_choice = choice;
|
||||
OnPropertyChanged(nameof(Bring));
|
||||
OnPropertyChanged(nameof(Choice));
|
||||
OnPropertyChanged(nameof(ChoiceAccessibleName));
|
||||
}
|
||||
|
||||
private string Side(bool here) => Loc.L(IsMerge ? (here ? "Server.Copies.Detail.Kept" : "Server.Copies.Detail.Other")
|
||||
: here ? "Server.Copies.Detail.ThisPc" : "Server.Copies.Detail.Server");
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System.Windows.Input;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Ui.Controls;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>A line of the Plan part ("Receives 24 photos · 412 MB"); a warning line (last copies) leads its column.</summary>
|
||||
public sealed record CopyPlanLine(string Text, string? ToolTip = null, bool IsWarning = false)
|
||||
{
|
||||
public StatusKind Kind => IsWarning ? StatusKind.Warning : StatusKind.Done;
|
||||
public string ShownToolTip => ToolTip ?? Text;
|
||||
}
|
||||
|
||||
/// <summary>Why the plan cannot be applied, with its one action where the dialog itself settles it (Choose).</summary>
|
||||
public sealed class CopyBlockLine(CopyBlock block, string text, Action? choose)
|
||||
{
|
||||
public CopyBlock Block { get; } = block;
|
||||
public string Text { get; } = text;
|
||||
public ICommand? ChooseCommand { get; } = choose is null ? null : new RelayCommand(choose);
|
||||
public bool HasChoose => ChooseCommand is not null;
|
||||
public string ChooseText => Loc.L("Server.Copies.Action.Choose");
|
||||
public string ChooseToolTip => Loc.L("Tooltips.Server.Copies.Choose");
|
||||
}
|
||||
|
||||
/// <summary>A side of a local pair the merge keeps ("Main archive · 1,204 photos · 18.2 GB"): the Kept sequence radios.</summary>
|
||||
public sealed class CopyKeepOption(Guid sequenceId, CopyFacts facts, Action<CopyKeepOption> chosen) : ObservableObject
|
||||
{
|
||||
private bool _isChecked;
|
||||
|
||||
public Guid SequenceId { get; } = sequenceId;
|
||||
public string Text => Loc.L("Server.Copies.Plan.KeptChoice", facts.Where, Loc.Plural("Shell.Status.Photos", facts.Photos), Formatting.Bytes(facts.Bytes));
|
||||
public string ToolTip => Loc.L("Tooltips.Server.Copies.KeptCopy");
|
||||
public string AccessibleName => Loc.L("Server.Copies.ControlFor", facts.Where, Loc.L("Server.Copies.Plan.KeptCopy"));
|
||||
|
||||
public bool IsChecked
|
||||
{
|
||||
get => _isChecked;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _isChecked, value) || !value) return;
|
||||
chosen(this);
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetQuietly(bool value)
|
||||
{
|
||||
_isChecked = value;
|
||||
OnPropertyChanged(nameof(IsChecked));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>A project of one side (the Projects part): name · versions · last change, and the name it gets at the other home.</summary>
|
||||
public sealed class CopyProjectRow(ProjectLine project) : ObservableObject
|
||||
{
|
||||
private string? _target;
|
||||
|
||||
public ProjectLine Project { get; } = project;
|
||||
public string Name => Project.Name;
|
||||
public string VersionsText => Loc.Plural("Server.Copies.Projects.Versions", Project.Versions);
|
||||
public string ChangedText => Formatting.Date(Project.UpdatedAt);
|
||||
|
||||
/// <summary>"→ Vertical (STUDIO-PC)" once the plan named it; null when it stays or Main.</summary>
|
||||
public string? TargetText => _target is null ? null : Loc.L("Server.Copies.Projects.Target", _target);
|
||||
|
||||
public string ToolTip => Project.IsMain ? Loc.L("Tooltips.Server.Copies.Projects.Main")
|
||||
: string.Join(Loc.Separator, Name, VersionsText, ChangedText);
|
||||
|
||||
internal void SetTarget(string? target)
|
||||
{
|
||||
_target = target;
|
||||
OnPropertyChanged(nameof(TargetText));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
using System.Windows.Input;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Ui.Controls;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>A button of a Matches row; kept while the row offers it, so focus and tooltips survive a reload.</summary>
|
||||
public sealed class CopyRowAction : ObservableObject
|
||||
{
|
||||
private readonly AsyncRelayCommand _command;
|
||||
private string _toolTip = string.Empty;
|
||||
private string _sequence = string.Empty;
|
||||
private bool _isEnabled = true;
|
||||
|
||||
public CopyRowAction(CopyAction action, Func<Task> execute)
|
||||
{
|
||||
Action = action;
|
||||
_command = new AsyncRelayCommand(execute, () => _isEnabled);
|
||||
}
|
||||
|
||||
public CopyAction Action { get; }
|
||||
public string Text => CopyText.Label(Action);
|
||||
public ICommand Command => _command;
|
||||
|
||||
public string ToolTip { get => _toolTip; set => Set(ref _toolTip, value); }
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => _isEnabled;
|
||||
set
|
||||
{
|
||||
if (Set(ref _isEnabled, value)) _command.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string Sequence
|
||||
{
|
||||
get => _sequence;
|
||||
set
|
||||
{
|
||||
if (Set(ref _sequence, value)) OnPropertyChanged(nameof(AccessibleName));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>"Compare…: Lighthouse 2026-08-13": screen readers name the pair each of the identical buttons acts on.</summary>
|
||||
public string AccessibleName => Loc.L("Server.Sync.ActionFor", Text, _sequence);
|
||||
|
||||
public void Relabel()
|
||||
{
|
||||
OnPropertyChanged(nameof(Text));
|
||||
OnPropertyChanged(nameof(AccessibleName));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>One row of Server › Matches (design §8.1): the sequence, both sides, the state and the actions that apply.</summary>
|
||||
public sealed class CopyRow : ObservableObject
|
||||
{
|
||||
private readonly Func<CopyRow, CopyAction, Task> _act;
|
||||
private FoundCopyView _view;
|
||||
private CopyRights _rights;
|
||||
private (long Done, long Total)? _progress;
|
||||
private Core.Model.JobState? _job;
|
||||
private IReadOnlyList<CopyRowAction> _actions = [];
|
||||
|
||||
public CopyRow(FoundCopyView view, CopyRights rights, Func<CopyRow, CopyAction, Task> act)
|
||||
{
|
||||
_view = view;
|
||||
_act = act;
|
||||
UpdateActions(rights);
|
||||
}
|
||||
|
||||
public FoundCopyView View => _view;
|
||||
public FoundCopy Copy => _view.Copy;
|
||||
public Guid Id => _view.Copy.Id;
|
||||
public string Title => _view.Here.Title;
|
||||
|
||||
/// <summary>Both titles: the other copy may carry another name.</summary>
|
||||
public string TitleToolTip => string.Equals(_view.Here.Title, _view.There.Title, StringComparison.CurrentCulture)
|
||||
? _view.Here.Title
|
||||
: string.Join(Loc.Separator, _view.Here.Title, _view.There.Title);
|
||||
|
||||
public string HereText => CopyText.Where(_view.Here, isServer: false);
|
||||
public string ThereText => CopyText.Where(_view.There, isServer: Copy.Kind == CopyKind.LocalServer);
|
||||
|
||||
public StatusKind StateKind => CopyText.State(Copy, _rights.ServerName, _progress).Kind;
|
||||
public string StateText => CopyText.State(Copy, _rights.ServerName, _progress).Text;
|
||||
public string StateToolTip => string.Join(Loc.Separator, StateText, CopyText.State(Copy, _rights.ServerName, _progress).ToolTip);
|
||||
|
||||
/// <summary>"Lighthouse 2026-08-13: match found": what a screen reader announces when the state changes.</summary>
|
||||
public string StateAnnouncement => Loc.L("Server.Sync.Row.State", Title, StateText);
|
||||
|
||||
/// <summary>The pair asks for a choice: the row is drawn on the warning tint (the State word says it too).</summary>
|
||||
public bool IsConflict => Copy.NeedsAttention;
|
||||
|
||||
public IReadOnlyList<CopyRowAction> Actions
|
||||
{
|
||||
get => _actions;
|
||||
private set => Set(ref _actions, value);
|
||||
}
|
||||
|
||||
public void Update(FoundCopyView view, CopyRights rights)
|
||||
{
|
||||
_view = view;
|
||||
UpdateActions(rights);
|
||||
RaiseTexts();
|
||||
}
|
||||
|
||||
/// <summary>The Integrate job's step ("integrating · 2 of 5") and whether it is paused.</summary>
|
||||
public void UpdateJob(Core.Model.JobState? state, long done, long total)
|
||||
{
|
||||
_progress = (done, total);
|
||||
if (_job != state)
|
||||
{
|
||||
_job = state;
|
||||
UpdateActions(_rights);
|
||||
}
|
||||
RaiseTexts();
|
||||
}
|
||||
|
||||
public void Relabel()
|
||||
{
|
||||
foreach (var action in _actions) action.Relabel();
|
||||
UpdateActions(_rights);
|
||||
RaiseTexts();
|
||||
}
|
||||
|
||||
private void UpdateActions(CopyRights rights)
|
||||
{
|
||||
_rights = rights;
|
||||
var wanted = CopyText.Actions(Copy, _job);
|
||||
if (!wanted.SequenceEqual(_actions.Select(a => a.Action)))
|
||||
{
|
||||
var kept = _actions.ToDictionary(a => a.Action);
|
||||
Actions = [.. wanted.Select(action => kept.GetValueOrDefault(action) ?? new CopyRowAction(action, () => _act(this, action)))];
|
||||
}
|
||||
foreach (var action in _actions)
|
||||
{
|
||||
action.ToolTip = CopyText.ToolTip(Copy, action.Action, rights);
|
||||
action.IsEnabled = CopyText.Blocked(Copy, action.Action, rights) is null;
|
||||
action.Sequence = Title;
|
||||
}
|
||||
}
|
||||
|
||||
private void RaiseTexts()
|
||||
{
|
||||
OnPropertyChanged(nameof(View));
|
||||
OnPropertyChanged(nameof(Copy));
|
||||
OnPropertyChanged(nameof(Title));
|
||||
OnPropertyChanged(nameof(TitleToolTip));
|
||||
OnPropertyChanged(nameof(HereText));
|
||||
OnPropertyChanged(nameof(ThereText));
|
||||
OnPropertyChanged(nameof(StateKind));
|
||||
OnPropertyChanged(nameof(StateText));
|
||||
OnPropertyChanged(nameof(StateToolTip));
|
||||
OnPropertyChanged(nameof(StateAnnouncement));
|
||||
OnPropertyChanged(nameof(IsConflict));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Shell;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Sync;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>
|
||||
/// The Matches states that <c>--capture</c> renders (<c>server-copies-<scene>-<theme>.png</c>, design §8.7) and the
|
||||
/// screen smoke tests check, on the sample pairs: the list, the dialog at each part and with each list, the plan with and
|
||||
/// without a block, the merge of a local pair, the toast of Find matches, and the sync rows a pair marks.
|
||||
/// </summary>
|
||||
public static class CopyScenes
|
||||
{
|
||||
/// <summary>Scenes shown in the window (dialogs in-window included); the confirmations are separate windows.</summary>
|
||||
public static readonly IReadOnlyList<string> Views =
|
||||
[
|
||||
"server-copies", "server-copies-toast", "server-copies-photos", "server-copies-choose", "server-copies-versions",
|
||||
"server-copies-review", "server-copies-details", "server-copies-projects", "server-copies-plan", "server-copies-blocked",
|
||||
"server-copies-merge", "server-sync-copyfound", "server-copies-gone",
|
||||
];
|
||||
|
||||
/// <summary>The Lighthouse pair (a match found on the server).</summary>
|
||||
public const string Lighthouse = "Lighthouse 2026-08-13";
|
||||
|
||||
/// <summary>The Alps pair (twice on this PC).</summary>
|
||||
public const string Alps = "Alps 2025";
|
||||
|
||||
/// <summary>Shows <paramref name="view"/>; returns the dialog it opened, if any.</summary>
|
||||
public static async Task<CopyDialogViewModel?> ShowAsync(ShellViewModel shell, string view)
|
||||
{
|
||||
var server = shell.Server;
|
||||
var sync = server.Sync;
|
||||
var list = sync.Copies;
|
||||
shell.Navigate(SectionKey.Server);
|
||||
if (server.Dialog is { } open) server.CloseDialog(open);
|
||||
sync.SearchText = string.Empty;
|
||||
await sync.ReloadAsync();
|
||||
await list.ReloadAsync();
|
||||
switch (view)
|
||||
{
|
||||
case "server-sync-copyfound":
|
||||
sync.ShowFilter(SyncFilter.All);
|
||||
return null;
|
||||
case "server-copies-gone":
|
||||
sync.ShowFilter(SyncFilter.All, "Garden");
|
||||
return null;
|
||||
case "server-copies-toast":
|
||||
sync.ShowFilter(SyncFilter.FoundCopies);
|
||||
if (list.Engine is { } engine) list.Announce(await engine.FindAsync(shell.Services.Sync.Remote, CancellationToken.None));
|
||||
return null;
|
||||
}
|
||||
sync.ShowFilter(SyncFilter.FoundCopies);
|
||||
if (view == "server-copies") return null;
|
||||
var title = view is "server-copies-versions" or "server-copies-merge" ? Alps : view == "server-copies-review" ? "Bridge works wk 41" : Lighthouse;
|
||||
if (list.Pairs.FirstOrDefault(p => p.Here.Title == title) is not { } pair) return null;
|
||||
var (part, photos) = view switch
|
||||
{
|
||||
"server-copies-photos" => (CopyDialogPart.Photos, PhotoClass.OnlyHere),
|
||||
"server-copies-choose" => (CopyDialogPart.Photos, PhotoClass.Differs),
|
||||
"server-copies-versions" => (CopyDialogPart.Photos, PhotoClass.Versions),
|
||||
"server-copies-review" => (CopyDialogPart.Photos, PhotoClass.DeletedThere),
|
||||
"server-copies-details" => (CopyDialogPart.Details, (PhotoClass?)null),
|
||||
"server-copies-projects" => (CopyDialogPart.Projects, null),
|
||||
_ => (CopyDialogPart.Plan, null),
|
||||
};
|
||||
if (list.Open(pair, part, photos) is not { } dialog) return null;
|
||||
await dialog.LoadAsync();
|
||||
switch (view)
|
||||
{
|
||||
case "server-copies-choose":
|
||||
dialog.Policy = dialog.Policies.First(o => o.Value == CopyPhotoPolicy.ChoosePerPhoto);
|
||||
dialog.SelectedClass = dialog.Classes.FirstOrDefault(c => c.Class == PhotoClass.Differs);
|
||||
break;
|
||||
case "server-copies-details":
|
||||
if (dialog.Details.Count > 0) dialog.Details[0].ChoiceIndex = 0;
|
||||
break;
|
||||
case "server-copies-plan":
|
||||
dialog.AllHereCommand.Execute(null);
|
||||
dialog.Part = CopyDialogPart.Plan;
|
||||
break;
|
||||
}
|
||||
if (dialog.IsPlan) await dialog.PlanNowAsync();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
/// <summary>"Replace photos?": the Lighthouse plan where this PC's version of the different photos wins.</summary>
|
||||
public static async Task<ConfirmRequest?> ReplaceRequestAsync(ShellViewModel shell)
|
||||
{
|
||||
if (await ShowAsync(shell, "server-copies-plan") is not { } dialog) return null;
|
||||
dialog.Policy = dialog.Policies.First(o => o.Value == CopyPhotoPolicy.ThisPcWins);
|
||||
await dialog.PlanNowAsync();
|
||||
var request = dialog.Plan is { } plan ? CopyDialogViewModel.ReplaceRequest(plan) : null;
|
||||
shell.Server.CloseDialog(dialog);
|
||||
return request;
|
||||
}
|
||||
|
||||
/// <summary>"Merge sequences?": the Alps merge, with the typed photo count.</summary>
|
||||
public static async Task<ConfirmRequest?> MergeRequestAsync(ShellViewModel shell)
|
||||
{
|
||||
if (await ShowAsync(shell, "server-copies-merge") is not { } dialog) return null;
|
||||
dialog.AllHereCommand.Execute(null);
|
||||
await dialog.PlanNowAsync();
|
||||
var request = dialog.MergePlan is { } plan ? dialog.MergeRequest(plan) : null;
|
||||
shell.Server.CloseDialog(dialog);
|
||||
return request;
|
||||
}
|
||||
|
||||
/// <summary>Back to the sync table with no dialog and no search.</summary>
|
||||
public static void Reset(ShellViewModel shell)
|
||||
{
|
||||
if (shell.Server.Dialog is { } open) shell.Server.CloseDialog(open);
|
||||
shell.Server.Sync.ShowFilter(SyncFilter.All, string.Empty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Ui.Controls;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>What a row of Server › Matches offers (design §8.1).</summary>
|
||||
public enum CopyAction
|
||||
{
|
||||
Compare,
|
||||
Integrate,
|
||||
Merge,
|
||||
KeepApart,
|
||||
AskAgain,
|
||||
Unlink,
|
||||
Review,
|
||||
KeepHere,
|
||||
UploadAgain,
|
||||
ToTrash,
|
||||
Pause,
|
||||
Resume,
|
||||
}
|
||||
|
||||
/// <summary>What the signed-in account allows a pair's actions; Server is null when signed out.</summary>
|
||||
/// <param name="Server">The signed-in server's key, or null.</param>
|
||||
/// <param name="ServerName">The name shown for that server.</param>
|
||||
/// <param name="CanIntegrate">The server announces the capabilities an Integrate needs.</param>
|
||||
/// <param name="CanUpload">The account may upload.</param>
|
||||
/// <param name="Busy">The pair's sequences an Integrate or Merge job holds.</param>
|
||||
public readonly record struct CopyRights(string? Server, string? ServerName, bool CanIntegrate, bool CanUpload, bool Busy = false);
|
||||
|
||||
/// <summary>The words, glyphs and actions of a pair (design §8.1): plain functions of a <see cref="FoundCopy"/>, like <see cref="SyncText"/>.</summary>
|
||||
public static class CopyText
|
||||
{
|
||||
/// <summary>The state glyph, word and tooltip of a pair; <paramref name="progress"/> is the Integrate job's step (done, total).</summary>
|
||||
public static (StatusKind Kind, string Text, string ToolTip) State(FoundCopy copy, string? serverName = null, (long Done, long Total)? progress = null)
|
||||
{
|
||||
var deleted = copy.Score.DeletedThere;
|
||||
if (copy.RemoteGone && copy.State == CopyState.KeptApart)
|
||||
return (StatusKind.Offline, Loc.L("Server.Copies.State.KeptHere"), Loc.L("Tooltips.Server.Copies.State.KeptHere"));
|
||||
if (copy.RemoteGone)
|
||||
return (StatusKind.Warning, Loc.L("Server.Copies.State.RemoteGone"), Loc.L("Tooltips.Server.Copies.State.RemoteGone"));
|
||||
if (copy.State is CopyState.Linked or CopyState.Integrated && deleted > 0)
|
||||
{
|
||||
var key = copy.Kind == CopyKind.LocalLocal ? "Server.Copies.State.DeletedOther" : "Server.Copies.State.DeletedThere";
|
||||
return (StatusKind.Warning, Loc.L(key, Formatting.Count(deleted)), Loc.Plural("Tooltips.Server.Copies.State.DeletedThere", deleted));
|
||||
}
|
||||
return copy.State switch
|
||||
{
|
||||
CopyState.Candidate => (StatusKind.Warning, Loc.L("Server.Copies.State.Candidate"),
|
||||
Loc.L("Tooltips.Server.Copies.State.Candidate", SharedPercent(copy.Score))),
|
||||
CopyState.KeptApart => (StatusKind.Offline, Loc.L("Server.Copies.State.KeptApart"),
|
||||
Loc.L("Tooltips.Server.Copies.State.KeptApart", Formatting.Date(copy.AnsweredAt ?? copy.UpdatedAt))),
|
||||
CopyState.Linked => (StatusKind.Synced, Loc.L("Server.Copies.State.Linked"), Loc.L("Tooltips.Server.Copies.State.Linked")),
|
||||
CopyState.Integrating => (StatusKind.Running,
|
||||
Loc.L("Server.Copies.State.Integrating", Formatting.Count(progress?.Done ?? 0), Formatting.Count(progress?.Total ?? 0)),
|
||||
Loc.L("Tooltips.Server.Copies.State.Integrating")),
|
||||
_ => (StatusKind.Done, Loc.L("Server.Copies.State.Integrated"), Loc.L("Tooltips.Server.Copies.State.Integrated")),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>The share of the smaller side's photos the other holds too, in whole per cent ("98").</summary>
|
||||
public static string SharedPercent(CopyScore score) =>
|
||||
Math.Round(Math.Clamp(score.Containment, 0, 1000) / 10.0).ToString("0", Loc.Culture);
|
||||
|
||||
/// <summary>"Main archive · 1,204 photos": where one side of a pair lies.</summary>
|
||||
public static string Where(CopyFacts facts, bool isServer) =>
|
||||
Loc.Plural(isServer ? "Server.Copies.Where.Server" : "Server.Copies.Where.Archive", facts.Photos, facts.Where);
|
||||
|
||||
/// <summary>"Lighthouse · 1,204 photos · 18.2 GB": a side of the dialog's header.</summary>
|
||||
public static string Facts(CopyFacts facts) => Loc.Plural("Server.Copies.Facts", facts.Photos, facts.Where, Formatting.Bytes(facts.Bytes));
|
||||
|
||||
/// <summary>The row's buttons in the order of design §8.1.</summary>
|
||||
public static IReadOnlyList<CopyAction> Actions(FoundCopy copy, Core.Model.JobState? job = null)
|
||||
{
|
||||
var local = copy.Kind == CopyKind.LocalLocal;
|
||||
if (copy.RemoteGone)
|
||||
return copy.State == CopyState.KeptApart ? [CopyAction.UploadAgain] : [CopyAction.KeepHere, CopyAction.UploadAgain, CopyAction.ToTrash];
|
||||
return copy.State switch
|
||||
{
|
||||
CopyState.Candidate => [CopyAction.Compare, local ? CopyAction.Merge : CopyAction.Integrate, CopyAction.KeepApart],
|
||||
CopyState.KeptApart => [CopyAction.Compare, CopyAction.AskAgain],
|
||||
CopyState.Linked when copy.Score.DeletedThere > 0 => [CopyAction.Compare, CopyAction.Integrate, CopyAction.Unlink, CopyAction.Review],
|
||||
CopyState.Linked => [CopyAction.Compare, CopyAction.Integrate, CopyAction.Unlink],
|
||||
CopyState.Integrating => [job == Core.Model.JobState.Paused ? CopyAction.Resume : CopyAction.Pause],
|
||||
_ when copy.Score.DeletedThere > 0 => [CopyAction.Compare, CopyAction.Unlink, CopyAction.Review],
|
||||
_ => [CopyAction.Compare, CopyAction.Unlink],
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>The button's label ("Compare…", "Merge…").</summary>
|
||||
public static string Label(CopyAction action) => action switch
|
||||
{
|
||||
CopyAction.Merge => Loc.L("Server.Copies.Action.MergeRow"),
|
||||
CopyAction.Pause => Loc.L("Server.Sync.Action.Pause"),
|
||||
CopyAction.Resume => Loc.L("Server.Sync.Action.Resume"),
|
||||
_ => Loc.L("Server.Copies.Action." + action),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Why the action cannot be pressed now, or null when it can: a pair of a server needs that server signed in; Integrate
|
||||
/// a server that announces the capabilities; Upload again the upload right; nothing that moves files while a job holds it.
|
||||
/// </summary>
|
||||
public static string? Blocked(FoundCopy copy, CopyAction action, CopyRights rights)
|
||||
{
|
||||
if (action is CopyAction.Pause or CopyAction.Resume or CopyAction.KeepApart or CopyAction.AskAgain or CopyAction.KeepHere) return null;
|
||||
if (copy.Kind == CopyKind.LocalServer && action is not CopyAction.ToTrash
|
||||
&& !string.Equals(copy.Server, rights.Server, StringComparison.OrdinalIgnoreCase))
|
||||
return Loc.L("Tooltips.Server.Copies.SignIn", copy.Server ?? string.Empty);
|
||||
if (rights.Busy && action is CopyAction.Integrate or CopyAction.Merge or CopyAction.ToTrash or CopyAction.UploadAgain)
|
||||
return Loc.L("Errors.Copies.Busy");
|
||||
return action switch
|
||||
{
|
||||
CopyAction.Integrate when !rights.CanIntegrate => Loc.L("Tooltips.Server.Copies.NeedsNewerServer"),
|
||||
CopyAction.UploadAgain when !rights.CanUpload => Loc.L("Tooltips.Server.Sync.UploadAll.NoRight"),
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>What the button does; for a disabled one, why not.</summary>
|
||||
public static string ToolTip(FoundCopy copy, CopyAction action, CopyRights rights) => Blocked(copy, action, rights) ?? action switch
|
||||
{
|
||||
CopyAction.UploadAgain => Loc.L("Tooltips.Server.Copies.UploadAgain", rights.ServerName ?? copy.Server ?? string.Empty),
|
||||
CopyAction.ToTrash => Loc.L("Tooltips.Server.Copies.ToTrashSequence"),
|
||||
CopyAction.Pause => Loc.L("Tooltips.Server.Sync.Pause"),
|
||||
CopyAction.Resume => Loc.L("Tooltips.Server.Sync.Resume"),
|
||||
_ => Loc.L("Tooltips.Server.Copies." + action),
|
||||
};
|
||||
|
||||
/// <summary>Sorting (design §8.1): pairs asking for attention first, then the stronger hints, then by title.</summary>
|
||||
public static IEnumerable<FoundCopyView> Sorted(IEnumerable<FoundCopyView> pairs) => pairs
|
||||
.OrderByDescending(p => p.Copy.NeedsAttention)
|
||||
.ThenByDescending(p => p.Copy.Score.Hints)
|
||||
.ThenBy(p => p.Here.Title, StringComparer.CurrentCultureIgnoreCase);
|
||||
|
||||
/// <summary>The search of the Matches list: either title.</summary>
|
||||
public static bool Matches(FoundCopyView pair, string search) => search.Length == 0
|
||||
|| pair.Here.Title.Contains(search, StringComparison.CurrentCultureIgnoreCase)
|
||||
|| pair.There.Title.Contains(search, StringComparison.CurrentCultureIgnoreCase);
|
||||
|
||||
/// <summary>The word of a photo class ("Only here").</summary>
|
||||
public static string Class(PhotoClass c) => Loc.L("Server.Copies.Class." + c);
|
||||
|
||||
public static string ClassToolTip(PhotoClass c) => Loc.L("Tooltips.Server.Copies.Class." + c);
|
||||
|
||||
/// <summary>The glyph of a photo class: what an Integrate settles by itself is fine; what waits for a choice is a warning.</summary>
|
||||
public static StatusKind ClassKind(PhotoClass c) => c switch
|
||||
{
|
||||
PhotoClass.Same or PhotoClass.Converted => StatusKind.Done,
|
||||
PhotoClass.SameUnhashed => StatusKind.Queued,
|
||||
PhotoClass.OnlyHere or PhotoClass.OnlyThere => StatusKind.Synced,
|
||||
PhotoClass.DeletedHere => StatusKind.Offline,
|
||||
_ => StatusKind.Warning,
|
||||
};
|
||||
|
||||
/// <summary>The sentence of a block (each maps to one <c>Errors.Copies.*</c> key).</summary>
|
||||
public static string Block(CopyBlock block, string title, string? server, string? need = null, int unchosen = 0) => block switch
|
||||
{
|
||||
CopyBlock.NeedsNewerServer => Loc.L("Errors.Copies.NeedsNewerServer", server ?? string.Empty),
|
||||
CopyBlock.LinkTaken => Loc.L("Errors.Copies.LinkTaken", title, server ?? string.Empty),
|
||||
CopyBlock.NoSpace => Loc.L("Errors.Copies.NoSpace", title, need ?? string.Empty),
|
||||
CopyBlock.ArchiveOffline or CopyBlock.FolderMoved or CopyBlock.ChangedFile => Loc.L("Errors.Copies." + block, title),
|
||||
CopyBlock.UnsentWorkspace => Loc.L("Errors.Copies.Unsent", title),
|
||||
CopyBlock.BothLinked => Loc.L("Errors.Copies.BothLinked", server ?? string.Empty),
|
||||
CopyBlock.TrashBlocked => Loc.L("Errors.Copies.TrashBlocked", title, need ?? string.Empty),
|
||||
CopyBlock.DetailsUnchosen => Loc.Plural("Errors.Copies.DetailsUnchosen", unchosen),
|
||||
_ => Loc.L("Errors.Copies." + block),
|
||||
};
|
||||
|
||||
/// <summary>A block the user settles in the dialog itself: its line gets the one action Choose.</summary>
|
||||
public static bool HasChoose(CopyBlock block) => block is CopyBlock.DetailsUnchosen or CopyBlock.KeptUnchosen;
|
||||
}
|
||||
Reference in new issue
Block a user