Findings, advisor reasons and a few UI texts put a count before a plural noun without plural forms, so English and Italian read "1 frames are black". Each such key is now a plural stem (.one/.other) whose count is its first argument; findings and reasons, which travel as data, resolve through the new Loc.Text, which picks the form from that argument (a fraction takes "other"), so stored deep reports and project reasons keep their keys and arguments. Texts with two or more counts (job log lines, "frames with a capture time: 12 of 300") read as labels, which agree with no number. A single exposure change gets its own finding instead of "1 exposure changes, typically 0 frames apart". The converted and reworded keys leave the 36 other catalogs until they are translated again; the dead plain Shell.JobBar.Ready goes too. `i18n check` now fails on an English text that counts a noun without plural forms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
298 lines
11 KiB
C#
298 lines
11 KiB
C#
using System.Windows.Input;
|
|
using Titano.Core.Advice;
|
|
using Titano.Core.Analysis;
|
|
using Titano.Core.Localization;
|
|
using Titano.Core.Model;
|
|
using Titano.Ui.Controls;
|
|
using Titano.Ui.Mvvm;
|
|
|
|
namespace Titano.App.Editor;
|
|
|
|
/// <summary>Columns of the Frames table, each sortable (DESIGN §4 tables).</summary>
|
|
public enum FrameSort
|
|
{
|
|
Number,
|
|
Time,
|
|
Exposure,
|
|
Iso,
|
|
Aperture,
|
|
Size,
|
|
Tier,
|
|
Flags,
|
|
}
|
|
|
|
/// <summary>A sortable column header of the Frames table: its sort state and the command that sorts on it.</summary>
|
|
public sealed class FrameColumn(FramesTab owner, FrameSort sort) : ObservableObject
|
|
{
|
|
public FrameSort Sort { get; } = sort;
|
|
|
|
public bool IsSorted => owner.SortBy == Sort;
|
|
|
|
public bool IsDescending => IsSorted && owner.SortDescending;
|
|
|
|
public ICommand SortCommand { get; } = new RelayCommand(() => owner.SortOn(sort));
|
|
|
|
public void Refresh()
|
|
{
|
|
OnPropertyChanged(nameof(IsSorted));
|
|
OnPropertyChanged(nameof(IsDescending));
|
|
}
|
|
}
|
|
|
|
/// <summary>One frame of the Frames table; texts are formatted when shown (the table is virtualised).</summary>
|
|
public sealed class FrameRow(FramesTab owner, Frame frame, int index) : ObservableObject
|
|
{
|
|
/// <summary>Archive flags named in the table (the others are internal or shown elsewhere).</summary>
|
|
public const FrameFlags Shown = FrameFlags.Missing | FrameFlags.Corrupt | FrameFlags.Duplicate | FrameFlags.Undecodable | FrameFlags.Black | FrameFlags.White;
|
|
|
|
private static readonly FrameFlags[] ShownFlags =
|
|
[FrameFlags.Missing, FrameFlags.Corrupt, FrameFlags.Duplicate, FrameFlags.Undecodable, FrameFlags.Black, FrameFlags.White];
|
|
|
|
public int Index { get; } = index;
|
|
|
|
public Frame Frame => frame;
|
|
|
|
public string Number => (Index + 1).ToString("D4", Loc.Culture);
|
|
|
|
public string Time => frame.CapturedAt?.ToString("T", Loc.Culture) ?? string.Empty;
|
|
|
|
public string Exposure => frame.ExposureTime is > 0 and var t ? EditorText.Shutter(t) : string.Empty;
|
|
|
|
public string Iso => frame.Iso?.ToString(Loc.Culture) ?? string.Empty;
|
|
|
|
public string Aperture => frame.FNumber is > 0 and var f ? Loc.L("Editor.Shot.Aperture", f.ToString("0.#", Loc.Culture)) : string.Empty;
|
|
|
|
public string Size => frame.Width > 0 ? EditorText.Size(frame.Width, frame.Height) : string.Empty;
|
|
|
|
/// <summary>Decode tier: the format, and "preview" when only the embedded preview decodes.</summary>
|
|
public string Tier => (frame.Flags & FrameFlags.PreviewOnly) != 0 ? Loc.L("Editor.Frames.PreviewOnly", frame.Format) : frame.Format.ToString();
|
|
|
|
/// <summary>"Excluded · black", the project's exclusion first, then the archive's flags.</summary>
|
|
public string Flags
|
|
{
|
|
get
|
|
{
|
|
var parts = new List<string>();
|
|
if (IsExcluded) parts.Add(Loc.L("Editor.Frames.Excluded"));
|
|
if (IsHero) parts.Add(Loc.L("Editor.Frames.Hero"));
|
|
foreach (var flag in ShownFlags)
|
|
{
|
|
if ((frame.Flags & flag) != 0) parts.Add(Loc.L("Editor.Frames.Flag." + flag));
|
|
}
|
|
return string.Join(Loc.Separator, parts);
|
|
}
|
|
}
|
|
|
|
public bool IsExcluded => owner.IsExcluded(Index);
|
|
|
|
public bool IsHero => owner.HeroIndex == Index;
|
|
|
|
public string ExcludeText => Loc.L(IsExcluded ? "Editor.Frames.Include" : "Editor.Frames.Exclude");
|
|
|
|
public string ExcludeToolTip => owner.Editor.LockedToolTip ?? Loc.L(IsExcluded ? "Tooltips.Editor.Frames.Include" : "Tooltips.Editor.Frames.Exclude");
|
|
|
|
/// <summary>A job of the sequence started or ended: the action tooltips say why they wait.</summary>
|
|
public void RefreshBusy() => OnPropertyChanged(nameof(ExcludeToolTip));
|
|
|
|
/// <summary>The project's exclusions or hero changed.</summary>
|
|
public void Refresh()
|
|
{
|
|
OnPropertyChanged(nameof(IsExcluded));
|
|
OnPropertyChanged(nameof(IsHero));
|
|
OnPropertyChanged(nameof(Flags));
|
|
OnPropertyChanged(nameof(ExcludeText));
|
|
OnPropertyChanged(nameof(ExcludeToolTip));
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>A finding of the analyses with the frame to jump to.</summary>
|
|
public sealed record FindingItem(StatusKind Kind, string Text, int? Frame);
|
|
|
|
/// <summary>
|
|
/// Frames (BRIEF §12.3): the virtualised frame table (index, time, exposure, ISO, aperture, size, tier, flags) with
|
|
/// exclude/include and hero, and the warnings of the analyses; Optimise adds the advised exclusions and hero.
|
|
/// </summary>
|
|
public sealed class FramesTab : EditorTab
|
|
{
|
|
private HashSet<int> _excluded = [];
|
|
private int? _hero;
|
|
private FrameRow[] _rows = [];
|
|
private IReadOnlyList<FrameRow> _frames = [];
|
|
private IReadOnlyList<FindingItem> _findings = [];
|
|
private FrameRow? _selected;
|
|
|
|
public FramesTab(EditorViewModel editor)
|
|
: base(editor, "Frames", AdvisorSection.Frames)
|
|
{
|
|
ToggleExcludeCommand = new RelayCommand(p => ToggleExcluded(p is FrameRow row ? row.Index : Editor.CurrentIndex), _ => !Editor.IsLocked);
|
|
SetHeroCommand = new RelayCommand(p => Editor.Session.SetHero(p is FrameRow row ? row.Index : Editor.CurrentIndex), _ => !Editor.IsLocked);
|
|
SeekCommand = new RelayCommand(p =>
|
|
{
|
|
if (p is FindingItem { Frame: { } frame }) Editor.CurrentIndex = frame;
|
|
});
|
|
Columns = [.. Enum.GetValues<FrameSort>().Select(c => new FrameColumn(this, c))];
|
|
Load();
|
|
}
|
|
|
|
/// <summary>Rows in the table's order (<see cref="SortBy"/>).</summary>
|
|
public IReadOnlyList<FrameRow> Frames { get => _frames; private set => Set(ref _frames, value); }
|
|
|
|
/// <summary>Column headers in <see cref="FrameSort"/> order.</summary>
|
|
public IReadOnlyList<FrameColumn> Columns { get; }
|
|
|
|
public FrameSort SortBy { get; private set; } = FrameSort.Number;
|
|
|
|
public bool SortDescending { get; private set; }
|
|
|
|
public IReadOnlyList<FindingItem> Findings
|
|
{
|
|
get => _findings;
|
|
private set
|
|
{
|
|
if (Set(ref _findings, value)) OnPropertyChanged(nameof(HasFindings));
|
|
}
|
|
}
|
|
|
|
public bool HasFindings => _findings.Count > 0;
|
|
|
|
/// <summary>The row of the current frame (selecting a row seeks the preview).</summary>
|
|
public FrameRow? Selected
|
|
{
|
|
get => _selected;
|
|
set
|
|
{
|
|
if (!Set(ref _selected, value) || value is null) return;
|
|
Editor.CurrentIndex = value.Index;
|
|
}
|
|
}
|
|
|
|
public int? HeroIndex => _hero;
|
|
|
|
/// <summary>"Frame 0413", or "Not set".</summary>
|
|
public string HeroText => _hero is { } h ? Loc.L("Editor.Frames.HeroValue", (h + 1).ToString("D4", Loc.Culture)) : Loc.L("Editor.Frames.HeroNone");
|
|
|
|
/// <summary>"12 frames", "None".</summary>
|
|
public string ExcludedText => _excluded.Count > 0 ? Loc.Plural("Editor.Value.Frames", _excluded.Count) : Loc.L("Editor.Frames.ExcludedNone");
|
|
|
|
public bool IsCurrentExcluded => IsExcluded(Editor.CurrentIndex);
|
|
|
|
public string CurrentExcludeText => Loc.L(IsCurrentExcluded ? "Editor.Frames.IncludeFrame" : "Editor.Frames.ExcludeFrame");
|
|
|
|
public string CurrentExcludeToolTip => Editor.LockedToolTip ?? Loc.L(IsCurrentExcluded ? "Tooltips.Editor.Frames.Include" : "Tooltips.Editor.Frames.Exclude");
|
|
|
|
/// <summary>What Set hero does, or why it waits.</summary>
|
|
public string HeroToolTip => Editor.LockedToolTip ?? Loc.L("Tooltips.Editor.Frames.Hero");
|
|
|
|
public override bool CanReset => false;
|
|
|
|
public ICommand ToggleExcludeCommand { get; }
|
|
|
|
public ICommand SetHeroCommand { get; }
|
|
|
|
public ICommand SeekCommand { get; }
|
|
|
|
public bool IsExcluded(int index) => _excluded.Contains(index);
|
|
|
|
/// <summary>Sorts the table on <paramref name="column"/>; the same column again reverses the order.</summary>
|
|
public void SortOn(FrameSort column)
|
|
{
|
|
SortDescending = column == SortBy && !SortDescending;
|
|
SortBy = column;
|
|
Frames = Sorted();
|
|
foreach (var header in Columns) header.Refresh();
|
|
}
|
|
|
|
public override void Refresh()
|
|
{
|
|
base.Refresh();
|
|
var project = Editor.Session.Project;
|
|
var excluded = project.ExcludedFrames.ToHashSet();
|
|
if (excluded.SetEquals(_excluded) && project.HeroFrame == _hero) return;
|
|
var changed = new HashSet<int>(excluded);
|
|
changed.SymmetricExceptWith(_excluded);
|
|
if (_hero is { } oldHero) changed.Add(oldHero);
|
|
if (project.HeroFrame is { } newHero) changed.Add(newHero);
|
|
_excluded = excluded;
|
|
_hero = project.HeroFrame;
|
|
foreach (var index in changed)
|
|
{
|
|
if ((uint)index < (uint)_rows.Length) _rows[index].Refresh();
|
|
}
|
|
OnPropertyChanged(nameof(HeroText));
|
|
OnPropertyChanged(nameof(ExcludedText));
|
|
OnCurrentFrameChanged();
|
|
}
|
|
|
|
public override void OnContentChanged()
|
|
{
|
|
Load();
|
|
base.OnContentChanged();
|
|
}
|
|
|
|
public override void OnBusyChanged()
|
|
{
|
|
base.OnBusyChanged();
|
|
OnPropertyChanged(nameof(HeroToolTip));
|
|
OnPropertyChanged(nameof(CurrentExcludeToolTip));
|
|
foreach (var row in _rows) row.RefreshBusy();
|
|
}
|
|
|
|
public override void OnCurrentFrameChanged()
|
|
{
|
|
var index = Editor.CurrentIndex;
|
|
if ((uint)index < (uint)_rows.Length && !ReferenceEquals(_selected, _rows[index]))
|
|
{
|
|
_selected = _rows[index];
|
|
OnPropertyChanged(nameof(Selected));
|
|
}
|
|
OnPropertyChanged(nameof(IsCurrentExcluded));
|
|
OnPropertyChanged(nameof(CurrentExcludeText));
|
|
OnPropertyChanged(nameof(CurrentExcludeToolTip));
|
|
}
|
|
|
|
private void Load()
|
|
{
|
|
var content = Editor.Session.Content;
|
|
_excluded = Editor.Session.Project.ExcludedFrames.ToHashSet();
|
|
_hero = Editor.Session.Project.HeroFrame;
|
|
_rows = [.. content.Frames.Select((f, i) => new FrameRow(this, f, i))];
|
|
Frames = Sorted();
|
|
Findings = [.. Editor.Session.Advice.Findings.OrderByDescending(f => f.Severity).Select(ToItem)];
|
|
_selected = null;
|
|
OnCurrentFrameChanged();
|
|
}
|
|
|
|
private IReadOnlyList<FrameRow> Sorted()
|
|
{
|
|
IEnumerable<FrameRow> rows = SortBy switch
|
|
{
|
|
FrameSort.Time => _rows.OrderBy(r => r.Frame.CapturedAt),
|
|
FrameSort.Exposure => _rows.OrderBy(r => r.Frame.ExposureTime),
|
|
FrameSort.Iso => _rows.OrderBy(r => r.Frame.Iso),
|
|
FrameSort.Aperture => _rows.OrderBy(r => r.Frame.FNumber),
|
|
FrameSort.Size => _rows.OrderBy(r => (long)r.Frame.Width * r.Frame.Height),
|
|
FrameSort.Tier => _rows.OrderBy(r => r.Tier, StringComparer.CurrentCulture),
|
|
// Flagged frames together: excluded first, then by how many archive flags they carry.
|
|
FrameSort.Flags => _rows.OrderBy(r => (r.IsExcluded ? 0 : 1) * 64 - BitCount(r.Frame.Flags & FrameRow.Shown)),
|
|
_ => _rows,
|
|
};
|
|
if (SortBy != FrameSort.Number && rows is IOrderedEnumerable<FrameRow> ordered) rows = ordered.ThenBy(r => r.Index);
|
|
return SortDescending ? [.. rows.Reverse()] : [.. rows];
|
|
}
|
|
|
|
private static int BitCount(FrameFlags flags) => System.Numerics.BitOperations.PopCount((uint)flags);
|
|
|
|
private static FindingItem ToItem(Finding finding) => new(
|
|
finding.Severity switch
|
|
{
|
|
FindingSeverity.Error => StatusKind.Error,
|
|
FindingSeverity.Warning => StatusKind.Warning,
|
|
_ => StatusKind.NotAnalysed,
|
|
},
|
|
Loc.Text(finding.Key, finding.Arguments),
|
|
finding.Frames.Count > 0 ? finding.Frames[0] : null);
|
|
|
|
private void ToggleExcluded(int index) => Editor.Session.SetExcluded([index], !IsExcluded(index));
|
|
}
|