fix(ui): the viewport's tools are its logical children; remote editor tests read a shared job table safely

The preview tools are a property value of the viewport, presented by its template
with no logical parent, so neither an element-name nor an ancestor binding gave
them the editor reliably: the crop result toggle then showed with no tooltip.
As logical children they inherit the viewport's data context like any content.

The remote editor tests changed the fake server's job table while the source's
event loop read it, which could hand the loop a null job; it is now a concurrent
dictionary. The read-only test waits for the event, which is raised after the
flag is set, instead of the flag.

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-11 23:20:51 +00:00
1 parent c5a01c1290
commit 77e07bf000
5 files changed
+26 -11

No files matched your search

+2 -6
View File
@@ -124,12 +124,8 @@
CropMaskMode="{Binding CropMaskMode}" InfoText="{Binding InfoText}" ToolTip="{l:Loc Tooltips.Editor.Preview.View}"
AutomationProperties.Name="{l:Loc Editor.Preview}" SizeChanged="OnPreviewSizeChanged">
<v:PreviewViewport.ToolsContent>
<!--
Tools give the keyboard back to the preview after a click, so Space keeps playing (OnToolClicked). The viewport
presents them outside the view's logical tree, so they take the editor from the viewport they sit in.
-->
<StackPanel Orientation="Horizontal" DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=v:PreviewViewport}}"
ButtonBase.Click="OnToolClicked">
<!-- Tools give the keyboard back to the preview after a click, so Space keeps playing (OnToolClicked). -->
<StackPanel Orientation="Horizontal" ButtonBase.Click="OnToolClicked">
<ToggleButton Style="{StaticResource ToggleButton.PreviewTool}" IsChecked="{Binding IsCompare}" ui:ButtonIcon.Glyph="{StaticResource Icon.Compare}"
Content="{l:Loc Editor.Preview.Compare}" ToolTip="{l:Loc Tooltips.Editor.Preview.Compare}" />
<ToggleButton Visibility="{Binding IsExportTab, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" Style="{StaticResource ToggleButton.PreviewTool}"
+17 -2
View File
@@ -1,3 +1,4 @@
using System.Collections;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
@@ -106,7 +107,8 @@ public class PreviewViewport : Control
public static readonly DependencyProperty InfoTextProperty = DependencyProperty.Register(nameof(InfoText), typeof(string), typeof(PreviewViewport));
public static readonly DependencyProperty ToolsContentProperty = DependencyProperty.Register(nameof(ToolsContent), typeof(object), typeof(PreviewViewport));
public static readonly DependencyProperty ToolsContentProperty = DependencyProperty.Register(
nameof(ToolsContent), typeof(object), typeof(PreviewViewport), new PropertyMetadata(null, OnToolsContentChanged));
private const double MinZoom = 0.01;
private const double MaxZoom = 32;
@@ -185,9 +187,15 @@ public class PreviewViewport : Control
/// <summary>Shot data shown in the bottom-right pill.</summary>
public string? InfoText { get => (string?)GetValue(InfoTextProperty); set => SetValue(InfoTextProperty, value); }
/// <summary>Tool buttons shown bottom-left over the image.</summary>
/// <summary>
/// Tool buttons shown bottom-left over the image. They are logical children of the viewport, so they take its data
/// context and resources like any content, although the template presents them.
/// </summary>
public object? ToolsContent { get => GetValue(ToolsContentProperty); set => SetValue(ToolsContentProperty, value); }
protected override IEnumerator LogicalChildren =>
ToolsContent is { } tools ? new[] { tools }.GetEnumerator() : base.LogicalChildren;
/// <summary>Current image-to-view transform in DIPs (for hit testing overlays from outside).</summary>
public ViewTransform View => _view;
@@ -198,6 +206,13 @@ public class PreviewViewport : Control
private double PixelScale => VisualTreeHelper.GetDpi(this).DpiScaleX;
private static void OnToolsContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var viewport = (PreviewViewport)d;
if (e.OldValue is not null) viewport.RemoveLogicalChild(e.OldValue);
if (e.NewValue is not null) viewport.AddLogicalChild(e.NewValue);
}
public override void OnApplyTemplate()
{
if (_surface is not null) _surface.SizeChanged -= OnSurfaceSizeChanged;
@@ -1,3 +1,4 @@
using System.Collections.Concurrent;
using System.Net;
using System.Runtime.CompilerServices;
using System.Threading.Channels;
@@ -39,7 +40,8 @@ internal sealed class FakeRemoteSequenceApi(Sequence sequence, IReadOnlyList<Gui
/// <summary>Priorities set after jobs were posted (job, wire name).</summary>
public List<(Guid Job, string Priority)> Priorities { get; } = [];
public Dictionary<Guid, JobDto> Jobs { get; } = [];
/// <summary>The server's jobs; tests change them while the source's event loop reads them.</summary>
public ConcurrentDictionary<Guid, JobDto> Jobs { get; } = new();
/// <summary>Thrown by the next read of a job (a failure the editor's event listener does not expect).</summary>
public Exception? FailNextJobRead { get; set; }
@@ -413,7 +413,9 @@ public sealed class RemoteSequenceSourceTests(TestContext context)
api.FramesVersion = 3;
api.Publish(new SequenceChangedEvent(Guid.CreateVersion7(), "frames", 7, 1));
api.Publish(new SequenceChangedEvent(remote.Sequence.Id, "frames", 3, api.SettingsVersion));
await WaitAsync(() => source.IsOutdated);
// The flag is set before the event is raised: wait for the event, which comes last.
await WaitAsync(() => Volatile.Read(ref changes) > 0);
Assert.True(source.IsOutdated);
Assert.True(source.IsReadOnly);
Assert.Equal(1, Volatile.Read(ref changes));
@@ -334,7 +334,7 @@ public sealed class ScreenSmokeTests
{
var name = AutomationProperties.GetName(control);
Assert.False(string.IsNullOrWhiteSpace(name), $"{screen}: an icon-only {control.GetType().Name} bound to {(control as ButtonBase)?.Command} has no name");
Assert.True(control.ToolTip is not null, $"{screen}: '{name}' has no tooltip");
Assert.True(control.ToolTip is not null, $"{screen}: '{name}' has no tooltip (data context: {control.DataContext?.GetType().Name ?? "none"})");
}
}