feat(app): editor view models for every section, preset cards and render actions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 17:14:48 +00:00
1 parent e6d1317aab
commit f6ad822fbb
15 files changed
+2666 -6

No files matched your search

+199
View File
@@ -0,0 +1,199 @@
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>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>
private static readonly FrameFlags[] ShownFlags =
[FrameFlags.Missing, FrameFlags.Corrupt, FrameFlags.Duplicate, FrameFlags.Undecodable, FrameFlags.Black, FrameFlags.White];
public int Index { get; } = index;
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(" · ", 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 => Loc.L(IsExcluded ? "Tooltips.Editor.Frames.Include" : "Tooltips.Editor.Frames.Exclude");
/// <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 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.IsBusy);
SetHeroCommand = new RelayCommand(p => Editor.Session.SetHero(p is FrameRow row ? row.Index : Editor.CurrentIndex), _ => !Editor.IsBusy);
SeekCommand = new RelayCommand(p =>
{
if (p is FindingItem { Frame: { } frame }) Editor.CurrentIndex = frame;
});
Load();
}
public IReadOnlyList<FrameRow> Frames { get => _frames; private set => Set(ref _frames, value); }
public IReadOnlyList<FindingItem> Findings { get => _findings; private set => Set(ref _findings, value); }
/// <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 => Loc.L(IsCurrentExcluded ? "Tooltips.Editor.Frames.Include" : "Tooltips.Editor.Frames.Exclude");
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);
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)Frames.Count) Frames[index].Refresh();
}
OnPropertyChanged(nameof(HeroText));
OnPropertyChanged(nameof(ExcludedText));
OnCurrentFrameChanged();
}
public override void OnContentChanged()
{
Load();
base.OnContentChanged();
}
public void OnCurrentFrameChanged()
{
var index = Editor.CurrentIndex;
if ((uint)index < (uint)Frames.Count && !ReferenceEquals(_selected, Frames[index]))
{
_selected = Frames[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;
Frames = [.. content.Frames.Select((f, i) => new FrameRow(this, f, i))];
Findings = [.. Editor.Session.Advice.Findings.OrderByDescending(f => f.Severity).Select(ToItem)];
_selected = null;
OnCurrentFrameChanged();
}
private static FindingItem ToItem(Finding finding) => new(
finding.Severity switch
{
FindingSeverity.Error => StatusKind.Error,
FindingSeverity.Warning => StatusKind.Warning,
_ => StatusKind.NotAnalysed,
},
Loc.L(finding.Key, finding.Arguments),
finding.Frames.Count > 0 ? finding.Frames[0] : null);
private void ToggleExcluded(int index) => Editor.Session.SetExcluded([index], !IsExcluded(index));
}