diff --git a/src/Greenshot.Editor/Drawing/Surface.cs b/src/Greenshot.Editor/Drawing/Surface.cs
index b30e8d700..e8561ab4b 100644
--- a/src/Greenshot.Editor/Drawing/Surface.cs
+++ b/src/Greenshot.Editor/Drawing/Surface.cs
@@ -2075,8 +2075,28 @@ namespace Greenshot.Editor.Drawing
}
///
- /// This method is called to confirm/cancel "confirmable" elements, like the crop-container.
+ /// This method is called to confirm/cancel.
/// Called when pressing enter or using the "check" in the editor.
+ /// redirects to the specialized confirm/cancel method
+ ///
+ /// bool
+ public void Confirm(bool confirm)
+ {
+ if (DrawingMode == DrawingModes.Crop)
+ {
+ ConfirmCrop(confirm);
+ }
+ else
+ {
+ ConfirmSelectedConfirmableElements(confirm);
+ }
+ }
+
+ ///
+ /// This method is called to confirm/cancel "confirmable" elements
+ /// Called when pressing enter or using the "check" in the editor.
+ ///
+ /// For crop-container there is a dedicated method .
///
/// bool
public void ConfirmSelectedConfirmableElements(bool confirm)
@@ -2084,44 +2104,47 @@ namespace Greenshot.Editor.Drawing
// create new collection so that we can iterate safely (selectedElements might change due with confirm/cancel)
List selectedDCs = new List(selectedElements);
foreach (IDrawableContainer dc in selectedDCs)
+ {
+ throw new NotImplementedException($"No confirm/cancel defined for Container type {dc.GetType()}");
+ }
+
+ // maybe the undo button has to be enabled
+ if (_movingElementChanged != null)
+ {
+ _movingElementChanged(this, new SurfaceElementEventArgs());
+ }
+ }
+
+ ///
+ /// This method is called to confirm/cancel the crop-container.
+ /// Called when pressing enter or using the "check" in the editor.
+ ///
+ /// bool
+ public void ConfirmCrop(bool confirm)
+ {
+ if (_cropContainer is not CropContainer e) return;
+
+ if (confirm && selectedElements.Count > 0)
{
- if (!dc.Equals(_cropContainer)) continue;
- DrawingMode = DrawingModes.None;
// No undo memento for the cropcontainer itself, only for the effect
RemoveElement(_cropContainer, false);
- if (confirm)
+
+ _ = e.GetFieldValue(FieldType.CROPMODE) switch
{
- if (dc is CropContainer e)
- {
- switch (e.GetFieldValue(FieldType.CROPMODE))
- {
- case CropContainer.CropModes.Horizontal:
- {
- ApplyHorizontalCrop(_cropContainer.Bounds);
- break;
- }
- case CropContainer.CropModes.Vertical:
- {
- ApplyVerticalCrop(_cropContainer.Bounds);
- break;
- }
- default:
- {
- ApplyCrop(_cropContainer.Bounds);
- break;
- }
- }
- }
- else
- {
- ApplyCrop(_cropContainer.Bounds);
- }
- }
+ CropContainer.CropModes.Horizontal => ApplyHorizontalCrop(_cropContainer.Bounds),
+ CropContainer.CropModes.Vertical => ApplyVerticalCrop(_cropContainer.Bounds),
+ _ => ApplyCrop(_cropContainer.Bounds)
+ };
_cropContainer.Dispose();
_cropContainer = null;
- break;
}
+ else
+ {
+ RemoveCropContainer();
+ }
+
+ DrawingMode = DrawingModes.None;
// maybe the undo button has to be enabled
if (_movingElementChanged != null)
@@ -2457,7 +2480,7 @@ namespace Greenshot.Editor.Drawing
/// false if no keys were processed
public bool ProcessCmdKey(Keys k)
{
- if (selectedElements.Count <= 0) return false;
+ if (selectedElements.Count <= 0 && k != Keys.Escape) return false;
bool shiftModifier = (ModifierKeys & Keys.Shift) == Keys.Shift;
int px = shiftModifier ? 10 : 1;
@@ -2493,10 +2516,10 @@ namespace Greenshot.Editor.Drawing
PushElementsToBottom();
break;
case Keys.Enter:
- ConfirmSelectedConfirmableElements(true);
+ Confirm(true);
break;
case Keys.Escape:
- ConfirmSelectedConfirmableElements(false);
+ Confirm(false);
break;
case Keys.D0 | Keys.Control:
case Keys.D0 | Keys.Shift | Keys.Control:
diff --git a/src/Greenshot.Editor/Forms/ImageEditorForm.cs b/src/Greenshot.Editor/Forms/ImageEditorForm.cs
index 4e45e7ec7..f12e3a2be 100644
--- a/src/Greenshot.Editor/Forms/ImageEditorForm.cs
+++ b/src/Greenshot.Editor/Forms/ImageEditorForm.cs
@@ -1627,13 +1627,13 @@ namespace Greenshot.Editor.Forms
private void BtnConfirmClick(object sender, EventArgs e)
{
- _surface.ConfirmSelectedConfirmableElements(true);
+ _surface.Confirm(true);
RefreshEditorControls();
}
private void BtnCancelClick(object sender, EventArgs e)
{
- _surface.ConfirmSelectedConfirmableElements(false);
+ _surface.Confirm(false);
RefreshEditorControls();
}