using System.Windows.Input; using Chronos.Core.Advice; using Chronos.Core.Localization; using Chronos.Ui.Mvvm; namespace Chronos.App.Editor; /// /// One step of the Edit path (BRIEF §12.3, owner review 1 R7): its measuring tool below the filmstrip and its column /// on the right, with "Optimise section" and "Reset" for a section the advisor decides. runs after /// every project change; the editor sets where the step stands (). /// public abstract class EditorTab : LocalizedViewModel { private StepState _state = new(StepStatus.Todo, string.Empty); private bool _isVisited; protected EditorTab(EditorViewModel editor, string key, AdvisorSection? section) { Editor = editor; Key = key; Section = section; OptimiseCommand = new RelayCommand(() => { if (Section is { } s) Editor.Optimise(s); }, () => CanOptimise && !Editor.IsLocked); ResetCommand = new RelayCommand(() => { if (Section is { } s) Editor.Session.ResetSection(s); }, () => CanReset && !Editor.IsLocked); } public EditorViewModel Editor { get; } /// "Frames", "Exposure"… (resource key suffix and step). public string Key { get; } /// The advisor section of the step; null for a step the advisor does not decide (Analysis). public AdvisorSection? Section { get; } public string Header => Loc.L("Editor.Tab." + Key); public string ToolTip => Loc.L("Tooltips.Editor.Tab." + Key); /// Settings rows of the right column (empty for tabs with their own panel). public IReadOnlyList Rows { get; protected init; } = []; /// The advisor has heavier decisions for this section (stacking and the analysis have none). public virtual bool CanOptimise => Section is not null; public virtual bool CanReset => Section is not null; /// What Optimise section does, or why it cannot run now. public string OptimiseToolTip => !CanOptimise ? Loc.L("Tooltips.Editor.OptimiseNone") : Editor.LockedToolTip ?? Loc.L("Tooltips.Editor.OptimiseSection"); public string ResetToolTip => Editor.LockedToolTip ?? Loc.L("Tooltips.Editor.ResetSection"); public ICommand OptimiseCommand { get; } public ICommand ResetCommand { get; } // ---- The step ---- /// Position on the path, from 1. public int Number { get; internal set; } /// The path's last step (its connector line is not drawn). public bool IsLast { get; internal set; } /// Alt+1…Alt+9; empty from the tenth step on. public string Shortcut => Number is >= 1 and <= 9 ? Loc.L("Editor.Step.Shortcut", Number) : string.Empty; /// The user opened the step since the sequence opened (or since the analysis it waited for ended). public bool IsVisited { get => _isVisited; internal set => Set(ref _isVisited, value); } public StepStatus Status => _state.Status; /// "Auto", "3 flagged frames", "Not rendered" (three words at most). public string StateText => _state.Text; /// A sentence on the state, when there is more to say than . public string? StateDetail => _state.Detail; /// "Exposure · what the step is for · its state · Alt+3": the name first, so a name cut in the step bar can be read whole. public string StepToolTip => Shortcut.Length > 0 ? Loc.L("Tooltips.Editor.Step", Header, ToolTip, StateDetail ?? StateText, Number) : string.Join(Loc.Separator, Header, ToolTip, StateDetail ?? StateText); /// The measuring area takes more of the height than the preview (the findings, the preset cards). public virtual bool PrefersTallMeasure => false; /// Where the step stands now; raises only what changed. public void SetStep(StepState state) { ArgumentNullException.ThrowIfNull(state); if (state == _state) return; var old = _state; _state = state; if (old.Status != state.Status) OnPropertyChanged(nameof(Status)); if (old.Text != state.Text) OnPropertyChanged(nameof(StateText)); if (old.Detail != state.Detail) OnPropertyChanged(nameof(StateDetail)); OnPropertyChanged(nameof(StepToolTip)); } /// Re-reads the project (any change). public virtual void Refresh() { foreach (var row in Rows) row.Refresh(); } /// The sequence was read again: new analyses (charts, findings). public virtual void OnContentChanged() => Refresh(); /// The preview's corrections were prepared for the current settings (target curves). public virtual void OnCorrectionsChanged() { } /// The export plan of the project changed (durations, sizes). public virtual void OnPlanChanged() { } /// The frame on screen changed (playheads, the frame table, keyframe commands). public virtual void OnCurrentFrameChanged() { } /// A job of this sequence started or ended: commands and their tooltips follow. public virtual void OnBusyChanged() { OnPropertyChanged(nameof(OptimiseToolTip)); OnPropertyChanged(nameof(ResetToolTip)); } /// Raises the enabled state of the tab's asynchronous commands (the others follow the command manager). public virtual void RefreshCommands() { } /// Whether this sequence can send its renders to the server changed (). public virtual void OnSyncGateChanged() { } public override void Dispose() { foreach (var row in Rows) row.Dispose(); base.Dispose(); } }