DuplicateLayerFunction.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using PaintDotNet.Measurement.HistoryMementos;
  2. using System;
  3. namespace PaintDotNet.Measurement.HistoryFunctions
  4. {
  5. public sealed class DuplicateLayerFunction
  6. : HistoryFunction
  7. {
  8. private int layerIndex;
  9. public static string StaticName
  10. {
  11. get
  12. {
  13. return PdnResources.GetString("DuplicateLayer.HistoryMementoName");
  14. }
  15. }
  16. public static ImageResource StaticImage
  17. {
  18. get
  19. {
  20. return PdnResources.GetImageResource("Icons.MenuLayersDuplicateLayerIcon.png");
  21. }
  22. }
  23. public override HistoryMemento OnExecute(IDocumentWorkspace historyWorkspace)
  24. {
  25. if (this.layerIndex < 0 || this.layerIndex >= historyWorkspace.GetDocument().Layers.Count)
  26. {
  27. throw new ArgumentOutOfRangeException("layerIndex = " + layerIndex + ", expected [0, " + historyWorkspace.GetDocument().Layers.Count + ")");
  28. }
  29. Layer newLayer = null;
  30. newLayer = (Layer)historyWorkspace.GetActiveLayer().Clone();
  31. newLayer.IsBackground = false;
  32. int newIndex = 1 + this.layerIndex;
  33. HistoryMemento ha = new NewLayerHistoryMemento(
  34. StaticName,
  35. StaticImage,
  36. historyWorkspace,
  37. newIndex);
  38. EnterCriticalRegion();
  39. historyWorkspace.GetDocument().Layers.Insert(newIndex, newLayer);
  40. newLayer.Invalidate();
  41. return ha;
  42. }
  43. public DuplicateLayerFunction(int layerIndex)
  44. : base(PaintDotNet.Measurement.Enum.ActionFlags.None)
  45. {
  46. this.layerIndex = layerIndex;
  47. }
  48. }
  49. }