mirror of
https://github.com/greenshot/greenshot
synced 2025-08-22 06:23:24 -07:00
The confirm method has been split into specialized methods
This commit is contained in:
parent
eed210d05c
commit
5b2b66c789
2 changed files with 59 additions and 36 deletions
|
@ -2075,8 +2075,28 @@ namespace Greenshot.Editor.Drawing
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
/// <param name="confirm">bool</param>
|
||||
public void Confirm(bool confirm)
|
||||
{
|
||||
if (DrawingMode == DrawingModes.Crop)
|
||||
{
|
||||
ConfirmCrop(confirm);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConfirmSelectedConfirmableElements(confirm);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called to confirm/cancel "confirmable" elements
|
||||
/// Called when pressing enter or using the "check" in the editor.
|
||||
/// <br/>
|
||||
/// For crop-container there is a dedicated method <see cref="ConfirmCrop(bool)"/>.
|
||||
/// </summary>
|
||||
/// <param name="confirm">bool</param>
|
||||
public void ConfirmSelectedConfirmableElements(bool confirm)
|
||||
|
@ -2085,43 +2105,46 @@ namespace Greenshot.Editor.Drawing
|
|||
List<IDrawableContainer> selectedDCs = new List<IDrawableContainer>(selectedElements);
|
||||
foreach (IDrawableContainer dc in selectedDCs)
|
||||
{
|
||||
if (!dc.Equals(_cropContainer)) continue;
|
||||
DrawingMode = DrawingModes.None;
|
||||
// No undo memento for the cropcontainer itself, only for the effect
|
||||
RemoveElement(_cropContainer, false);
|
||||
if (confirm)
|
||||
{
|
||||
if (dc is CropContainer e)
|
||||
{
|
||||
switch (e.GetFieldValue(FieldType.CROPMODE))
|
||||
{
|
||||
case CropContainer.CropModes.Horizontal:
|
||||
{
|
||||
ApplyHorizontalCrop(_cropContainer.Bounds);
|
||||
break;
|
||||
throw new NotImplementedException($"No confirm/cancel defined for Container type {dc.GetType()}");
|
||||
}
|
||||
case CropContainer.CropModes.Vertical:
|
||||
|
||||
// maybe the undo button has to be enabled
|
||||
if (_movingElementChanged != null)
|
||||
{
|
||||
ApplyVerticalCrop(_cropContainer.Bounds);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
ApplyCrop(_cropContainer.Bounds);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplyCrop(_cropContainer.Bounds);
|
||||
_movingElementChanged(this, new SurfaceElementEventArgs());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is called to confirm/cancel the crop-container.
|
||||
/// Called when pressing enter or using the "check" in the editor.
|
||||
/// </summary>
|
||||
/// <param name="confirm">bool</param>
|
||||
public void ConfirmCrop(bool confirm)
|
||||
{
|
||||
if (_cropContainer is not CropContainer e) return;
|
||||
|
||||
if (confirm && selectedElements.Count > 0)
|
||||
{
|
||||
// No undo memento for the cropcontainer itself, only for the effect
|
||||
RemoveElement(_cropContainer, false);
|
||||
|
||||
_ = e.GetFieldValue(FieldType.CROPMODE) switch
|
||||
{
|
||||
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
|
|||
/// <returns>false if no keys were processed</returns>
|
||||
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:
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue