Files
OpenNest/OpenNest.WinForms.Tests/Forms/LeadInSidePanelTests.cs
T
aj 2b8a3ce7db fix(leadin): add close button to Place Lead-in side panel
The docked side panel could only be closed with Escape, which was
unreliable: MainForm consumes Escape before ActionLeadIn's KeyDown
handler, so with a part selected ActionManager called the action's
empty CancelAction and nothing happened; with nothing selected the
panel closed but was stored as the previous action, so the next
Escape reopened it.

- EditNestForm side panel gets a header with the panel title and an
  always-visible close button that ends the action.
- ActionLeadIn.CancelAction now steps back (unlock contour, then
  deselect part), replacing the dead KeyDown handler.
- Actions can opt out of Escape-resume (ResumeOnEscape); the lead-in
  action does, so a closed panel stays closed.
2026-09-29 08:38:48 -04:00

65 lines
1.8 KiB
C#

using System.Runtime.ExceptionServices;
using System.Windows.Forms;
using OpenNest.Forms;
namespace OpenNest.WinForms.Tests.Forms;
public class LeadInSidePanelTests
{
[Theory]
[InlineData(true)]
[InlineData(false)]
public void PanelClosesWithoutEscapeReopeningIt(bool useCloseButton) => RunSta(() =>
{
using var form = new EditNestForm(new Nest("lead-in panel"));
form.Show();
form.PlaceLeadIn_Click(null!, EventArgs.Empty);
Assert.True(form.IsSidePanelVisible);
Assert.Equal("Place Lead-in", form.PlateView.Status);
if (useCloseButton)
{
var close = Assert.IsType<Button>(
Assert.Single(form.Controls.Find("sidePanelCloseButton", true))
);
close.PerformClick();
}
else
{
form.PlateView.ProcessEscapeKey();
}
Assert.False(form.IsSidePanelVisible);
Assert.Equal("Select", form.PlateView.Status);
// Escape from Select normally resumes the previous action; it must not
// bring back a panel the user just closed.
form.PlateView.ProcessEscapeKey();
Assert.False(form.IsSidePanelVisible);
Assert.Equal("Select", form.PlateView.Status);
});
private static void RunSta(System.Action action)
{
Exception? failure = null;
var thread = new Thread(() =>
{
try
{
action();
}
catch (Exception ex)
{
failure = ex;
}
})
{ IsBackground = true };
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
Assert.True(thread.Join(TimeSpan.FromSeconds(60)), "The STA test did not complete.");
if (failure != null)
ExceptionDispatchInfo.Capture(failure).Throw();
}
}