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

+121 -4
View File
@@ -1,12 +1,129 @@
using System.ComponentModel;
using System.IO;
using System.Windows.Input;
using Titano.App.Editor;
using Titano.App.Shell;
using Titano.Core.Diagnostics;
using Titano.Core.Export;
using Titano.Core.Imaging.Decoders;
using Titano.Core.Localization;
using Titano.Data.Archiving;
using Titano.Ui.Mvvm;
namespace Titano.App.Sections;
/// <summary>Sequence editor (BRIEF §12.3).</summary>
public sealed class SequenceViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.Sequence, "Icon.Sequence")
/// <summary>
/// The Sequence section (BRIEF §12.3): opens the sequence the Library (or Jobs) chose into an <see cref="EditorViewModel"/>
/// and closes the previous one after saving it; without a sequence it shows the empty state.
/// </summary>
public sealed class SequenceViewModel : SectionViewModel
{
public ShellViewModel Shell { get; } = shell;
public ICommand OpenLibraryCommand => new RelayCommand(() => Shell.Navigate(SectionKey.Library));
private EditorViewModel? _editor;
private Guid? _openId;
private bool _isLoading;
private Task _switch = Task.CompletedTask;
public SequenceViewModel(ShellViewModel shell)
: base(SectionKey.Sequence, "Icon.Sequence")
{
Shell = shell;
OpenLibraryCommand = new RelayCommand(() => Shell.Navigate(SectionKey.Library));
shell.PropertyChanged += OnShellChanged;
}
public ShellViewModel Shell { get; }
public ICommand OpenLibraryCommand { get; }
/// <summary>The open sequence; null shows the empty state.</summary>
public EditorViewModel? Editor
{
get => _editor;
private set
{
if (!Set(ref _editor, value)) return;
OnPropertyChanged(nameof(IsEmpty));
OnPropertyChanged(nameof(Title));
}
}
public bool IsLoading { get => _isLoading; private set => Set(ref _isLoading, value); }
public bool IsEmpty => _editor is null && !_isLoading;
/// <summary>"Titano — Harbour sunset" while a sequence is open.</summary>
public override string Title => _editor?.Title ?? Label;
/// <summary>Opens <paramref name="sequenceId"/> (the editor of another sequence is saved and closed first).</summary>
public Task OpenAsync(Guid sequenceId)
{
_switch = SwitchAsync(_switch, sequenceId);
return _switch;
}
/// <summary>Saves and closes the open sequence.</summary>
public async Task CloseAsync()
{
await _switch;
if (Editor is not { } editor) return;
Editor = null;
_openId = null;
await editor.DisposeAsync();
}
public override void Dispose()
{
Shell.PropertyChanged -= OnShellChanged;
Editor?.Dispose();
base.Dispose();
}
protected override void OnActivated()
{
if (Shell.CurrentSequenceId is { } id && id != _openId) _ = OpenAsync(id);
}
private void OnShellChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(ShellViewModel.CurrentSequenceId) && IsSelected) OnActivated();
}
private async Task SwitchAsync(Task previous, Guid sequenceId)
{
await previous;
if (sequenceId == _openId) return;
var services = Shell.Services;
IsLoading = true;
OnPropertyChanged(nameof(IsEmpty));
try
{
if (Editor is { } old)
{
Editor = null;
await old.DisposeAsync();
}
_openId = sequenceId;
if (services.Database is not { } db) throw new InvalidOperationException(Loc.L("Editor.Error.NoEngine"));
var processing = services.Processing?.Options;
var source = new LocalSequenceSource(db, sequenceId, processing?.Archive.Decoder ?? DecoderFactory.CreateClient(null), services.Engine,
processing?.Archive);
var content = await source.LoadAsync(CancellationToken.None);
var encoders = processing?.Encoders ?? [];
var session = new EditorSession(source, content, [.. encoders.SelectMany(e => e.Capabilities)]);
var editor = new EditorViewModel(Shell, session, encoders, processing?.Host ?? EncoderHost.Client);
Editor = editor;
await editor.AttachJobsAsync();
}
catch (Exception ex) when (ex is InvalidDataException or InvalidOperationException or IOException or UnauthorizedAccessException)
{
_openId = null;
Log.Warning("editor", $"Sequence {sequenceId} could not be opened", ex);
Shell.ReportError(ex);
}
finally
{
IsLoading = false;
OnPropertyChanged(nameof(IsEmpty));
}
}
}