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

+11 -27
View File
@@ -40,7 +40,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
private readonly LatestRunner _corrections = new(Debounce);
private readonly LatestRunner _plans = new(Debounce);
private readonly DispatcherTimer _player;
private readonly Dictionary<Guid, Job> _jobs = [];
private readonly SequenceJobs _jobs;
private readonly AsyncRelayCommand _analyse;
private readonly AsyncRelayCommand _render;
private readonly AsyncRelayCommand _cancelServerJob;
@@ -83,6 +83,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
_encoders = encoders;
_host = host;
_dispatcher = Dispatcher.CurrentDispatcher;
_jobs = new SequenceJobs(session.Content.Sequence.Id);
_renderer = new PreviewRenderer(session.Content, session.Source);
Planner = new ExportPlanner(session.Content, encoders, host);
_thumbnails = new EditorThumbnails(session.Source, session.Content.Count);
@@ -181,10 +182,8 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
/// <summary>The Export "Sync" option: available, or why not.</summary>
public ExportSyncGate SyncGate { get => _syncGate; private set => Set(ref _syncGate, value); }
/// <summary>The server job the header shows: one running, else one paused, else the oldest waiting.</summary>
private Job? ServerJob => IsRemote
? _jobs.Values.OrderBy(j => j.State switch { JobState.Running => 0, JobState.Paused => 1, _ => 2 }).ThenBy(j => j.Started ?? j.Created).FirstOrDefault()
: null;
/// <summary>The server job the header shows (<see cref="SequenceJobs.Shown"/>).</summary>
private Job? ServerJob => IsRemote ? _jobs.Shown : null;
/// <summary>
/// "3,600 frames · Canon EOS R5 · 2 s interval · 2 h 00 m · 3 warnings"; on the Export tab what the video will be:
@@ -373,10 +372,10 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
public ExportPlan? Plan { get => _plan; private set => Set(ref _plan, value); }
/// <summary>An analysis or render of this sequence is running: settings wait, viewing tools stay live.</summary>
public bool IsBusy => _jobs.Values.Any(j => j.State == JobState.Running);
public bool IsBusy => _jobs.IsBusy;
/// <summary>A deep analysis of this sequence is queued, running or paused (Analyse would queue it twice).</summary>
public bool IsAnalysing => _jobs.Values.Any(j => j.Kind == JobKind.DeepAnalyse);
public bool IsAnalysing => _jobs.IsAnalysing;
/// <summary>
/// The project is shown, not changed: a server sequence for an account without the Edit right, or one whose frames
@@ -573,7 +572,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
{
await RefreshSyncGateAsync();
var jobs = await Session.Source.ListJobsAsync(CancellationToken.None);
foreach (var job in jobs) Track(job);
foreach (var job in jobs) _jobs.Track(job);
foreach (var job in jobs.OrderBy(j => j.Finished)) LearnAnalysisSpeed(job);
OnBusyChanged();
}
@@ -875,13 +874,13 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
private void OnJobChanged(Job job)
{
if (!Concerns(job)) return;
if (!_jobs.Concerns(job)) return;
_dispatcher.BeginInvoke(() =>
{
if (_disposed) return;
var wasActive = _jobs.ContainsKey(job.Id);
var wasActive = _jobs.IsActive(job.Id);
// Progress alone (several times a second on a server) only moves the server job's text and bar.
if (Track(job)) OnBusyChanged();
if (_jobs.Track(job)) OnBusyChanged();
else OnServerJobChanged();
LearnAnalysisSpeed(job);
if (!wasActive) return;
@@ -892,7 +891,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
/// <summary>
/// The frames of the server sequence changed while it is open (any thread): everything that changes the project is
/// disabled and saying why, and a toast offers to fetch the proxies again.
/// disabled and says why, and a toast offers to fetch the proxies again.
/// </summary>
private void OnReadOnlyChanged() => _dispatcher.BeginInvoke(() =>
{
@@ -951,21 +950,6 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
}
}
/// <summary>An analysis or render of this sequence.</summary>
private bool Concerns(Job job) =>
job.TargetIds.Contains(Session.Content.Sequence.Id) && job.Kind is JobKind.DeepAnalyse or JobKind.LightAnalyse or JobKind.Render;
/// <summary>Keeps the jobs of this sequence that wait, run or are paused.</summary>
/// <returns>Whether a job joined or left them or changed state (progress alone does not count).</returns>
private bool Track(Job job)
{
if (!Concerns(job)) return false;
if (job.State is not (JobState.Queued or JobState.Running or JobState.Paused)) return _jobs.Remove(job.Id);
var changed = !_jobs.TryGetValue(job.Id, out var known) || known.State != job.State;
_jobs[job.Id] = job;
return changed;
}
/// <summary>Seconds per frame of the latest finished deep analysis (any sequence): the cost Analyse announces.</summary>
private void LearnAnalysisSpeed(Job job)
{