1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using PaintDotNet.Measurement.HistoryMementos;
- using System;
- namespace PaintDotNet.Measurement.HistoryFunctions
- {
- public sealed class DuplicateLayerFunction
- : HistoryFunction
- {
- private int layerIndex;
- public static string StaticName
- {
- get
- {
- return PdnResources.GetString("DuplicateLayer.HistoryMementoName");
- }
- }
- public static ImageResource StaticImage
- {
- get
- {
- return PdnResources.GetImageResource("Icons.MenuLayersDuplicateLayerIcon.png");
- }
- }
- public override HistoryMemento OnExecute(IDocumentWorkspace historyWorkspace)
- {
- if (this.layerIndex < 0 || this.layerIndex >= historyWorkspace.GetDocument().Layers.Count)
- {
- throw new ArgumentOutOfRangeException("layerIndex = " + layerIndex + ", expected [0, " + historyWorkspace.GetDocument().Layers.Count + ")");
- }
- Layer newLayer = null;
- newLayer = (Layer)historyWorkspace.GetActiveLayer().Clone();
- newLayer.IsBackground = false;
- int newIndex = 1 + this.layerIndex;
- HistoryMemento ha = new NewLayerHistoryMemento(
- StaticName,
- StaticImage,
- historyWorkspace,
- newIndex);
- EnterCriticalRegion();
- historyWorkspace.GetDocument().Layers.Insert(newIndex, newLayer);
- newLayer.Invalidate();
- return ha;
- }
- public DuplicateLayerFunction(int layerIndex)
- : base(PaintDotNet.Measurement.Enum.ActionFlags.None)
- {
- this.layerIndex = layerIndex;
- }
- }
- }
|