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>
- /// This HistoryMemento can be used to save an entire Document for undo purposes
- /// Create this HistoryMemento, then use SetDocument(), then push this on to the
- /// History using PushNewAction.
- /// </summary>
- public class ReplaceDocumentHistoryMemento
- : HistoryMemento
- {
- private IDocumentWorkspace historyWorkspace;
- [Serializable]
- private sealed class ReplaceDocumentHistoryMementoData
- : HistoryMementoData
- {
- private Document oldDocument;
- public Document OldDocument
- {
- get
- {
- return oldDocument;
- }
- }
- public ReplaceDocumentHistoryMementoData(Document oldDocument)
- {
- this.oldDocument = oldDocument;
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (oldDocument != null)
- {
- oldDocument.Dispose();
- oldDocument = null;
- }
- }
- }
- }
- public ReplaceDocumentHistoryMemento(string name, ImageResource image, IDocumentWorkspace historyWorkspace)
- : base(name, image)
- {
- this.historyWorkspace = historyWorkspace;
- ReplaceDocumentHistoryMementoData data = new ReplaceDocumentHistoryMementoData(this.historyWorkspace.GetDocument());
- this.Data = data;
- }
- protected override HistoryMemento OnUndo()
- {
- ReplaceDocumentHistoryMemento ha = new ReplaceDocumentHistoryMemento(Name, Image, this.historyWorkspace);
- this.historyWorkspace.SetDocument(((ReplaceDocumentHistoryMementoData)Data).OldDocument);
- return ha;
- }
- }
- }
|