refactor(editor): the open sequence's jobs in their own type; restore undo as an object

WIP of the interrupted fix stage.

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-06 07:49:27 +00:00
1 parent 757695f037
commit 31c1a2d9c6
9 files changed
+356 -42

No files matched your search

+17 -3
View File
@@ -148,14 +148,16 @@ public sealed class EditorSession : IAsyncDisposable
: [RenderRequest(export)];
/// <summary>
/// Makes a "Save both" copy of this PC's settings the project, as one undoable step; false when it stores the same values.
/// Makes a "Save both" copy of this PC's settings the project, as one undoable step; null when it stores the same values.
/// </summary>
/// <returns>The restore, which its toast can take back while it is the last change.</returns>
/// <exception cref="System.IO.InvalidDataException">The copy cannot be read.</exception>
public async Task<bool> RestoreAsync(SavedCopy copy)
public async Task<ProjectRestore?> RestoreAsync(SavedCopy copy)
{
ArgumentNullException.ThrowIfNull(copy);
var restored = await Task.Run(() => SavedCopies.Read(copy));
return Edit(_ => restored);
var before = Project;
return Edit(_ => restored) ? new ProjectRestore(this, before, Project) : null;
}
/// <summary>The export of the project with preset <paramref name="presetId"/> chosen (own values, no batch).</summary>
@@ -235,3 +237,15 @@ public sealed class EditorSession : IAsyncDisposable
if (!ProjectMerge.SameValues(stored, project)) History.Replace(ProjectMerge.Merge(project, Project, stored));
}
}
/// <summary>
/// A "Save both" copy made the project (<see cref="EditorSession.RestoreAsync"/>). Its Undo brings back the project from
/// before as a new step, and only while the restore is still the last change: after another edit, an undo or a merged
/// save it would take that change back instead.
/// </summary>
public sealed class ProjectRestore(EditorSession session, ProjectSettings before, ProjectSettings restored)
{
public bool CanUndo => ReferenceEquals(session.Project, restored);
public bool Undo() => CanUndo && session.Edit(_ => before);
}