/* * Greenshot - a free and open source screenshot tool * Copyright (C) 2007-2013 Thomas Braun, Jens Klingen, Robin Krom * * For more information see: http://getgreenshot.org/ * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ using Greenshot.Configuration; using Greenshot.Plugin.Drawing; using GreenshotPlugin.Core; using System; using System.Collections.Generic; using System.Drawing; namespace Greenshot.Memento { /// /// The DrawableContainerBoundsChangeMemento makes it possible to undo-redo an IDrawableContainer resize & move /// public class DrawableContainerBoundsChangeMemento : IMemento { private List points = new List(); private List sizes = new List(); private List listOfdrawableContainer; private void StoreBounds() { foreach (IDrawableContainer drawableContainer in listOfdrawableContainer) { points.Add(drawableContainer.Location); sizes.Add(drawableContainer.Size); } } public DrawableContainerBoundsChangeMemento(List listOfdrawableContainer) { this.listOfdrawableContainer = listOfdrawableContainer; StoreBounds(); } public DrawableContainerBoundsChangeMemento(IDrawableContainer drawableContainer) { listOfdrawableContainer = new List(); listOfdrawableContainer.Add(drawableContainer); StoreBounds(); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { // if (disposing) { } listOfdrawableContainer = null; } public LangKey ActionLanguageKey { get { return LangKey.none; } } public bool Merge(IMemento otherMemento) { DrawableContainerBoundsChangeMemento other = otherMemento as DrawableContainerBoundsChangeMemento; if (other != null) { if (Objects.CompareLists(listOfdrawableContainer, other.listOfdrawableContainer)) { // Lists are equal, as we have the state already we can ignore the new memento return true; } } return false; } public IMemento Restore() { DrawableContainerBoundsChangeMemento oldState = new DrawableContainerBoundsChangeMemento(listOfdrawableContainer); for (int index = 0; index < listOfdrawableContainer.Count; index++) { IDrawableContainer drawableContainer = listOfdrawableContainer[index]; // Before drawableContainer.Invalidate(); drawableContainer.Left = points[index].X; drawableContainer.Top = points[index].Y; drawableContainer.Width = sizes[index].Width; drawableContainer.Height = sizes[index].Height; // After drawableContainer.Invalidate(); drawableContainer.Parent.Modified = true; } return oldState; } } }