| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 | /////////////////////////////////////////////////////////////////////////////////// Paint.NET                                                                   //// Copyright (C) dotPDN LLC, Rick Brewster, Tom Jackson, and contributors.     //// Portions Copyright (C) Microsoft Corporation. All Rights Reserved.          //// See src/Resources/Files/License.txt for full licensing and attribution      //// details.                                                                    //// .                                                                           ///////////////////////////////////////////////////////////////////////////////////using System;namespace PaintDotNet.Measurement.HistoryMementos{    /// <summary>    /// Provides the ability to undo deleting a layer.    /// </summary>    public class DeleteLayerHistoryMemento        : HistoryMemento    {        private int index;        private IDocumentWorkspace historyWorkspace;        [Serializable]        private sealed class DeleteLayerHistoryMementoData            : HistoryMementoData        {            private Layer layer;            public Layer Layer            {                get                {                    return layer;                }            }            public DeleteLayerHistoryMementoData(Layer layer)            {                this.layer = layer;            }            protected override void Dispose(bool disposing)            {                if (disposing)                {                    if (layer != null)                    {                        layer.Dispose();                        layer = null;                    }                }            }        }        protected override HistoryMemento OnUndo()        {            DeleteLayerHistoryMementoData data = (DeleteLayerHistoryMementoData)this.Data;            HistoryMemento ha = new NewLayerHistoryMemento(Name, Image, this.historyWorkspace, this.index);            this.historyWorkspace.GetDocument().Layers.Insert(index, data.Layer);            ((Layer)this.historyWorkspace.GetDocument().Layers[index]).Invalidate();            return ha;        }        public DeleteLayerHistoryMemento(string name, ImageResource image, IDocumentWorkspace historyWorkspace, Layer deleteMe)            : base(name, image)        {            this.historyWorkspace = historyWorkspace;            this.index = historyWorkspace.GetDocument().Layers.IndexOf(deleteMe);            this.Data = new DeleteLayerHistoryMementoData(deleteMe);        }    }}
 |