using PaintDotNet.Measurement.HistoryMementos; using System; namespace PaintDotNet.Measurement.HistoryFunctions { public sealed class SwapLayerFunction : HistoryFunction { private int layer1Index; private int layer2Index; public static string StaticName { get { return PdnResources.GetString("SwapLayerFunction.Name"); } } public static ImageResource StaticImage { get { // TODO: find a real icon for this? //return PdnResources.GetImageResource("todo.png"); return PdnResources.GetImageResource("Icons.MenuLayersMoveLayerUpIcon.png"); } } public override HistoryMemento OnExecute(IDocumentWorkspace historyWorkspace) { if (layer1Index < 0 || layer1Index >= historyWorkspace.GetDocument().Layers.Count || layer2Index < 0 || layer2Index >= historyWorkspace.GetDocument().Layers.Count) { throw new ArgumentOutOfRangeException("layer1Index = " + this.layer1Index + ", layer2Index = " + layer2Index + ", expected [0," + historyWorkspace.GetDocument().Layers.Count + ")"); } SwapLayerHistoryMemento slhm = new SwapLayerHistoryMemento( StaticName, StaticImage, historyWorkspace, layer1Index, layer2Index); Layer layer1 = historyWorkspace.GetDocument().Layers.GetAt(layer1Index); Layer layer2 = historyWorkspace.GetDocument().Layers.GetAt(layer2Index); EnterCriticalRegion(); historyWorkspace.GetDocument().Layers[layer1Index] = layer2; historyWorkspace.GetDocument().Layers[layer2Index] = layer1; layer1.Invalidate(); layer2.Invalidate(); return slhm; } public SwapLayerFunction(int layer1Index, int layer2Index) : base(PaintDotNet.Measurement.Enum.ActionFlags.None) { this.layer1Index = layer1Index; this.layer2Index = layer2Index; } } }