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 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 10:51:28 -05:00
parent 0573cb2f6d
commit b030de77a8
2 changed files with 25 additions and 0 deletions

View File

@@ -15,6 +15,8 @@ namespace OpenNest.Actions
public virtual void OnPlateChanged() { }
public virtual void ConnectEvents() { }
public abstract void DisconnectEvents();
public abstract void CancelAction();

View File

@@ -25,6 +25,7 @@ namespace OpenNest.Controls
private string status;
private Plate plate;
private Action currentAction;
private Action previousAction;
private List<LayoutPart> 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)