예제 #1
0
        protected override bool GetEnabled(string ribbonId)
        {
            Selection currentSelection = this.GetCurrentSelection();

            return(!ClipboardUtil.IsClipboardEmpty() &&
                   ShapeUtil.IsSelectionSingleShape(currentSelection) &&
                   !ShapeUtil.HasPlaceholderInSelection(currentSelection));
        }
        // 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();
            }
        }
 protected override bool GetEnabled(string ribbonId)
 {
     return(!ClipboardUtil.IsClipboardEmpty());
 }