// Sealed method: Subclasses should override ExecutePasteAction instead
        protected sealed override void ExecuteAction(string ribbonId)
        {
            this.StartNewUndoEntry();

            PowerPointPresentation presentation = this.GetCurrentPresentation();
            PowerPointSlide        slide        = this.GetCurrentSlide();
            Selection selection = this.GetCurrentSelection();

            if (ClipboardUtil.IsClipboardEmpty())
            {
                Logger.Log(ribbonId + " failed. Clipboard is empty.");
                MessageBox.Show(PasteLabText.ErrorEmptyClipboard, PasteLabText.ErrorDialogTitle);
                return;
            }

            ShapeRange passedSelectedShapes      = null;
            ShapeRange passedSelectedChildShapes = null;

            if (ShapeUtil.IsSelectionShape(selection) && !IsSelectionIgnored(ribbonId))
            {
                // When pasting some objects, the selection may change to the pasted object (e.g. jpg from desktop).
                // Therefore we must capture the selection first.
                ShapeRange selectedShapes = selection.ShapeRange;

                // Preserve selection by tagging them
                for (int i = 1; i <= selectedShapes.Count; i++)
                {
                    selectedShapes[i].Tags.Add(SelectOrderTagName, i.ToString());
                }

                ShapeRange selectedChildShapes = null;
                if (selection.HasChildShapeRange)
                {
                    selectedChildShapes = selection.ChildShapeRange;
                    for (int i = 1; i <= selectedChildShapes.Count; i++)
                    {
                        selectedChildShapes[i].Tags.Add(SelectChildOrderTagName, i.ToString());
                    }
                }

                // Corruption correction
                ShapeRange correctedShapes = ShapeUtil.CorruptionCorrection(selectedShapes, slide);

                // Reselect the preserved selections
                List <Shape> correctedShapeList      = new List <Shape>();
                List <Shape> correctedChildShapeList = new List <Shape>();
                foreach (Shape shape in correctedShapes)
                {
                    correctedShapeList.Add(shape);
                    correctedChildShapeList.AddRange(ShapeUtil.GetChildrenWithNonEmptyTag(shape, SelectChildOrderTagName));
                }
                correctedShapeList.Sort((sh1, sh2) => int.Parse(sh1.Tags[SelectOrderTagName]) - int.Parse(sh2.Tags[SelectOrderTagName]));
                correctedChildShapeList.Sort((sh1, sh2) => int.Parse(sh1.Tags[SelectChildOrderTagName]) - int.Parse(sh2.Tags[SelectChildOrderTagName]));
                passedSelectedShapes      = slide.ToShapeRange(correctedShapeList);
                passedSelectedChildShapes = slide.ToShapeRange(correctedChildShapeList);

                // Remove shape tags after they have been used
                ShapeUtil.DeleteTagFromShapes(passedSelectedShapes, SelectOrderTagName);
                ShapeUtil.DeleteTagFromShapes(passedSelectedChildShapes, SelectChildOrderTagName);
            }

            ShapeRange result = ExecutePasteAction(ribbonId, presentation, slide, passedSelectedShapes, passedSelectedChildShapes);

            if (result != null)
            {
                result.Select();
            }
        }
Пример #2
0
        // Sealed method: Subclasses should override ExecutePasteAction instead
        protected sealed override void ExecuteAction(string ribbonId)
        {
            this.StartNewUndoEntry();

            PowerPointPresentation presentation = this.GetCurrentPresentation();
            PowerPointSlide        slide        = this.GetCurrentSlide();
            Selection selection = this.GetCurrentSelection();

            if (GraphicsUtil.IsClipboardEmpty())
            {
                Logger.Log(ribbonId + " failed. Clipboard is empty.");
                return;
            }

            ShapeRange passedSelectedShapes      = null;
            ShapeRange passedSelectedChildShapes = null;

            if (ShapeUtil.IsSelectionShape(selection) && !IsSelectionIgnored(ribbonId))
            {
                // Save clipboard onto a temp slide, because CorruptionCorrrection uses Copy-Paste
                PowerPointSlide tempClipboardSlide  = presentation.AddSlide(index: slide.Index);
                ShapeRange      tempClipboardShapes = PasteShapesFromClipboard(tempClipboardSlide);

                // Nothing is pasted, stop now
                if (tempClipboardShapes == null)
                {
                    tempClipboardSlide.Delete();
                    return;
                }

                // Preserve selection using tags
                ShapeRange selectedShapes = selection.ShapeRange;
                for (int i = 1; i <= selectedShapes.Count; i++)
                {
                    selectedShapes[i].Tags.Add(SelectOrderTagName, i.ToString());
                }

                ShapeRange selectedChildShapes = null;
                if (selection.HasChildShapeRange)
                {
                    selectedChildShapes = selection.ChildShapeRange;
                    for (int i = 1; i <= selectedChildShapes.Count; i++)
                    {
                        selectedChildShapes[i].Tags.Add(SelectChildOrderTagName, i.ToString());
                    }
                }

                // Corruption correction
                ShapeRange correctedShapes = ShapeUtil.CorruptionCorrection(selectedShapes, slide);

                // Reselect the preserved selections
                List <Shape> correctedShapeList      = new List <Shape>();
                List <Shape> correctedChildShapeList = new List <Shape>();
                foreach (Shape shape in correctedShapes)
                {
                    correctedShapeList.Add(shape);
                    correctedChildShapeList.AddRange(ShapeUtil.GetChildrenWithNonEmptyTag(shape, SelectChildOrderTagName));
                }
                correctedShapeList.Sort((sh1, sh2) => int.Parse(sh1.Tags[SelectOrderTagName]) - int.Parse(sh2.Tags[SelectOrderTagName]));
                correctedChildShapeList.Sort((sh1, sh2) => int.Parse(sh1.Tags[SelectChildOrderTagName]) - int.Parse(sh2.Tags[SelectChildOrderTagName]));
                passedSelectedShapes      = slide.ToShapeRange(correctedShapeList);
                passedSelectedChildShapes = slide.ToShapeRange(correctedChildShapeList);

                // Remove the tags after they have been used
                ShapeUtil.DeleteTagFromShapes(passedSelectedShapes, SelectOrderTagName);
                ShapeUtil.DeleteTagFromShapes(passedSelectedChildShapes, SelectChildOrderTagName);

                // Revert clipboard
                tempClipboardShapes.Copy();
                tempClipboardSlide.Delete();
            }

            ShapeRange result = ExecutePasteAction(ribbonId, presentation, slide, passedSelectedShapes, passedSelectedChildShapes);

            if (result != null)
            {
                result.Select();
            }
        }