Small code cleanup of the places I already touched in this PR.

This commit is contained in:
Robin Krom 2022-03-04 23:04:14 +01:00
commit 8bc6fbdcc4
No known key found for this signature in database
GPG key ID: BCC01364F1371490
10 changed files with 175 additions and 195 deletions

View file

@ -136,7 +136,7 @@ namespace Greenshot.Editor.Drawing
} }
/// <summary> /// <summary>
/// Make a following bounds change on this containerlist undoable! /// Make a following bounds change on this DrawableContainerList undoable!
/// </summary> /// </summary>
/// <param name="allowMerge">true means allow the moves to be merged</param> /// <param name="allowMerge">true means allow the moves to be merged</param>
public void MakeBoundsChangeUndoable(bool allowMerge) public void MakeBoundsChangeUndoable(bool allowMerge)
@ -301,8 +301,7 @@ namespace Greenshot.Editor.Drawing
{ {
return Rectangle.Empty; return Rectangle.Empty;
} }
else
{
var result = this[0].DrawingBounds; var result = this[0].DrawingBounds;
for (int i = 1; i < Count; i++) for (int i = 1; i < Count; i++)
{ {
@ -312,14 +311,13 @@ namespace Greenshot.Editor.Drawing
return result; return result;
} }
} }
}
/// <summary> /// <summary>
/// Triggers all elements in the list ot be redrawn. /// Triggers all elements in the list ot be redrawn.
/// </summary> /// </summary>
/// <param name="g">the to the bitmap related Graphics object</param> /// <param name="g">the to the bitmap related Graphics object</param>
/// <param name="bitmap">Bitmap to draw</param> /// <param name="bitmap">Bitmap to draw</param>
/// <param name="renderMode">the rendermode in which the element is to be drawn</param> /// <param name="renderMode">the RenderMode in which the element is to be drawn</param>
/// <param name="clipRectangle"></param> /// <param name="clipRectangle"></param>
public void Draw(Graphics g, Bitmap bitmap, RenderMode renderMode, Rectangle clipRectangle) public void Draw(Graphics g, Bitmap bitmap, RenderMode renderMode, Rectangle clipRectangle)
{ {
@ -584,9 +582,7 @@ namespace Greenshot.Editor.Drawing
return; return;
} }
var dc = this[index1]; (this[index1], this[index2]) = (this[index2], this[index1]);
this[index1] = this[index2];
this[index2] = dc;
Parent.Modified = true; Parent.Modified = true;
} }

View file

@ -711,7 +711,7 @@ namespace Greenshot.Editor.Drawing
BinaryFormatter binaryRead = new BinaryFormatter(); BinaryFormatter binaryRead = new BinaryFormatter();
IDrawableContainerList loadedElements = (IDrawableContainerList) binaryRead.Deserialize(streamRead); IDrawableContainerList loadedElements = (IDrawableContainerList) binaryRead.Deserialize(streamRead);
loadedElements.Parent = this; loadedElements.Parent = this;
// Make sure the steplabels are sorted accoring to their number // Make sure the steplabels are sorted according to their number
_stepLabels.Sort((p1, p2) => p1.Number.CompareTo(p2.Number)); _stepLabels.Sort((p1, p2) => p1.Number.CompareTo(p2.Number));
DeselectAllElements(); DeselectAllElements();
AddElements(loadedElements); AddElements(loadedElements);
@ -1119,8 +1119,8 @@ namespace Greenshot.Editor.Drawing
/// <param name="message">Message itself</param> /// <param name="message">Message itself</param>
public void SendMessageEvent(object source, SurfaceMessageTyp messageType, string message) public void SendMessageEvent(object source, SurfaceMessageTyp messageType, string message)
{ {
if (_surfaceMessage != null) if (_surfaceMessage == null) return;
{
var eventArgs = new SurfaceMessageEventArgs var eventArgs = new SurfaceMessageEventArgs
{ {
Message = message, Message = message,
@ -1129,81 +1129,76 @@ namespace Greenshot.Editor.Drawing
}; };
_surfaceMessage(source, eventArgs); _surfaceMessage(source, eventArgs);
} }
}
/// <summary> /// <summary>
/// Use to update UI when pressing a key to change the foreground color /// Use to update UI when pressing a key to change the foreground color
/// </summary> /// </summary>
/// <param name="source">Who send</param> /// <param name="source">Who send</param>
/// <param name="color">new color</param> /// <param name="color">new color</param>
public void UpdateForegroundColorEvent(object source, Color color) private void UpdateForegroundColorEvent(object source, Color color)
{
if (_foregroundColorChanged != null)
{ {
if (_foregroundColorChanged == null) return;
var eventArgs = new SurfaceForegroundColorEventArgs var eventArgs = new SurfaceForegroundColorEventArgs
{ {
Color = color, Color = color,
}; };
_foregroundColorChanged(source, eventArgs); _foregroundColorChanged(source, eventArgs);
} }
}
/// <summary> /// <summary>
/// Use to update UI when pressing a key to change the background color /// Use to update UI when pressing a key to change the background color
/// </summary> /// </summary>
/// <param name="source">Who send</param> /// <param name="source">Who send</param>
/// <param name="color">new color</param> /// <param name="color">new color</param>
public void UpdateBackgroundColorEvent(object source, Color color) private void UpdateBackgroundColorEvent(object source, Color color)
{
if (_lineThicknessChanged != null)
{ {
if (_lineThicknessChanged == null) return;
var eventArgs = new SurfaceBackgroundColorEventArgs var eventArgs = new SurfaceBackgroundColorEventArgs
{ {
Color = color, Color = color,
}; };
_backgroundColorChanged(source, eventArgs); _backgroundColorChanged(source, eventArgs);
} }
}
/// <summary> /// <summary>
/// Use to update UI when pressing a key to change the line thickness /// Use to update UI when pressing a key to change the line thickness
/// </summary> /// </summary>
/// <param name="source">Who send</param> /// <param name="source">Who send</param>
/// <param name="thickness">new thickness</param> /// <param name="thickness">new thickness</param>
public void UpdateLineThicknessEvent(object source, int thickness) private void UpdateLineThicknessEvent(object source, int thickness)
{
if (_lineThicknessChanged != null)
{ {
if (_lineThicknessChanged == null) return;
var eventArgs = new SurfaceLineThicknessEventArgs var eventArgs = new SurfaceLineThicknessEventArgs
{ {
Thickness = thickness, Thickness = thickness,
}; };
_lineThicknessChanged(source, eventArgs); _lineThicknessChanged(source, eventArgs);
} }
}
/// <summary> /// <summary>
/// Use to update UI when pressing the key to show/hide the shadow /// Use to update UI when pressing the key to show/hide the shadow
/// </summary> /// </summary>
/// <param name="source">Who send</param> /// <param name="source">Who send</param>
/// <param name="hasShadow">has shadow</param> /// <param name="hasShadow">has shadow</param>
public void UpdateShadowEvent(object source, bool hasShadow) private void UpdateShadowEvent(object source, bool hasShadow)
{
if (_shadowChanged != null)
{ {
if (_shadowChanged == null) return;
var eventArgs = new SurfaceShadowEventArgs var eventArgs = new SurfaceShadowEventArgs
{ {
HasShadow = hasShadow, HasShadow = hasShadow,
}; };
_shadowChanged(source, eventArgs); _shadowChanged(source, eventArgs);
} }
}
/// <summary> /// <summary>
/// Crop the surface /// Crop the surface
/// </summary> /// </summary>
/// <param name="cropRectangle">rectangle that remains</param> /// <param name="cropRectangle">rectangle that remains</param>
/// <returns></returns> /// <returns>bool</returns>
public bool ApplyCrop(Rectangle cropRectangle) public bool ApplyCrop(Rectangle cropRectangle)
{ {
if (!IsCropPossible(ref cropRectangle, CropContainer.CropModes.Default)) return false; if (!IsCropPossible(ref cropRectangle, CropContainer.CropModes.Default)) return false;
@ -1224,7 +1219,7 @@ namespace Greenshot.Editor.Drawing
throw; throw;
} }
Matrix matrix = new Matrix(); var matrix = new Matrix();
matrix.Translate(-cropRectangle.Left, -cropRectangle.Top, MatrixOrder.Append); matrix.Translate(-cropRectangle.Left, -cropRectangle.Top, MatrixOrder.Append);
// Make undoable // Make undoable
MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false); MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false);
@ -1246,8 +1241,8 @@ namespace Greenshot.Editor.Drawing
/// Splits the image in 3 parts(top, middle, bottom). Crop out the middle and joins top and bottom. /// Splits the image in 3 parts(top, middle, bottom). Crop out the middle and joins top and bottom.
/// </summary> /// </summary>
/// <param name="cropRectangle">rectangle of the middle part</param> /// <param name="cropRectangle">rectangle of the middle part</param>
/// <returns></returns> /// <returns>bool</returns>
public bool ApplyHorizontalCrop(Rectangle cropRectangle) private bool ApplyHorizontalCrop(Rectangle cropRectangle)
{ {
if (!IsCropPossible(ref cropRectangle, CropContainer.CropModes.Horizontal)) return false; if (!IsCropPossible(ref cropRectangle, CropContainer.CropModes.Horizontal)) return false;
@ -1255,12 +1250,12 @@ namespace Greenshot.Editor.Drawing
var topRectangle = new Rectangle(0, 0, Image.Size.Width, cropRectangle.Top); var topRectangle = new Rectangle(0, 0, Image.Size.Width, cropRectangle.Top);
var bottomRectangle = new Rectangle(0, cropRectangle.Top + cropRectangle.Height, Image.Size.Width, Image.Size.Height - cropRectangle.Top - cropRectangle.Height); var bottomRectangle = new Rectangle(0, cropRectangle.Top + cropRectangle.Height, Image.Size.Width, Image.Size.Height - cropRectangle.Top - cropRectangle.Height);
Bitmap tmpNewimage; Bitmap newImage;
List<Bitmap> imageParts = new List<Bitmap>(); var imageParts = new List<Bitmap>();
// Make sure we have information, this this fails // Make sure we have information, this this fails
try try
{ {
tmpNewimage = new Bitmap(Image.Size.Width, Image.Size.Height - cropRectangle.Height); newImage = new Bitmap(Image.Size.Width, Image.Size.Height - cropRectangle.Height);
if (topRectangle.Height > 0) if (topRectangle.Height > 0)
{ {
@ -1280,7 +1275,7 @@ namespace Greenshot.Editor.Drawing
ex.Data.Add("Pixelformat", Image.PixelFormat); ex.Data.Add("Pixelformat", Image.PixelFormat);
throw; throw;
} }
using Graphics g = Graphics.FromImage(tmpNewimage); using Graphics g = Graphics.FromImage(newImage);
var insertPositionTop = 0; var insertPositionTop = 0;
foreach (var image in imageParts) foreach (var image in imageParts)
@ -1290,16 +1285,16 @@ namespace Greenshot.Editor.Drawing
image.Dispose(); image.Dispose();
} }
Matrix matrix = new Matrix(); var matrix = new Matrix();
matrix.Translate(0, -(cropRectangle.Top + cropRectangle.Height), MatrixOrder.Append); matrix.Translate(0, -(cropRectangle.Top + cropRectangle.Height), MatrixOrder.Append);
// Make undoable // Make undoable
MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false); MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false);
// Do not dispose otherwise we can't undo the image! // Do not dispose otherwise we can't undo the image!
SetImage(tmpNewimage, false); SetImage(newImage, false);
_elements.Transform(matrix); _elements.Transform(matrix);
if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, tmpNewimage.Size))) if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size)))
{ {
_surfaceSizeChanged(this, null); _surfaceSizeChanged(this, null);
} }
@ -1313,20 +1308,20 @@ namespace Greenshot.Editor.Drawing
/// Splits the image in 3 parts(left, middle, right). Crop out the middle and joins top and bottom. /// Splits the image in 3 parts(left, middle, right). Crop out the middle and joins top and bottom.
/// </summary> /// </summary>
/// <param name="cropRectangle">rectangle of the middle part</param> /// <param name="cropRectangle">rectangle of the middle part</param>
/// <returns></returns> /// <returns>bool</returns>
public bool ApplyVerticalCrop(Rectangle cropRectangle) private bool ApplyVerticalCrop(Rectangle cropRectangle)
{ {
if (!IsCropPossible(ref cropRectangle, CropContainer.CropModes.Vertical)) return false; if (!IsCropPossible(ref cropRectangle, CropContainer.CropModes.Vertical)) return false;
var imageRectangle = new Rectangle(Point.Empty, Image.Size); var imageRectangle = new Rectangle(Point.Empty, Image.Size);
var leftRectangle = new Rectangle(0, 0, cropRectangle.Left, Image.Size.Height); var leftRectangle = new Rectangle(0, 0, cropRectangle.Left, Image.Size.Height);
var rightRectangle = new Rectangle(cropRectangle.Left + cropRectangle.Width, 0, Image.Size.Width - cropRectangle.Width - cropRectangle.Left, Image.Size.Height); var rightRectangle = new Rectangle(cropRectangle.Left + cropRectangle.Width, 0, Image.Size.Width - cropRectangle.Width - cropRectangle.Left, Image.Size.Height);
Bitmap tmpNewimage; Bitmap newImage;
List<Bitmap> imageParts = new List<Bitmap>(); var imageParts = new List<Bitmap>();
// Make sure we have information, this this fails // Make sure we have information, this this fails
try try
{ {
tmpNewimage = new Bitmap(Image.Size.Width - cropRectangle.Width, Image.Size.Height); newImage = new Bitmap(Image.Size.Width - cropRectangle.Width, Image.Size.Height);
if (leftRectangle.Width > 0) if (leftRectangle.Width > 0)
{ {
@ -1346,7 +1341,7 @@ namespace Greenshot.Editor.Drawing
ex.Data.Add("Pixelformat", Image.PixelFormat); ex.Data.Add("Pixelformat", Image.PixelFormat);
throw; throw;
} }
using Graphics g = Graphics.FromImage(tmpNewimage); using Graphics g = Graphics.FromImage(newImage);
var insertPositionLeft = 0; var insertPositionLeft = 0;
foreach (var image in imageParts) foreach (var image in imageParts)
@ -1356,17 +1351,16 @@ namespace Greenshot.Editor.Drawing
image.Dispose(); image.Dispose();
} }
var matrix = new Matrix();
Matrix matrix = new Matrix();
matrix.Translate(-cropRectangle.Left - cropRectangle.Width, 0, MatrixOrder.Append); matrix.Translate(-cropRectangle.Left - cropRectangle.Width, 0, MatrixOrder.Append);
// Make undoable // Make undoable
MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false); MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false);
// Do not dispose otherwise we can't undo the image! // Do not dispose otherwise we can't undo the image!
SetImage(tmpNewimage, false); SetImage(newImage, false);
_elements.Transform(matrix); _elements.Transform(matrix);
if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, tmpNewimage.Size))) if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size)))
{ {
_surfaceSizeChanged(this, null); _surfaceSizeChanged(this, null);
} }
@ -1404,8 +1398,8 @@ namespace Greenshot.Editor.Drawing
{ {
foreach (IAdorner adorner in drawableContainer.Adorners) foreach (IAdorner adorner in drawableContainer.Adorners)
{ {
if (adorner.IsActive || adorner.HitTest(mouseEventArgs.Location)) if (!adorner.IsActive && !adorner.HitTest(mouseEventArgs.Location)) continue;
{
if (adorner.Cursor != null) if (adorner.Cursor != null)
{ {
Cursor = adorner.Cursor; Cursor = adorner.Cursor;
@ -1414,7 +1408,6 @@ namespace Greenshot.Editor.Drawing
return adorner; return adorner;
} }
} }
}
return null; return null;
} }
@ -1643,8 +1636,8 @@ namespace Greenshot.Editor.Drawing
Cursor = DrawingMode != DrawingModes.None ? Cursors.Cross : Cursors.Default; Cursor = DrawingMode != DrawingModes.None ? Cursors.Cross : Cursors.Default;
if (_mouseDown) if (!_mouseDown) return;
{
if (_mouseDownElement != null) if (_mouseDownElement != null)
{ {
// an element is currently dragged // an element is currently dragged
@ -1686,7 +1679,6 @@ namespace Greenshot.Editor.Drawing
_modified = true; _modified = true;
} }
} }
}
/// <summary> /// <summary>
/// This event handler is called when the surface is double clicked. /// This event handler is called when the surface is double clicked.
@ -2018,7 +2010,7 @@ namespace Greenshot.Editor.Drawing
Invalidate(); Invalidate();
} }
if (makeUndoable && elementToRemove.IsUndoable) if (makeUndoable && elementToRemove is { IsUndoable: true })
{ {
MakeUndoable(new DeleteElementMemento(this, elementToRemove), false); MakeUndoable(new DeleteElementMemento(this, elementToRemove), false);
} }
@ -2085,37 +2077,32 @@ namespace Greenshot.Editor.Drawing
/// </summary> /// </summary>
public void CutSelectedElements() public void CutSelectedElements()
{ {
if (HasSelectedElements) if (!HasSelectedElements) return;
{
ClipboardHelper.SetClipboardData(typeof(IDrawableContainerList), selectedElements); ClipboardHelper.SetClipboardData(typeof(IDrawableContainerList), selectedElements);
RemoveSelectedElements(); RemoveSelectedElements();
} }
}
/// <summary> /// <summary>
/// Copy the selected elements to the clipboard /// Copy the selected elements to the clipboard
/// </summary> /// </summary>
public void CopySelectedElements() public void CopySelectedElements()
{ {
if (HasSelectedElements) if (!HasSelectedElements) return;
{
ClipboardHelper.SetClipboardData(typeof(IDrawableContainerList), selectedElements); ClipboardHelper.SetClipboardData(typeof(IDrawableContainerList), selectedElements);
} }
}
/// <summary> /// <summary>
/// This method is called to confirm/cancel "confirmable" elements, like the crop-container. /// This method is called to confirm/cancel "confirmable" elements, like the crop-container.
/// Called when pressing enter or using the "check" in the editor. /// Called when pressing enter or using the "check" in the editor.
/// </summary> /// </summary>
/// <param name="confirm"></param> /// <param name="confirm">bool</param>
public void ConfirmSelectedConfirmableElements(bool confirm) public void ConfirmSelectedConfirmableElements(bool confirm)
{ {
// create new collection so that we can iterate safely (selectedElements might change due with confirm/cancel) // create new collection so that we can iterate safely (selectedElements might change due with confirm/cancel)
List<IDrawableContainer> selectedDCs = new List<IDrawableContainer>(selectedElements); List<IDrawableContainer> selectedDCs = new List<IDrawableContainer>(selectedElements);
foreach (IDrawableContainer dc in selectedDCs) foreach (IDrawableContainer dc in selectedDCs)
{ {
if (dc.Equals(_cropContainer)) if (!dc.Equals(_cropContainer)) continue;
{
DrawingMode = DrawingModes.None; DrawingMode = DrawingModes.None;
// No undo memento for the cropcontainer itself, only for the effect // No undo memento for the cropcontainer itself, only for the effect
RemoveElement(_cropContainer, false); RemoveElement(_cropContainer, false);
@ -2153,7 +2140,6 @@ namespace Greenshot.Editor.Drawing
break; break;
} }
} }
}
public void RemoveCropContainer() public void RemoveCropContainer()
{ {
@ -2337,13 +2323,13 @@ namespace Greenshot.Editor.Drawing
/// <summary> /// <summary>
/// Get the rectangle bounding all selected elements (in surface coordinates space), /// Get the rectangle bounding all selected elements (in surface coordinates space),
/// or empty rectangle if nothing is selcted. /// or empty rectangle if nothing is selected.
/// </summary> /// </summary>
public Rectangle GetSelectionRectangle() public Rectangle GetSelectionRectangle()
=> ToSurfaceCoordinates(selectedElements.DrawingBounds); => ToSurfaceCoordinates(selectedElements.DrawingBounds);
/// <summary> /// <summary>
/// Duplicate all the selecteded elements /// Duplicate all the selected elements
/// </summary> /// </summary>
public void DuplicateSelectedElements() public void DuplicateSelectedElements()
{ {
@ -2680,7 +2666,7 @@ namespace Greenshot.Editor.Drawing
return _elements.CanPushDown(selectedElements); return _elements.CanPushDown(selectedElements);
} }
public void Element_FieldChanged(object sender, FieldChangedEventArgs e) private void Element_FieldChanged(object sender, FieldChangedEventArgs e)
{ {
selectedElements.HandleFieldChangedEvent(sender, e); selectedElements.HandleFieldChangedEvent(sender, e);
} }
@ -2738,8 +2724,7 @@ namespace Greenshot.Editor.Drawing
{ {
return rc; return rc;
} }
else
{
Point[] points = Point[] points =
{ {
rc.Location, rc.Location + rc.Size rc.Location, rc.Location + rc.Size
@ -2753,5 +2738,4 @@ namespace Greenshot.Editor.Drawing
); );
} }
} }
}
} }

View file

@ -44,7 +44,7 @@ namespace Greenshot.Editor.Memento
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
protected virtual void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
//if (disposing) { } //if (disposing) { }
_drawableContainer = null; _drawableContainer = null;

View file

@ -43,7 +43,7 @@ namespace Greenshot.Editor.Memento
Dispose(true); Dispose(true);
} }
protected virtual void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
{ {

View file

@ -44,7 +44,7 @@ namespace Greenshot.Editor.Memento
Dispose(true); Dispose(true);
} }
protected virtual void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
{ {

View file

@ -45,7 +45,7 @@ namespace Greenshot.Editor.Memento
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
protected virtual void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
if (!disposing) return; if (!disposing) return;

View file

@ -43,7 +43,7 @@ namespace Greenshot.Editor.Memento
Dispose(true); Dispose(true);
} }
protected virtual void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
{ {

View file

@ -34,30 +34,30 @@ namespace Greenshot.Editor.Memento
{ {
private readonly List<Point> _points = new(); private readonly List<Point> _points = new();
private readonly List<Size> _sizes = new(); private readonly List<Size> _sizes = new();
private IDrawableContainerList _listOfdrawableContainer; private IDrawableContainerList _listOfDrawableContainer;
private void StoreBounds() private void StoreBounds()
{ {
foreach (IDrawableContainer drawableContainer in _listOfdrawableContainer) foreach (IDrawableContainer drawableContainer in _listOfDrawableContainer)
{ {
_points.Add(drawableContainer.Location); _points.Add(drawableContainer.Location);
_sizes.Add(drawableContainer.Size); _sizes.Add(drawableContainer.Size);
} }
} }
public DrawableContainerBoundsChangeMemento(IDrawableContainerList listOfdrawableContainer) public DrawableContainerBoundsChangeMemento(IDrawableContainerList listOfDrawableContainer)
{ {
_listOfdrawableContainer = listOfdrawableContainer; _listOfDrawableContainer = listOfDrawableContainer;
StoreBounds(); StoreBounds();
} }
public DrawableContainerBoundsChangeMemento(IDrawableContainer drawableContainer) public DrawableContainerBoundsChangeMemento(IDrawableContainer drawableContainer)
{ {
_listOfdrawableContainer = new DrawableContainerList _listOfDrawableContainer = new DrawableContainerList
{ {
drawableContainer drawableContainer
}; };
_listOfdrawableContainer.Parent = drawableContainer.Parent; _listOfDrawableContainer.Parent = drawableContainer.Parent;
StoreBounds(); StoreBounds();
} }
@ -66,21 +66,21 @@ namespace Greenshot.Editor.Memento
Dispose(true); Dispose(true);
} }
protected virtual void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
{ {
_listOfdrawableContainer?.Dispose(); _listOfDrawableContainer?.Dispose();
} }
_listOfdrawableContainer = null; _listOfDrawableContainer = null;
} }
public bool Merge(IMemento otherMemento) public bool Merge(IMemento otherMemento)
{ {
if (otherMemento is not DrawableContainerBoundsChangeMemento other) return false; if (otherMemento is not DrawableContainerBoundsChangeMemento other) return false;
if (ObjectExtensions.CompareLists(_listOfdrawableContainer, other._listOfdrawableContainer)) if (ObjectExtensions.CompareLists(_listOfDrawableContainer, other._listOfDrawableContainer))
{ {
// Lists are equal, as we have the state already we can ignore the new memento // Lists are equal, as we have the state already we can ignore the new memento
return true; return true;
@ -91,10 +91,10 @@ namespace Greenshot.Editor.Memento
public IMemento Restore() public IMemento Restore()
{ {
var oldState = new DrawableContainerBoundsChangeMemento(_listOfdrawableContainer); var oldState = new DrawableContainerBoundsChangeMemento(_listOfDrawableContainer);
for (int index = 0; index < _listOfdrawableContainer.Count; index++) for (int index = 0; index < _listOfDrawableContainer.Count; index++)
{ {
IDrawableContainer drawableContainer = _listOfdrawableContainer[index]; IDrawableContainer drawableContainer = _listOfDrawableContainer[index];
// Before // Before
drawableContainer.Invalidate(); drawableContainer.Invalidate();
drawableContainer.Left = _points[index].X; drawableContainer.Left = _points[index].X;

View file

@ -52,7 +52,7 @@ namespace Greenshot.Editor.Memento
Dispose(true); Dispose(true);
} }
protected virtual void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
if (!disposing) return; if (!disposing) return;

View file

@ -43,7 +43,7 @@ namespace Greenshot.Editor.Memento
Dispose(true); Dispose(true);
} }
protected virtual void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
{ {