* ci: Qodana - a workflow of its own from JetBrains' template, Qodana Community for .NET over FrameLedger.slnx (D93) The first run: the linter in its Linux container, EnableWindowsTargeting passed to it, no quality gate yet - what it builds and what it reports decides the rest. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * ci: Qodana's gate is zero problems, and the inspections this project argues with are off in .editorconfig, each with its reason (D93) Pushed before the fixes on purpose: the run this starts has the settings and none of the fixes, so it shows the gate failing on what is left. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * fix: what Qodana's first run reported, settled - about 400 fixes in 181 files, none changing behaviour; the documents (D93) Redundant qualifiers, casts, using directives, nullable suppressions and unsafe modifiers removed from the report's own positions; var for built-in types and one-line block bodies brought to .editorconfig's style by dotnet format; every XAML item template names its DataType and a binding that reached its page through DataContext.ViewModel names the page's type; two unread fields, two overwritten initialisers and an unused parameter removed; SpokenTextAutomationPeer no longer assumes the base peer's name is a string. docs/13_CI_CD.md §Qodana, CLAUDE.md, the wiki's workflow table, HANDOFF's decisions index (D93) and the changelog entry. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
184 lines
7.7 KiB
C#
184 lines
7.7 KiB
C#
// SPDX-License-Identifier: GPL-3.0-only
|
|
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
|
|
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Threading;
|
|
using Wpf.Ui.Appearance;
|
|
using Wpf.Ui.Markup;
|
|
|
|
namespace FrameLedger.App.Tests;
|
|
|
|
/// <summary>
|
|
/// Visual-tree helpers for the rendered checks (beta.14), all run on <see cref="PagesLoadTests.OnStaAsync{T}"/>'s thread:
|
|
/// find elements, pump the dispatcher, lay out at a size, swap the theme for one check, and the colour actually painted
|
|
/// under an element — the stack of backgrounds a pixel shows, composited, rather than one control's Background property.
|
|
/// </summary>
|
|
internal static class Visuals
|
|
{
|
|
public static T? Find<T>(DependencyObject root)
|
|
where T : DependencyObject => FindAll<T>(root).FirstOrDefault();
|
|
|
|
public static IEnumerable<T> FindAll<T>(DependencyObject root)
|
|
where T : DependencyObject
|
|
{
|
|
int count = VisualTreeHelper.GetChildrenCount(root);
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
DependencyObject child = VisualTreeHelper.GetChild(root, i);
|
|
if (child is T hit)
|
|
{
|
|
yield return hit;
|
|
}
|
|
|
|
foreach (T deeper in FindAll<T>(child))
|
|
{
|
|
yield return deeper;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>The innermost element under <paramref name="root"/> along first children — where a pointer over it would land.</summary>
|
|
public static UIElement Leaf(UIElement root)
|
|
{
|
|
UIElement current = root;
|
|
while (VisualTreeHelper.GetChildrenCount(current) > 0 && VisualTreeHelper.GetChild(current, 0) is UIElement child)
|
|
{
|
|
current = child;
|
|
}
|
|
|
|
return current;
|
|
}
|
|
|
|
/// <summary>Runs the dispatcher's queue down to background priority — a Frame's navigation, Loaded, a deferred layout.</summary>
|
|
public static void Pump()
|
|
{
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
var frame = new DispatcherFrame();
|
|
#pragma warning disable VSTHRD001 // a test's own STA thread: no JoinableTaskFactory exists here, and the frame is what is waited on
|
|
_ = Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(_ =>
|
|
{
|
|
frame.Continue = false;
|
|
return null;
|
|
}), null);
|
|
#pragma warning restore VSTHRD001
|
|
Dispatcher.PushFrame(frame);
|
|
}
|
|
}
|
|
|
|
public static void Layout(FrameworkElement element, double width, double height)
|
|
{
|
|
element.Measure(new Size(width, height));
|
|
element.Arrange(new Rect(0, 0, width, height));
|
|
element.UpdateLayout();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Windows' default accent. The App derives its accent resources from the system's at each theme switch; the checks
|
|
/// derive them from this one colour, so a result does not depend on the machine's personalisation.
|
|
/// </summary>
|
|
public static readonly Color DefaultAccent = Color.FromRgb(0x00, 0x78, 0xD4);
|
|
|
|
/// <summary>
|
|
/// Runs <paramref name="work"/> under <paramref name="theme"/> the way the App switches (<c>WpfThemeApplier</c> →
|
|
/// <c>ApplicationThemeManager.Apply(theme, …, updateAccent: true)</c>): the accent resources derived for the theme from
|
|
/// <see cref="DefaultAccent"/>, then the theme dictionary swapped. Afterwards the dictionary and the application's own
|
|
/// resources are put back as they were, so no other check inherits this one's theme. Elements made inside take the
|
|
/// theme's resources when they are created; elements made before it hear the change, as a shown window does.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The accent is not in the theme dictionaries (WPF UI 4.3.0 writes it into <c>Application.Resources</c>), and the
|
|
/// test application's only accent is <c>Accent.xaml</c>'s default, the dark theme's: before 2026-10-07 a check under
|
|
/// Light measured a link in the dark theme's light blue on the light window, 1.9:1, a colour the App never shows.
|
|
/// </remarks>
|
|
public static T UnderTheme<T>(ApplicationTheme theme, Func<T> work)
|
|
{
|
|
ResourceDictionary resources = System.Windows.Application.Current.Resources;
|
|
System.Collections.ObjectModel.Collection<ResourceDictionary> merged = resources.MergedDictionaries;
|
|
int index = merged.ToList().FindIndex(static d => d is ThemesDictionary);
|
|
ResourceDictionary original = merged[index];
|
|
Dictionary<object, object> own = resources.Keys.Cast<object>().ToDictionary(static k => k, k => resources[k]);
|
|
ApplicationAccentColorManager.Apply(DefaultAccent, theme);
|
|
merged[index] = new ThemesDictionary { Theme = theme };
|
|
try
|
|
{
|
|
return work();
|
|
}
|
|
finally
|
|
{
|
|
merged[index] = original;
|
|
foreach (object added in resources.Keys.Cast<object>().Where(k => !own.ContainsKey(k)).ToList())
|
|
{
|
|
resources.Remove(added);
|
|
}
|
|
|
|
foreach ((object key, object value) in own.Where(kv => !ReferenceEquals(resources[kv.Key], kv.Value)))
|
|
{
|
|
resources[key] = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Runs <paramref name="work"/> under a Windows contrast theme the way the App follows one (beta.35, D91): the light or
|
|
/// the dark Fluent theme as the contrast theme is, under <c>ContrastOverlay</c> with its colours, and <c>ContrastTheme.Active</c>
|
|
/// set — then everything put back as <see cref="UnderTheme{T}"/> puts it back.
|
|
/// </summary>
|
|
public static T UnderContrast<T>(Services.ContrastPalette palette, Func<T> work)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(palette);
|
|
return UnderTheme(palette.IsDark ? ApplicationTheme.Dark : ApplicationTheme.Light, () =>
|
|
{
|
|
ResourceDictionary resources = System.Windows.Application.Current.Resources;
|
|
Services.ContrastOverlay.Install(resources, palette);
|
|
try
|
|
{
|
|
return work();
|
|
}
|
|
finally
|
|
{
|
|
Services.ContrastOverlay.Remove(resources);
|
|
}
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// The colour painted under <paramref name="element"/>: every Border's and Panel's background from <paramref name="root"/>
|
|
/// down to the element, composited over <paramref name="window"/> — what a template's parts draw, which is what the eye sees.
|
|
/// </summary>
|
|
public static Color PaintedUnder(DependencyObject element, DependencyObject root, Color window)
|
|
{
|
|
var chain = new List<Brush?>();
|
|
for (DependencyObject? at = element; at is not null; at = VisualTreeHelper.GetParent(at))
|
|
{
|
|
chain.Add(at switch
|
|
{
|
|
Border b => b.Background,
|
|
Panel p => p.Background,
|
|
_ => null,
|
|
});
|
|
if (ReferenceEquals(at, root))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
Color painted = window;
|
|
for (int i = chain.Count - 1; i >= 0; i--)
|
|
{
|
|
if (chain[i] is SolidColorBrush { Color.A: > 0 } solid)
|
|
{
|
|
painted = Wcag.Over(Color.FromArgb((byte)Math.Round(solid.Color.A * solid.Opacity), solid.Color.R, solid.Color.G, solid.Color.B), painted);
|
|
}
|
|
}
|
|
|
|
return painted;
|
|
}
|
|
|
|
/// <summary>A TextBlock's text colour as drawn over <paramref name="under"/>.</summary>
|
|
public static Color TextOver(TextBlock text, Color under) =>
|
|
text.Foreground is SolidColorBrush brush ? Wcag.Over(brush.Color, under) : throw new InvalidOperationException("a text whose foreground is not a solid colour");
|
|
}
|