From b030de77a839d6125466bbfe451bd52ed3c99408 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Sat, 7 Mar 2026 10:51:28 -0500 Subject: [PATCH] feat: restore previous action on Escape from ActionSelect Pressing Escape from ActionSelect now restores the previous action (e.g. ActionClone) instead of staying in Select mode. Adds ConnectEvents() to the Action base class for action resume support. Co-Authored-By: Claude Opus 4.6 --- OpenNest/Actions/Action.cs | 2 ++ OpenNest/Controls/PlateView.cs | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/OpenNest/Actions/Action.cs b/OpenNest/Actions/Action.cs index 22c82fd..c602942 100644 --- a/OpenNest/Actions/Action.cs +++ b/OpenNest/Actions/Action.cs @@ -15,6 +15,8 @@ namespace OpenNest.Actions public virtual void OnPlateChanged() { } + public virtual void ConnectEvents() { } + public abstract void DisconnectEvents(); public abstract void CancelAction(); diff --git a/OpenNest/Controls/PlateView.cs b/OpenNest/Controls/PlateView.cs index b19d305..760686d 100644 --- a/OpenNest/Controls/PlateView.cs +++ b/OpenNest/Controls/PlateView.cs @@ -25,6 +25,7 @@ namespace OpenNest.Controls private string status; private Plate plate; private Action currentAction; + private Action previousAction; private List parts; private Point middleMouseDownPoint; @@ -283,6 +284,8 @@ namespace OpenNest.Controls case Keys.Escape: if (currentAction.IsBusy()) currentAction.CancelAction(); + else if (currentAction is ActionSelect && previousAction != null) + RestorePreviousAction(); else SetAction(typeof(ActionSelect)); break; @@ -650,6 +653,11 @@ namespace OpenNest.Controls if (currentAction != null) { + if (type == typeof(ActionSelect) && !(currentAction is ActionSelect)) + previousAction = currentAction; + else + previousAction = null; + currentAction.CancelAction(); currentAction.DisconnectEvents(); currentAction = null; @@ -664,6 +672,7 @@ namespace OpenNest.Controls { if (currentAction != null) { + previousAction = null; currentAction.CancelAction(); currentAction.DisconnectEvents(); currentAction = null; @@ -688,6 +697,20 @@ namespace OpenNest.Controls Status = GetDisplayName(type); } + private void RestorePreviousAction() + { + var action = previousAction; + previousAction = null; + + currentAction.CancelAction(); + currentAction.DisconnectEvents(); + + action.ConnectEvents(); + currentAction = action; + + Status = GetDisplayName(action.GetType()); + } + public void AlignSelected(AlignType alignType) { if (SelectedParts.Count == 0)