MetaDataHistoryMemento.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /////////////////////////////////////////////////////////////////////////////////
  2. // Paint.NET //
  3. // Copyright (C) dotPDN LLC, Rick Brewster, Tom Jackson, and contributors. //
  4. // Portions Copyright (C) Microsoft Corporation. All Rights Reserved. //
  5. // See src/Resources/Files/License.txt for full licensing and attribution //
  6. // details. //
  7. // . //
  8. /////////////////////////////////////////////////////////////////////////////////
  9. using System;
  10. namespace PaintDotNet.Measurement.HistoryMementos
  11. {
  12. /// <summary>
  13. /// Saves the state of the Document's metadata.
  14. /// </summary>
  15. public class MetaDataHistoryMemento
  16. : HistoryMemento
  17. {
  18. private IDocumentWorkspace historyWorkspace;
  19. [Serializable]
  20. private class MetaDataHistoryMementoData
  21. : HistoryMementoData
  22. {
  23. private Document document;
  24. public Document Document
  25. {
  26. get
  27. {
  28. return this.document;
  29. }
  30. }
  31. public MetaDataHistoryMementoData(Document document)
  32. {
  33. this.document = document;
  34. }
  35. protected override void Dispose(bool disposing)
  36. {
  37. if (disposing)
  38. {
  39. if (this.document != null)
  40. {
  41. this.document.Dispose();
  42. this.document = null;
  43. }
  44. }
  45. base.Dispose(disposing);
  46. }
  47. }
  48. public MetaDataHistoryMemento(string name, ImageResource image, IDocumentWorkspace historyWorkspace)
  49. : base(name, image)
  50. {
  51. this.historyWorkspace = historyWorkspace;
  52. Document document = new Document(1, 1); // we need some place to store the metadata...
  53. document.ReplaceMetaDataFrom(historyWorkspace.GetDocument());
  54. MetaDataHistoryMementoData data = new MetaDataHistoryMementoData(document);
  55. this.Data = data;
  56. }
  57. protected override HistoryMemento OnUndo()
  58. {
  59. MetaDataHistoryMemento redo = new MetaDataHistoryMemento(this.Name, this.Image, this.historyWorkspace);
  60. MetaDataHistoryMementoData data = (MetaDataHistoryMementoData)this.Data;
  61. this.historyWorkspace.GetDocument().ReplaceMetaDataFrom(data.Document);
  62. return redo;
  63. }
  64. }
  65. }