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:
5 files changed
+26
-11
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user