AddNewBlankLayerFunction.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. using PaintDotNet.Measurement.HistoryMementos;
  2. namespace PaintDotNet.Measurement.HistoryFunctions
  3. {
  4. public sealed class AddNewBlankLayerFunction : HistoryFunction
  5. {
  6. public override HistoryMemento OnExecute(IDocumentWorkspace historyWorkspace)
  7. {
  8. BitmapLayer newLayer = null;
  9. newLayer = new BitmapLayer(historyWorkspace.GetDocument().Width, historyWorkspace.GetDocument().Height);
  10. string newLayerNameFormat = PdnResources.GetString("AddNewBlankLayer.LayerName.Format");
  11. newLayer.Name = string.Format(newLayerNameFormat, (1 + historyWorkspace.GetDocument().Layers.Count).ToString());
  12. newLayer.Opacity = 0;
  13. int newLayerIndex = historyWorkspace.GetActiveLayerIndex() + 1;
  14. NewLayerHistoryMemento ha = new NewLayerHistoryMemento(
  15. PdnResources.GetString("AddNewBlankLayer.HistoryMementoName"),
  16. PdnResources.GetImageResource("Icons.MenuLayersAddNewLayerIcon.png"),
  17. historyWorkspace,
  18. newLayerIndex);
  19. EnterCriticalRegion();
  20. historyWorkspace.GetDocument().Layers.Insert(newLayerIndex, newLayer);
  21. return ha;
  22. }
  23. public AddNewBlankLayerFunction()
  24. : base(PaintDotNet.Measurement.Enum.ActionFlags.None)
  25. {
  26. }
  27. }
  28. }