DeleteLayerFunction.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using PaintDotNet.Measurement.HistoryMementos;
  2. using System;
  3. namespace PaintDotNet.Measurement.HistoryFunctions
  4. {
  5. public sealed class DeleteLayerFunction
  6. : HistoryFunction
  7. {
  8. public static string StaticName
  9. {
  10. get
  11. {
  12. return PdnResources.GetString("DeleteLayer.HistoryMementoName");
  13. }
  14. }
  15. public static ImageResource StaticImage
  16. {
  17. get
  18. {
  19. return PdnResources.GetImageResource("Icons.MenuLayersDeleteLayerIcon.png");
  20. }
  21. }
  22. private int layerIndex;
  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 = " + this.layerIndex +
  28. ", expected [0, " + historyWorkspace.GetDocument().Layers.Count + ")");
  29. }
  30. HistoryMemento hm = new DeleteLayerHistoryMemento(StaticName, StaticImage, historyWorkspace, historyWorkspace.GetDocument().Layers.GetAt(this.layerIndex));
  31. EnterCriticalRegion();
  32. historyWorkspace.GetDocument().Layers.RemoveAt(this.layerIndex);
  33. return hm;
  34. }
  35. public DeleteLayerFunction(int layerIndex)
  36. : base(PaintDotNet.Measurement.Enum.ActionFlags.None)
  37. {
  38. this.layerIndex = layerIndex;
  39. }
  40. }
  41. }