using System; namespace CraftSynth.ImageEditor { /// /// Add new object command /// internal class CommandAdd : Command, IDisposable { private DrawObject drawObject; // Create this command with DrawObject instance added to the list public CommandAdd(DrawObject drawObject) : base() { // Keep copy of added object this.drawObject = drawObject.Clone(); } /// /// Undo last Add command /// /// Layers collection public override void Undo(Layers list) { list[list.ActiveLayerIndex].Graphics.DeleteLastAddedObject(); } /// /// Redo last Add command /// /// Layers collection public override void Redo(Layers list) { list[list.ActiveLayerIndex].Graphics.UnselectAll(); list[list.ActiveLayerIndex].Graphics.Add(drawObject); if (drawObject is DrawImage && (drawObject as DrawImage).IsInitialImage) { drawObject.Selected = true; list[list.ActiveLayerIndex].Graphics.MoveSelectionToBack(); list[list.ActiveLayerIndex].Graphics.UnselectAll(); } } #region Destruction // Flag: Has Dispose already been called? bool _disposed = false; // Protected implementation of Dispose pattern. public override void Dispose(bool disposing) { if (!this._disposed) { if (disposing) { // Free any managed objects here. // if (this.drawObject != null) { this.drawObject.Dispose(); } } // Free any unmanaged objects here. // this._disposed = true; } } ~CommandAdd() { this.Dispose(false); } #endregion } }