예제 #1
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (layer1Index < 0 || layer1Index >= historyWorkspace.Document.Layers.Count ||
                layer2Index < 0 || layer2Index >= historyWorkspace.Document.Layers.Count)
            {
                throw new ArgumentOutOfRangeException("layer1Index = " + this.layer1Index + ", layer2Index = " + layer2Index + ", expected [0," + historyWorkspace.Document.Layers.Count + ")");
            }

            SwapLayerHistoryMemento slhm = new SwapLayerHistoryMemento(
                StaticName,
                StaticImage,
                historyWorkspace,
                layer1Index,
                layer2Index);

            Layer layer1 = historyWorkspace.Document.Layers.GetAt(layer1Index);
            Layer layer2 = historyWorkspace.Document.Layers.GetAt(layer2Index);

            EnterCriticalRegion();
            historyWorkspace.Document.Layers[layer1Index] = layer2;
            historyWorkspace.Document.Layers[layer2Index] = layer1;

            layer1.Invalidate();
            layer2.Invalidate();

            return slhm;
        }
        protected override HistoryMemento OnUndo()
        {
            SwapLayerHistoryMemento slha = new SwapLayerHistoryMemento(this.Name, this.Image,
                                                                       this.historyWorkspace, this.layerIndex2, this.layerIndex1);

            Layer layer1 = (Layer)this.historyWorkspace.Document.Layers[this.layerIndex1];
            Layer layer2 = (Layer)this.historyWorkspace.Document.Layers[this.layerIndex2];

            int firstIndex  = Math.Min(layerIndex1, layerIndex2);
            int secondIndex = Math.Max(layerIndex1, layerIndex2);

            if (secondIndex - firstIndex == 1)
            {
                this.historyWorkspace.Document.Layers.RemoveAt(layerIndex1);
                this.historyWorkspace.Document.Layers.Insert(layerIndex2, layer1);
            }
            else
            {
                // general version
                this.historyWorkspace.Document.Layers[layerIndex1] = layer2;
                this.historyWorkspace.Document.Layers[layerIndex2] = layer1;
            }

            ((Layer)this.historyWorkspace.Document.Layers[this.layerIndex1]).Invalidate();
            ((Layer)this.historyWorkspace.Document.Layers[this.layerIndex2]).Invalidate();

            return(slha);
        }
        protected override HistoryMemento OnUndo()
        {
            SwapLayerHistoryMemento slha = new SwapLayerHistoryMemento(this.Name, this.Image,
                this.historyWorkspace, this.layerIndex2, this.layerIndex1);

            Layer layer1 = (Layer)this.historyWorkspace.Document.Layers[this.layerIndex1];
            Layer layer2 = (Layer)this.historyWorkspace.Document.Layers[this.layerIndex2];

            int firstIndex = Math.Min(layerIndex1, layerIndex2);
            int secondIndex = Math.Max(layerIndex1, layerIndex2);

            if (secondIndex - firstIndex == 1)
            {
                this.historyWorkspace.Document.Layers.RemoveAt(layerIndex1);
                this.historyWorkspace.Document.Layers.Insert(layerIndex2, layer1);
            }
            else
            {
                // general version
                this.historyWorkspace.Document.Layers[layerIndex1] = layer2;
                this.historyWorkspace.Document.Layers[layerIndex2] = layer1;
            }

            ((Layer)this.historyWorkspace.Document.Layers[this.layerIndex1]).Invalidate();
            ((Layer)this.historyWorkspace.Document.Layers[this.layerIndex2]).Invalidate();

            return slha;
        }
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            HistoryMemento hm = null;
            int index = documentWorkspace.ActiveLayerIndex;

            if (index != 0)
            {
                SwapLayerHistoryMemento slhm = new SwapLayerHistoryMemento(
                    StaticName,
                    StaticImage,
                    documentWorkspace,
                    index,
                    index - 1);

                hm = slhm.PerformUndo();
            }

            return hm;
        }
예제 #5
0
        protected override HistoryMemento OnUndo(ProgressEventHandler progressCallback)
        {
            SwapLayerHistoryMemento memento = new SwapLayerHistoryMemento(base.Name, base.Image, this.historyWorkspace, this.layerIndex2, this.layerIndex1);

            using (this.historyWorkspace.Document.Layers.UseChangeScope())
            {
                Layer item   = (Layer)this.historyWorkspace.Document.Layers[this.layerIndex1];
                Layer layer2 = (Layer)this.historyWorkspace.Document.Layers[this.layerIndex2];
                int   num    = Math.Min(this.layerIndex1, this.layerIndex2);
                if ((Math.Max(this.layerIndex1, this.layerIndex2) - num) == 1)
                {
                    this.historyWorkspace.Document.Layers.RemoveAt(this.layerIndex1);
                    this.historyWorkspace.Document.Layers.Insert(this.layerIndex2, item);
                }
                else
                {
                    this.historyWorkspace.Document.Layers[this.layerIndex1] = layer2;
                    this.historyWorkspace.Document.Layers[this.layerIndex2] = item;
                }
                this.historyWorkspace.Document.Invalidate();
            }
            return(memento);
        }