ToolHistoryMemento.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. /// A Tool may implement this class in order to provide history actions that do
  14. /// not deactivate the tool while being undone or redone.
  15. /// </summary>
  16. public abstract class ToolHistoryMemento : HistoryMemento
  17. {
  18. private IDocumentWorkspace documentWorkspace;
  19. private Type toolType;
  20. protected IDocumentWorkspace DocumentWorkspace
  21. {
  22. get
  23. {
  24. return this.documentWorkspace;
  25. }
  26. }
  27. public Type ToolType
  28. {
  29. get
  30. {
  31. return this.toolType;
  32. }
  33. }
  34. protected abstract HistoryMemento OnToolUndo();
  35. protected sealed override HistoryMemento OnUndo()
  36. {
  37. if (this.documentWorkspace.GetToolType() != this.toolType)
  38. {
  39. this.documentWorkspace.SetToolFromType(this.toolType);
  40. }
  41. return OnToolUndo();
  42. }
  43. public ToolHistoryMemento(IDocumentWorkspace documentWorkspace, string name, ImageResource image)
  44. : base(name, image)
  45. {
  46. this.documentWorkspace = documentWorkspace;
  47. this.toolType = documentWorkspace.GetToolType();
  48. }
  49. }
  50. }