feat(app): editor session, project history, local source, preview renderer and export planner

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:00:26 +00:00
1 parent 7d95536096
commit e6d1317aab
19 files changed
+2146

No files matched your search

+76
View File
@@ -0,0 +1,76 @@
using Titano.Core.Project;
namespace Titano.App.Editor;
/// <summary>
/// Undo and redo of the editor's project (Ctrl+Z / Ctrl+Y). Projects are immutable, so each step is a snapshot.
/// Consecutive edits with the same <c>mergeKey</c> (one slider drag, typing in one field) form a single step; any
/// other edit, undo or redo ends the run. The oldest steps are dropped beyond <see cref="Capacity"/>.
/// </summary>
public sealed class ProjectHistory(ProjectSettings initial, int capacity = 200)
{
private readonly LinkedList<ProjectSettings> _undo = new();
private readonly Stack<ProjectSettings> _redo = new();
private string? _runKey;
/// <summary>The project, after any edit, undo, redo or <see cref="Replace"/>.</summary>
public event Action? Changed;
public ProjectSettings Current { get; private set; } = initial ?? throw new ArgumentNullException(nameof(initial));
public int Capacity { get; } = capacity > 0 ? capacity : throw new ArgumentOutOfRangeException(nameof(capacity));
public bool CanUndo => _undo.Count > 0;
public bool CanRedo => _redo.Count > 0;
/// <summary>Makes <paramref name="next"/> current as an undoable step; false (and nothing recorded) when it stores the same values.</summary>
public bool Apply(ProjectSettings next, string? mergeKey = null)
{
ArgumentNullException.ThrowIfNull(next);
if (ProjectMerge.SameValues(next, Current)) return false;
if (mergeKey is null || mergeKey != _runKey || _undo.Count == 0)
{
_undo.AddLast(Current);
if (_undo.Count > Capacity) _undo.RemoveFirst();
}
_runKey = mergeKey;
_redo.Clear();
Current = next;
Changed?.Invoke();
return true;
}
public bool Undo()
{
if (_undo.Last is not { } previous) return false;
_undo.RemoveLast();
_redo.Push(Current);
return Move(previous.Value);
}
public bool Redo()
{
if (!_redo.TryPop(out var next)) return false;
_undo.AddLast(Current);
return Move(next);
}
/// <summary>Adopts a project changed outside the editor (analysis advice, a merge on save) without an undo step.</summary>
public void Replace(ProjectSettings current)
{
ArgumentNullException.ThrowIfNull(current);
if (ProjectMerge.SameValues(current, Current)) return;
_runKey = null;
Current = current;
Changed?.Invoke();
}
private bool Move(ProjectSettings target)
{
_runKey = null;
Current = target;
Changed?.Invoke();
return true;
}
}