mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-01 13:21:34 -05:00
MainStatusText words the main window's location, machine, material, utilization and version labels as WinForms does, with the labels' tooltips and the StatusBarLocationFollowsMouse setting both apps keep. MachineMenu lists the machines for Nest > Machine and the machine label (by name, the nest's checked, one no longer on file checked and disabled), and MachineSettingsSource.ApplyMachine assigns one with its support grid, cut-off defaults and spacing. PlateWorkGuard holds the "Finish or cancel the current nesting or plate action first." check. The WinForms main window delegates to them unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
2.2 KiB
C#
52 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using OpenNest.Data;
|
|
|
|
namespace OpenNest.Forms
|
|
{
|
|
/// <summary>
|
|
/// One entry of the machine list: <see cref="Machine"/> is the machine to assign when it is
|
|
/// chosen, or null for an entry that only informs.
|
|
/// </summary>
|
|
public sealed record MachineMenuItem(string Text, MachineConfig Machine, bool Checked, bool Enabled);
|
|
|
|
/// <summary>
|
|
/// The machines listed by Nest > Machine and the status bar's machine label: those on
|
|
/// file by name, the active nest's checked; one assigned but no longer on file is shown
|
|
/// checked and disabled so the nest still says what it was made for.
|
|
/// </summary>
|
|
public static class MachineMenu
|
|
{
|
|
public const string NoNestText = "(no nest open)";
|
|
public const string NoMachinesText = "(no machines; see Tools > Machine Configuration)";
|
|
|
|
/// <summary>The entries for <paramref name="nest"/> (null when no nest is open).</summary>
|
|
public static IReadOnlyList<MachineMenuItem> Items(Nest nest, IEnumerable<MachineConfig> machines)
|
|
{
|
|
if (nest == null)
|
|
return new[] { new MachineMenuItem(NoNestText, null, false, false) };
|
|
|
|
var sorted = (machines ?? Enumerable.Empty<MachineConfig>())
|
|
.OrderBy(m => m.Name, StringComparer.CurrentCultureIgnoreCase)
|
|
.ToList();
|
|
var items = sorted
|
|
.Select(m => new MachineMenuItem(m.Name, m, m.Id == nest.Machine?.Id, true))
|
|
.ToList();
|
|
if (nest.Machine is { } assigned && sorted.All(m => m.Id != assigned.Id))
|
|
items.Add(new MachineMenuItem($"{assigned.Name} (not on file)", null, true, false));
|
|
if (items.Count == 0)
|
|
items.Add(new MachineMenuItem(NoMachinesText, null, false, false));
|
|
return items;
|
|
}
|
|
|
|
/// <summary>Whether <paramref name="machine"/> is already the nest's, so choosing it changes nothing.</summary>
|
|
public static bool IsAssigned(Nest nest, MachineConfig machine)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(nest);
|
|
ArgumentNullException.ThrowIfNull(machine);
|
|
return nest.Machine?.Id == machine.Id;
|
|
}
|
|
}
|
|
}
|