mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-06 20:42:12 -04:00
Nest Info edits only the material name, but SaveNestInfo replaced the nest's material with new Material(name), so pressing OK without touching the material silently dropped its grade and density. SaveNestInfo now goes through NestMaterialSelection.Apply in OpenNest.Data: a name with the same SharedListNames.Key as the current material (trimmed, whitespace collapsed, invariant upper case) keeps its grade and density and takes the typed name; any other name gets a name-only material, as before. It always returns a new Material. SharedListNames.Key is the name normalizer the shared customer/material lists will use. Behavioral reds (each restored byte-identically): restoring the old name-only path fails both keep-grade tests; exact-string matching, dropping the upper-casing or the whitespace collapse fails the normalized-name test; returning the current instance fails the copy test. EditNestInfoFormTests cover Load -> Save through the real form; they are cross-compiled here and execute in the windows-desktop CI job.
26 lines
972 B
C#
26 lines
972 B
C#
namespace OpenNest.Data;
|
|
|
|
/// <summary>
|
|
/// Chooses the nest material when the Nest Info dialog is accepted. The dialog
|
|
/// edits only the material name, so grade and density must come from the
|
|
/// material the nest already has.
|
|
/// </summary>
|
|
public static class NestMaterialSelection
|
|
{
|
|
/// <summary>
|
|
/// Returns a new material named <paramref name="selectedName"/>. When that
|
|
/// name matches the current material's name by <see cref="SharedListNames.Key"/>,
|
|
/// the current grade and density are kept; any other name gets a name-only
|
|
/// material. The current material is never modified or returned.
|
|
/// </summary>
|
|
public static Material Apply(Material? current, string? selectedName)
|
|
{
|
|
var name = selectedName ?? "";
|
|
|
|
if (current != null && SharedListNames.Key(current.Name) == SharedListNames.Key(name))
|
|
return new Material(name, current.Grade, current.Density);
|
|
|
|
return new Material(name);
|
|
}
|
|
}
|