Пример #1
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            CompoundHistoryMemento chm = new CompoundHistoryMemento(this.historyName, this.undoImage);

            if (!historyWorkspace.Selection.IsEmpty)
            {
                DeselectFunction df = new DeselectFunction();
                EnterCriticalRegion();
                HistoryMemento hm = df.Execute(historyWorkspace);
                chm.PushNewAction(hm);
            }

            FlipLayerHistoryMemento flha = new FlipLayerHistoryMemento(
                null,
                null,
                historyWorkspace,
                this.layerIndex,
                this.flipType);

            EnterCriticalRegion();
            HistoryMemento flha2 = flha.PerformUndo();
            chm.PushNewAction(flha);

            return chm;
        }
Пример #2
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            CompoundHistoryMemento chm = new CompoundHistoryMemento(this.historyName, this.undoImage);

            if (!historyWorkspace.Selection.IsEmpty)
            {
                DeselectFunction df = new DeselectFunction();
                EnterCriticalRegion();
                HistoryMemento hm = df.Execute(historyWorkspace);
                chm.PushNewAction(hm);
            }

            FlipLayerHistoryMemento flha = new FlipLayerHistoryMemento(
                null,
                null,
                historyWorkspace,
                this.layerIndex,
                this.flipType);

            EnterCriticalRegion();
            HistoryMemento flha2 = flha.PerformUndo();

            chm.PushNewAction(flha);

            return(chm);
        }
Пример #3
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            SelectionData state = null;
            SegmentedList <HistoryMemento> actions = new SegmentedList <HistoryMemento>();

            if (!historyWorkspace.Selection.IsEmpty)
            {
                state = historyWorkspace.Selection.Save();
                HistoryMemento memento3 = new DeselectFunction().Execute(historyWorkspace);
                actions.Add(memento3);
            }
            ReplaceDocumentHistoryMemento item = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);

            actions.Add(item);
            CompoundHistoryMemento memento2 = new CompoundHistoryMemento(StaticName, PdnResources.GetImageResource("Icons.MenuImageFlattenIcon.png"), actions);
            Document document = RetryManager.RunMemorySensitiveOperation <Document>(() => historyWorkspace.Document.Flatten());

            base.EnterCriticalRegion();
            historyWorkspace.Document = document;
            if (state != null)
            {
                SelectionHistoryMemento newHA = new SelectionHistoryMemento(null, null, historyWorkspace);
                historyWorkspace.Selection.Restore(state);
                memento2.AddMemento(newHA);
            }
            return(memento2);
        }
Пример #4
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            CompoundHistoryMemento memento = new CompoundHistoryMemento(this.historyMementoName, this.historyMementoImage);

            if (!historyWorkspace.Selection.IsEmpty)
            {
                DeselectFunction function = new DeselectFunction();
                base.EnterCriticalRegion();
                HistoryMemento memento4 = function.Execute(historyWorkspace);
                memento.AddMemento(memento4);
            }
            FlipLayerHistoryMemento newHA = new FlipLayerHistoryMemento(null, null, historyWorkspace, this.layerIndex, this.flipType);

            base.EnterCriticalRegion();
            HistoryMemento memento3 = newHA.PerformUndo(null);

            memento.AddMemento(newHA);
            return(memento);
        }
Пример #5
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            List <HistoryMemento> mementos = new List <HistoryMemento>();

            if (!historyWorkspace.Selection.IsEmpty)
            {
                DeselectFunction function = new DeselectFunction();
                base.EnterCriticalRegion();
                HistoryMemento item = function.Execute(historyWorkspace);
                mementos.Add(item);
            }
            base.EnterCriticalRegion();
            int count = historyWorkspace.Document.Layers.Count;

            for (int i = 0; i < count; i++)
            {
                HistoryMemento memento2 = new FlipLayerFunction(this.flipType, i).Execute(historyWorkspace);
                mementos.Add(memento2);
            }
            return(HistoryMemento.Combine(this.historyMementoName, this.historyMementoImage, mementos));
        }
Пример #6
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            object savedSelection         = null;
            List <HistoryMemento> actions = new List <HistoryMemento>();

            if (!historyWorkspace.Selection.IsEmpty)
            {
                savedSelection = historyWorkspace.Selection.Save();
                DeselectFunction da = new DeselectFunction();
                HistoryMemento   hm = da.Execute(historyWorkspace);
                actions.Add(hm);
            }

            ReplaceDocumentHistoryMemento rdha = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);

            actions.Add(rdha);

            CompoundHistoryMemento chm = new CompoundHistoryMemento(
                StaticName,
                ImageResource.Get("Icons.MenuImageFlattenIcon.png"),
                actions);

            // TODO: we can save memory here by serializing, then flattening on to an existing layer
            Document flat = historyWorkspace.Document.Flatten();

            EnterCriticalRegion();
            historyWorkspace.Document = flat;

            if (savedSelection != null)
            {
                SelectionHistoryMemento shm = new SelectionHistoryMemento(null, null, historyWorkspace);
                historyWorkspace.Selection.Restore(savedSelection);
                chm.PushNewAction(shm);
            }

            return(chm);
        }
Пример #7
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            object savedSelection = null;
            List<HistoryMemento> actions = new List<HistoryMemento>();

            if (!historyWorkspace.Selection.IsEmpty)
            {
                savedSelection = historyWorkspace.Selection.Save();
                DeselectFunction da = new DeselectFunction();
                HistoryMemento hm = da.Execute(historyWorkspace);
                actions.Add(hm);
            }

            ReplaceDocumentHistoryMemento rdha = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);
            actions.Add(rdha);

            CompoundHistoryMemento chm = new CompoundHistoryMemento(
                StaticName,
                PdnResources.GetImageResource("Icons.MenuImageFlattenIcon.png"),
                actions);

            // TODO: we can save memory here by serializing, then flattening on to an existing layer
            Document flat = historyWorkspace.Document.Flatten();

            EnterCriticalRegion();
            historyWorkspace.Document = flat;

            if (savedSelection != null)
            {
                SelectionHistoryMemento shm = new SelectionHistoryMemento(null, null, historyWorkspace);
                historyWorkspace.Selection.Restore(savedSelection);
                chm.PushNewAction(shm);
            }

            return chm;
        }
Пример #8
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            List<HistoryMemento> actions = new List<HistoryMemento>();

            if (!historyWorkspace.Selection.IsEmpty)
            {
                DeselectFunction da = new DeselectFunction();
                EnterCriticalRegion();
                HistoryMemento hm = da.Execute(historyWorkspace);
                actions.Add(hm);
            }

            int count = historyWorkspace.Document.Layers.Count;

            for (int i = 0; i < count; ++i)
            {
                HistoryMemento memento = new FlipLayerHistoryMemento(this.historyName, undoImage, historyWorkspace, i, flipType);
                EnterCriticalRegion();
                HistoryMemento mementoToAdd = memento.PerformUndo();
                actions.Add(mementoToAdd);
            }

            return new CompoundHistoryMemento(this.historyName, undoImage, actions);
        }
Пример #9
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            List <HistoryMemento> actions = new List <HistoryMemento>();

            if (!historyWorkspace.Selection.IsEmpty)
            {
                DeselectFunction da = new DeselectFunction();
                EnterCriticalRegion();
                HistoryMemento hm = da.Execute(historyWorkspace);
                actions.Add(hm);
            }

            int count = historyWorkspace.Document.Layers.Count;

            for (int i = 0; i < count; ++i)
            {
                HistoryMemento memento = new FlipLayerHistoryMemento(this.historyName, undoImage, historyWorkspace, i, flipType);
                EnterCriticalRegion();
                HistoryMemento mementoToAdd = memento.PerformUndo();
                actions.Add(mementoToAdd);
            }

            return(new CompoundHistoryMemento(this.historyName, undoImage, actions));
        }
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            int newWidth;
            int newHeight;

            // Get new width and Height
            switch (rotation)
            {
                case RotateType.Clockwise90:
                case RotateType.Clockwise270:
                case RotateType.CounterClockwise90:
                case RotateType.CounterClockwise270:
                    newWidth = historyWorkspace.Document.Height;
                    newHeight = historyWorkspace.Document.Width;
                    break;

                case RotateType.Clockwise180:
                case RotateType.CounterClockwise180:
                    newWidth = historyWorkspace.Document.Width;
                    newHeight = historyWorkspace.Document.Height;
                    break;

                default:
                    throw new InvalidEnumArgumentException("invalid RotateType");
            }

            // Figure out which icon and text to use
            string iconResName;
            string suffix;

            switch (rotation)
            {
                case RotateType.Clockwise180:
                    iconResName = "Icons.MenuImageRotate180CWIcon.png";
                    suffix = PdnResources.GetString("RotateAction.180CW");
                    break;

                case RotateType.Clockwise270:
                    iconResName = "Icons.MenuImageRotate270CWIcon.png";
                    suffix = PdnResources.GetString("RotateAction.270CW");
                    break;

                case RotateType.Clockwise90:
                    iconResName = "Icons.MenuImageRotate90CWIcon.png";
                    suffix = PdnResources.GetString("RotateAction.90CW");
                    break;

                case RotateType.CounterClockwise180:
                    iconResName = "Icons.MenuImageRotate180CCWIcon.png";
                    suffix = PdnResources.GetString("RotateAction.180CCW");
                    break;

                case RotateType.CounterClockwise270:
                    iconResName = "Icons.MenuImageRotate270CCWIcon.png";
                    suffix = PdnResources.GetString("RotateAction.270CCW");
                    break;

                case RotateType.CounterClockwise90:
                    iconResName = "Icons.MenuImageRotate90CCWIcon.png";
                    suffix = PdnResources.GetString("RotateAction.90CCW");
                    break;

                default:
                    throw new InvalidEnumArgumentException("invalid RotateType");
            }

            // Initialize the new Doc
            string haNameFormat = PdnResources.GetString("RotateAction.HistoryMementoName.Format");
            string haName = string.Format(haNameFormat, StaticName, suffix);
            ImageResource haImage = ImageResource.Get(iconResName);

            List<HistoryMemento> actions = new List<HistoryMemento>();

            // do the memory allocation now: if this fails, we can still bail out cleanly
            Document newDoc = new Document(newWidth, newHeight);

            if (!historyWorkspace.Selection.IsEmpty)
            {
                DeselectFunction da = new DeselectFunction();
                EnterCriticalRegion();
                HistoryMemento hm = da.Execute(historyWorkspace);
                actions.Add(hm);
            }

            ReplaceDocumentHistoryMemento rdha = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);
            actions.Add(rdha);

            newDoc.ReplaceMetaDataFrom(historyWorkspace.Document);

            // TODO: serialize oldDoc to disk, and let the GC purge it if needed
            OnProgress(0.0);

            for (int i = 0; i < historyWorkspace.Document.Layers.Count; ++i)
            {
                Layer layer = historyWorkspace.Document.Layers.GetAt(i);

                double progressStart = 100.0 * ((double)i / (double)historyWorkspace.Document.Layers.Count);
                double progressEnd = 100.0 * ((double)(i + 1) / (double)historyWorkspace.Document.Layers.Count);

                if (layer is BitmapLayer)
                {
                    Layer nl = RotateLayer((BitmapLayer)layer, rotation, newWidth, newHeight, progressStart, progressEnd);
                    newDoc.Layers.Add(nl);
                }
                else
                {
                    throw new InvalidOperationException("Cannot Rotate non-BitmapLayers");
                }

                if (this.PleaseCancel)
                {
                    break;
                }

                OnProgress(progressEnd);
            }

            CompoundHistoryMemento chm = new CompoundHistoryMemento(
                haName,
                haImage,
                actions);

            if (this.PleaseCancel)
            {
                chm = null;
            }
            else
            {
                EnterCriticalRegion();
                historyWorkspace.Document = newDoc;
            }

            return chm;
        }
Пример #11
0
        private HistoryMemento ImportOneLayer(DocumentWorkspace documentWorkspace, BitmapLayer layer)
        {
            HistoryMemento retHA;
            List<HistoryMemento> historyMementos = new List<HistoryMemento>();
            bool success = true;

            if (success)
            {
                if (!documentWorkspace.Selection.IsEmpty)
                {
                    HistoryMemento ha = new DeselectFunction().Execute(documentWorkspace);
                    historyMementos.Add(ha);
                }
            }

            if (success)
            {
                if (layer.Width > documentWorkspace.Document.Width ||
                    layer.Height > documentWorkspace.Document.Height)
                {
                    HistoryMemento ha = DoCanvasResize(documentWorkspace, layer.Size);

                    if (ha == null)
                    {
                        success = false;
                    }
                    else
                    {
                        historyMementos.Add(ha);
                    }
                }
            }

            if (success)
            {
                if (layer.Size != documentWorkspace.Document.Size)
                {
                    BitmapLayer newLayer;

                    try
                    {
                        using (new WaitCursorChanger(documentWorkspace))
                        {
                            Utility.GCFullCollect();

                            newLayer = CanvasSizeAction.ResizeLayer((BitmapLayer)layer, documentWorkspace.Document.Size,
                                AnchorEdge.TopLeft, ColorBgra.White.NewAlpha(0));
                        }
                    }

                    catch (OutOfMemoryException)
                    {
                        Utility.ErrorBox(documentWorkspace, PdnResources.GetString("ImportFromFileAction.ImportOneLayer.OutOfMemory"));
                        success = false;
                        newLayer = null;
                    }

                    if (newLayer != null)
                    {
                        layer.Dispose();
                        layer = newLayer;
                    }
                }
            }

            if (success)
            {
                NewLayerHistoryMemento nlha = new NewLayerHistoryMemento(string.Empty, null, documentWorkspace, documentWorkspace.Document.Layers.Count);
                documentWorkspace.Document.Layers.Add(layer);
                historyMementos.Add(nlha);
            }

            if (success)
            {
                HistoryMemento[] has = historyMementos.ToArray();
                retHA = new CompoundHistoryMemento(string.Empty, null, has);
            }
            else
            {
                Rollback(historyMementos);
                retHA = null;
            }

            return retHA;
        }
Пример #12
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            int    height;
            int    width;
            string str;
            string str2;

            switch (this.rotation)
            {
            case RotateType.Clockwise90:
            case RotateType.CounterClockwise90:
                height = historyWorkspace.Document.Height;
                width  = historyWorkspace.Document.Width;
                break;

            case RotateType.Rotate180:
                height = historyWorkspace.Document.Width;
                width  = historyWorkspace.Document.Height;
                break;

            default:
                throw ExceptionUtil.InvalidEnumArgumentException <RotateType>(this.rotation, "this.rotation");
            }
            switch (this.rotation)
            {
            case RotateType.Clockwise90:
                str  = "Icons.MenuImageRotate90CWIcon.png";
                str2 = PdnResources.GetString("RotateAction.90CW");
                break;

            case RotateType.CounterClockwise90:
                str  = "Icons.MenuImageRotate90CCWIcon.png";
                str2 = PdnResources.GetString("RotateAction.90CCW");
                break;

            case RotateType.Rotate180:
                str  = "Icons.MenuImageRotate180Icon.png";
                str2 = PdnResources.GetString("RotateAction.180");
                break;

            default:
                throw ExceptionUtil.InvalidEnumArgumentException <RotateType>(this.rotation, "this.rotation");
            }
            string                name          = string.Format(PdnResources.GetString("RotateAction.HistoryMementoName.Format"), StaticName, str2);
            ImageResource         imageResource = PdnResources.GetImageResource(str);
            List <HistoryMemento> actions       = new List <HistoryMemento>();
            Document              document      = new Document(height, width);

            if (!historyWorkspace.Selection.IsEmpty)
            {
                DeselectFunction function = new DeselectFunction();
                base.EnterCriticalRegion();
                HistoryMemento memento3 = function.Execute(historyWorkspace);
                actions.Add(memento3);
            }
            ReplaceDocumentHistoryMemento item = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);

            actions.Add(item);
            document.ReplaceMetadataFrom(historyWorkspace.Document);
            for (int i = 0; i < historyWorkspace.Document.Layers.Count; i++)
            {
                Layer at = historyWorkspace.Document.Layers.GetAt(i);
                if (!(at is BitmapLayer))
                {
                    throw new InvalidOperationException("Cannot Rotate non-BitmapLayers");
                }
                Layer layer2 = this.RotateLayer((BitmapLayer)at, this.rotation, height, width);
                document.Layers.Add(layer2);
            }
            CompoundHistoryMemento memento2 = new CompoundHistoryMemento(name, imageResource, actions);

            base.EnterCriticalRegion();
            historyWorkspace.Document = document;
            return(memento2);
        }
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            int newWidth;
            int newHeight;

            // Get new width and Height
            switch (rotation)
            {
            case RotateType.Clockwise90:
            case RotateType.Clockwise270:
            case RotateType.CounterClockwise90:
            case RotateType.CounterClockwise270:
                newWidth  = historyWorkspace.Document.Height;
                newHeight = historyWorkspace.Document.Width;
                break;

            case RotateType.Clockwise180:
            case RotateType.CounterClockwise180:
                newWidth  = historyWorkspace.Document.Width;
                newHeight = historyWorkspace.Document.Height;
                break;

            default:
                throw new InvalidEnumArgumentException("invalid RotateType");
            }

            // Figure out which icon and text to use
            string iconResName;
            string suffix;

            switch (rotation)
            {
            case RotateType.Clockwise180:
                iconResName = "Icons.MenuImageRotate180CWIcon.png";
                suffix      = PdnResources.GetString("RotateAction.180CW");
                break;

            case RotateType.Clockwise270:
                iconResName = "Icons.MenuImageRotate270CWIcon.png";
                suffix      = PdnResources.GetString("RotateAction.270CW");
                break;

            case RotateType.Clockwise90:
                iconResName = "Icons.MenuImageRotate90CWIcon.png";
                suffix      = PdnResources.GetString("RotateAction.90CW");
                break;

            case RotateType.CounterClockwise180:
                iconResName = "Icons.MenuImageRotate180CCWIcon.png";
                suffix      = PdnResources.GetString("RotateAction.180CCW");
                break;

            case RotateType.CounterClockwise270:
                iconResName = "Icons.MenuImageRotate270CCWIcon.png";
                suffix      = PdnResources.GetString("RotateAction.270CCW");
                break;

            case RotateType.CounterClockwise90:
                iconResName = "Icons.MenuImageRotate90CCWIcon.png";
                suffix      = PdnResources.GetString("RotateAction.90CCW");
                break;

            default:
                throw new InvalidEnumArgumentException("invalid RotateType");
            }

            // Initialize the new Doc
            string        haNameFormat = PdnResources.GetString("RotateAction.HistoryMementoName.Format");
            string        haName       = string.Format(haNameFormat, StaticName, suffix);
            ImageResource haImage      = ImageResource.Get(iconResName);

            List <HistoryMemento> actions = new List <HistoryMemento>();

            // do the memory allocation now: if this fails, we can still bail out cleanly
            Document newDoc = new Document(newWidth, newHeight);

            if (!historyWorkspace.Selection.IsEmpty)
            {
                DeselectFunction da = new DeselectFunction();
                EnterCriticalRegion();
                HistoryMemento hm = da.Execute(historyWorkspace);
                actions.Add(hm);
            }

            ReplaceDocumentHistoryMemento rdha = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);

            actions.Add(rdha);

            newDoc.ReplaceMetaDataFrom(historyWorkspace.Document);

            // TODO: serialize oldDoc to disk, and let the GC purge it if needed
            OnProgress(0.0);

            for (int i = 0; i < historyWorkspace.Document.Layers.Count; ++i)
            {
                Layer layer = historyWorkspace.Document.Layers.GetAt(i);

                double progressStart = 100.0 * ((double)i / (double)historyWorkspace.Document.Layers.Count);
                double progressEnd   = 100.0 * ((double)(i + 1) / (double)historyWorkspace.Document.Layers.Count);

                if (layer is BitmapLayer)
                {
                    Layer nl = RotateLayer((BitmapLayer)layer, rotation, newWidth, newHeight, progressStart, progressEnd);
                    newDoc.Layers.Add(nl);
                }
                else
                {
                    throw new InvalidOperationException("Cannot Rotate non-BitmapLayers");
                }

                if (this.PleaseCancel)
                {
                    break;
                }

                OnProgress(progressEnd);
            }

            CompoundHistoryMemento chm = new CompoundHistoryMemento(
                haName,
                haImage,
                actions);

            if (this.PleaseCancel)
            {
                chm = null;
            }
            else
            {
                EnterCriticalRegion();
                historyWorkspace.Document = newDoc;
            }

            return(chm);
        }