Files
Chronos/src/Chronos.App/Editor/FramesTab.cs
T
Alby96andClaude Opus 5.5 f2b58522b9
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
The owner renamed the product and moved the repository to the self-hosted
Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control,
and asked for Actions and a first automatic release with the server package
and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md).

- Chronos everywhere: a byte-exact rename of contents and paths, then a
  per-language review of the forms the old name's ending had dictated.
- Gitea instead of GitHub: the update check, licence, issue and support
  links read ChronosReleasesUrl; the update check takes the highest stable
  version, offers a pre-release build its final release and reports a
  repository it cannot see as a failed check. EULA, security policy and
  Gitea issue forms live at the repository root.
- Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release,
  nightly image and performance gates in the .NET SDK container with git
  checkout and the system SQLite. The release cross-compiles the Windows
  programs, checks their icon, version and DPI manifest, packs installers
  and zips, publishes the Gitea release and pushes the server image
  (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows
  runner (WINDOWS_RUNNER).
- New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the
  docker-exec script, which Gitea's service containers do not allow; the
  throw-away server runs without durability) and pe-check.
- Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR,
  3 on the shared runner; the weekly performance gates keep theirs).

BREAKING CHANGE: programs, settings, data folders, file types, environment
variables and the Docker image use the new name; nothing is migrated from
Titano, which never had a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-10-23 12:45:18 +02:00

313 lines
12 KiB
C#

using System.Windows.Input;
using Chronos.Core.Advice;
using Chronos.Core.Analysis;
using Chronos.Core.Localization;
using Chronos.Core.Model;
using Chronos.Ui.Controls;
using Chronos.Ui.Mvvm;
namespace Chronos.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 name, 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;
/// <summary>"Time", "Decode" (narrow columns cut it at the minimum window: <see cref="ToolTip"/> has it whole).</summary>
public string Header => Loc.L("Editor.Frames.Column." + Sort);
/// <summary>"Time · Sort by this column…".</summary>
public string ToolTip => string.Join(Loc.Separator, Header, Loc.L("Tooltips.Editor.Frames.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(Header));
OnPropertyChanged(nameof(ToolTip));
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);
}
}
/// <summary><see cref="Flags"/> whole, where the column cuts it; none on a frame without flags.</summary>
public string? FlagsToolTip => Flags is { Length: > 0 } flags ? flags : null;
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(FlagsToolTip));
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 about frames; 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();
// A language switch arrives here too: the headers follow.
foreach (var column in Columns) column.Refresh();
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();
// The findings this step deals with, and those no step deals with; the Analysis step lists them all.
Findings = [.. Editor.Session.Advice.Findings.Where(f => EditPath.StepOf(f.Key) is null or EditPath.Frames).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);
internal 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));
}