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:
@@ -15,6 +15,8 @@ namespace OpenNest.Actions
|
||||
|
||||
public virtual void OnPlateChanged() { }
|
||||
|
||||
public virtual void ConnectEvents() { }
|
||||
|
||||
public abstract void DisconnectEvents();
|
||||
|
||||
public abstract void CancelAction();
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user