feat(P5): Render menu with grouped presets, Save frame and a fixed-width header

The editor header's button now reads "Render" whatever the preset, so its
width stays the same in every language, and the tooltip carries the preset,
size, codec, fps and estimates (owner review 1, R3, decisions 1, 2 and 12).
Its menu is rebuilt every time it opens. Top to bottom it lists:
- Recommended, the batch and up to three recent presets (taken from the
  render history);
- Other presets, grouped by Video, Social, Intermediate, Sequence and Web,
  each entry with a details line;
- Render batch, Add to queue, Save frame (PNG, JPEG or TIFF 16-bit) and
  Videos.
SplitButton learns hierarchical, two-line menu entries.

Still jobs come from EditorSession.StillRequests and carry the frame index
and the photo hash. Save frame stays disabled, with the reason in its
tooltip, in these cases:
- the sequence is read-only;
- there is no renderable frame;
- the server is older than settings format 3;
- the project is a workspace one, which has no still route yet (the
  IProjectStills hook is left for it).
A playback render is now gated on the format of the job's own export.
The project menu gains "Save project file".

Refs #21

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-05 02:18:24 +01:00
1 parent d472dfdec1
commit 7701fcac3e
9 files changed
+1137 -29

No files matched your search

+21
View File
@@ -293,6 +293,27 @@
<Setter Property="ui:ControlState.PressedBackground" Value="{DynamicResource Brush.AccentPressed}" />
</Style>
<!-- A structured entry of the ▾ menu (owner review 1, R3): its label, then the muted details line of a preset ("3840×2160 · HEVC
Main10 · 24 fps"); a header is a small muted title. Sizes and numbers read as the rest of the menu. -->
<DataTemplate x:Key="SplitButton.ItemTemplate" DataType="{x:Type v:RenderMenuItem}">
<StackPanel x:Name="Lines" Margin="0,5" VerticalAlignment="Center">
<TextBlock x:Name="Label" Text="{Binding Label}" TextTrimming="CharacterEllipsis" MaxWidth="320" />
<TextBlock x:Name="Details" Text="{Binding Details}" FontSize="{StaticResource Size.Secondary}" Foreground="{DynamicResource Brush.TextMuted}"
TextTrimming="CharacterEllipsis" MaxWidth="320" Typography.NumeralAlignment="Tabular" Margin="0,1,0,0" />
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Details}" Value="{x:Null}">
<Setter TargetName="Details" Property="Visibility" Value="Collapsed" />
<Setter TargetName="Lines" Property="Margin" Value="0" />
</DataTrigger>
<DataTrigger Binding="{Binding Kind}" Value="{x:Static v:RenderMenuItemKind.Header}">
<Setter TargetName="Label" Property="FontSize" Value="{StaticResource Size.Secondary}" />
<Setter TargetName="Label" Property="FontWeight" Value="SemiBold" />
<Setter TargetName="Label" Property="Foreground" Value="{DynamicResource Brush.TextMuted}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<Style TargetType="v:SplitButton">
<Setter Property="Height" Value="{StaticResource Height.Control}" />
<Setter Property="DropDownName" Value="{l:Loc Common.MoreChoices}" />
+159 -16
View File
@@ -10,17 +10,84 @@ using System.Windows.Input;
namespace Chronos.Ui.Visuals;
/// <summary>What a <see cref="RenderMenuItem"/> is in its menu.</summary>
public enum RenderMenuItemKind
{
/// <summary>A choice with a muted details line ("3840×2160 · HEVC Main10 · 24 fps"), checked when it is the current one.</summary>
Preset,
/// <summary>A section title ("Recommended", "Recent"): not clickable, skipped by the keyboard.</summary>
Header,
Separator,
/// <summary>An action ("Add to queue").</summary>
Command,
/// <summary>An entry that opens <see cref="RenderMenuItem.Children"/> ("Other presets ›", "Save frame ›").</summary>
Submenu,
}
/// <summary>
/// Main action on the left, a ▾ part on the right that drops down a menu of choices (Editor: "Render · preset ▾").
/// One entry of a structured <see cref="SplitButton"/> menu (owner review 1, R3: Render ▾ with headers, separators, two-line
/// presets and submenus). A view model builds the list; the button makes the menu items from it each time it opens. An
/// entry runs <see cref="Command"/> with <see cref="CommandParameter"/>; a submenu or command is shown disabled, with its
/// tooltip as the reason, when <see cref="IsEnabled"/> is false or its command cannot run.
/// </summary>
public sealed record RenderMenuItem
{
public RenderMenuItemKind Kind { get; init; }
/// <summary>The visible text, also the accessible name.</summary>
public string Label { get; init; } = string.Empty;
/// <summary>The muted second line of a preset; null for one line.</summary>
public string? Details { get; init; }
public bool IsChecked { get; init; }
public bool IsEnabled { get; init; } = true;
public ICommand? Command { get; init; }
public object? CommandParameter { get; init; }
public IReadOnlyList<RenderMenuItem> Children { get; init; } = [];
/// <summary>What the entry does, or why it is disabled (every actionable entry has one).</summary>
public string? ToolTip { get; init; }
/// <summary>A stable identity for tests and captures ("preset:4k-hevc", "batch", "frame:png"); never shown.</summary>
public string? Id { get; init; }
public static RenderMenuItem Separator { get; } = new() { Kind = RenderMenuItemKind.Separator };
public static RenderMenuItem Header(string label) => new() { Kind = RenderMenuItemKind.Header, Label = label };
/// <summary>The entries of this one and of its submenus, depth first.</summary>
public IEnumerable<RenderMenuItem> Flatten()
{
yield return this;
foreach (var child in Children.SelectMany(c => c.Flatten())) yield return child;
}
}
/// <summary>
/// Main action on the left, a ▾ part on the right that drops down a menu of choices (Editor: "Render ▾").
/// The main part executes <see cref="Command"/>; choosing a menu entry sets <see cref="SelectedItem"/> (checked in
/// the menu) — bind <see cref="CommandParameter"/> to it to act on the chosen preset. The control's ToolTip
/// describes the main action, <see cref="DropDownToolTip"/> the ▾ part. F4 or Alt+Down opens the menu.
/// <see cref="IsPrimary"/> gives the accent look of the screen's primary button. Screen readers see a split button
/// (named by AutomationProperties.Name or the content) that invokes and expands, holding the two parts;
/// the menu) — bind <see cref="CommandParameter"/> to it to act on the chosen preset. When <see cref="ItemsSource"/>
/// holds <see cref="RenderMenuItem"/>s, the menu is structured instead (headers, separators, two-line items, submenus,
/// each with its own command and tooltip) and read again from the binding every time it opens, so it never shows a stale
/// state. The control's ToolTip describes the main action, <see cref="DropDownToolTip"/> the ▾ part. F4 or Alt+Down opens
/// the menu. <see cref="IsPrimary"/> gives the accent look of the screen's primary button. Screen readers see a split
/// button (named by AutomationProperties.Name or the content) that invokes and expands, holding the two parts;
/// <see cref="DropDownName"/> names the ▾ part.
/// </summary>
public class SplitButton : Control
{
/// <summary>The header template of structured entries (Visuals.xaml): the label and, below it, the muted details.</summary>
public const string ItemTemplateKey = "SplitButton.ItemTemplate";
public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(nameof(Content), typeof(object), typeof(SplitButton));
public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(nameof(Command), typeof(ICommand), typeof(SplitButton));
public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register(nameof(CommandParameter), typeof(object), typeof(SplitButton));
@@ -42,6 +109,9 @@ public class SplitButton : Control
private ContextMenu? _menu;
/// <summary>The open menu was made from <see cref="RenderMenuItem"/>s (its entries run their own commands).</summary>
private bool _structured;
static SplitButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(SplitButton), new FrameworkPropertyMetadata(typeof(SplitButton)));
@@ -114,33 +184,106 @@ public class SplitButton : Control
}
}
/// <summary>The drop-down menu as it is now (made on the first open, filled again on every open); null before.</summary>
internal ContextMenu? Menu => _menu;
/// <summary>
/// The control of one structured entry: a <see cref="Separator"/>, or a <see cref="MenuItem"/> whose header is the entry
/// (shown by <paramref name="template"/>, its label alone without one) with its command, check, tooltip and submenu.
/// </summary>
internal static Control CreateItem(RenderMenuItem entry, DataTemplate? template)
{
ArgumentNullException.ThrowIfNull(entry);
if (entry.Kind == RenderMenuItemKind.Separator) return new Separator();
var item = new MenuItem
{
Header = template is null ? entry.Label : entry,
HeaderTemplate = template,
IsChecked = entry.IsChecked,
Command = entry.Command,
CommandParameter = entry.CommandParameter,
ToolTip = entry.ToolTip,
};
AutomationProperties.SetName(item, entry.Label);
if (entry.Details is { Length: > 0 } details) AutomationProperties.SetHelpText(item, details);
if (entry.Id is { Length: > 0 } id) AutomationProperties.SetAutomationId(item, id);
ToolTipService.SetShowOnDisabled(item, true);
if (!entry.IsEnabled) item.IsEnabled = false;
switch (entry.Kind)
{
case RenderMenuItemKind.Header:
// A title, not a choice: the keyboard and the mouse pass over it, and it keeps its full contrast.
item.Focusable = false;
item.IsHitTestVisible = false;
item.Height = 26;
break;
case RenderMenuItemKind.Submenu:
foreach (var child in entry.Children) item.Items.Add(CreateItem(child, template));
break;
}
if (entry.Details is { Length: > 0 })
{
// Two lines: the menu's 32 px rows give way to the label over its details.
item.Height = double.NaN;
item.MinHeight = 32;
}
return item;
}
private ContextMenu EnsureMenu()
{
if (_menu is not null) return _menu;
var menu = new ContextMenu { PlacementTarget = this, Placement = PlacementMode.Bottom, VerticalOffset = 4 };
if (_menu is null)
{
var menu = new ContextMenu { PlacementTarget = this, Placement = PlacementMode.Bottom, VerticalOffset = 4 };
menu.SetBinding(DataContextProperty, new Binding(nameof(DataContext)) { Source = this });
menu.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(OnMenuItemClick));
menu.Opened += (_, _) => MarkSelected();
menu.Closed += (_, _) => SetCurrentValue(IsDropDownOpenProperty, false);
_menu = menu;
}
Populate(_menu);
return _menu;
}
/// <summary>
/// Fills the menu for this opening: structured entries made again from the binding as it reads now (the state of the
/// commands, the current preset and the reasons may have changed since the last time), otherwise the items bound as a
/// plain list of choices.
/// </summary>
private void Populate(ContextMenu menu)
{
GetBindingExpression(ItemsSourceProperty)?.UpdateTarget();
var entries = ItemsSource?.OfType<RenderMenuItem>().ToList() ?? [];
_structured = entries.Count > 0;
if (_structured)
{
foreach (var property in new[] { ItemsControl.ItemsSourceProperty, ItemsControl.ItemTemplateProperty, ItemsControl.ItemContainerStyleProperty, ItemsControl.DisplayMemberPathProperty })
BindingOperations.ClearBinding(menu, property);
menu.Items.Clear();
var template = TryFindResource(ItemTemplateKey) as DataTemplate;
foreach (var entry in entries) menu.Items.Add(CreateItem(entry, template));
return;
}
if (BindingOperations.IsDataBound(menu, ItemsControl.ItemsSourceProperty)) return;
menu.Items.Clear();
menu.SetBinding(ItemsControl.ItemsSourceProperty, new Binding(nameof(ItemsSource)) { Source = this });
menu.SetBinding(ItemsControl.ItemTemplateProperty, new Binding(nameof(ItemTemplate)) { Source = this });
menu.SetBinding(ItemsControl.ItemContainerStyleProperty, new Binding(nameof(ItemContainerStyle)) { Source = this });
menu.SetBinding(ItemsControl.DisplayMemberPathProperty, new Binding(nameof(DisplayMemberPath)) { Source = this });
menu.SetBinding(DataContextProperty, new Binding(nameof(DataContext)) { Source = this });
menu.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(OnMenuItemClick));
menu.Opened += (_, _) => MarkSelected();
menu.Closed += (_, _) => SetCurrentValue(IsDropDownOpenProperty, false);
_menu = menu;
return menu;
}
private void OnMenuItemClick(object sender, RoutedEventArgs e)
{
if (_menu is null || e.OriginalSource is not MenuItem container) return;
// Structured entries run their own commands; a plain list's entry becomes the choice.
if (_menu is null || _structured || e.OriginalSource is not MenuItem container) return;
var item = _menu.ItemContainerGenerator.ItemFromContainer(container);
if (item != DependencyProperty.UnsetValue) SetCurrentValue(SelectedItemProperty, item);
}
/// <summary>Checks the menu entry of the current choice.</summary>
/// <summary>Checks the menu entry of the current choice (structured entries carry their own check).</summary>
private void MarkSelected()
{
if (_menu is null) return;
if (_menu is null || _structured) return;
_menu.UpdateLayout();
for (var i = 0; i < _menu.Items.Count; i++)
if (_menu.ItemContainerGenerator.ContainerFromIndex(i) is MenuItem container)