protected static void CheckIfClipboardIsRestored(Action action, int actualSlideNum, string shapeNameToBeCopied, int expSlideNum, string expShapeNameToDelete, string expCopiedShapeName) { Slide actualSlide = PpOperations.SelectSlide(actualSlideNum); ShapeRange shapeToBeCopied = PpOperations.SelectShape(shapeNameToBeCopied); Assert.AreEqual(1, shapeToBeCopied.Count); // Add this shape to clipboard shapeToBeCopied.Copy(); action(); // Paste whatever in clipboard ShapeRange newShape = actualSlide.Shapes.Paste(); // Check if pasted shape is the same as the shape added to clipboard originally Assert.AreEqual(shapeNameToBeCopied, newShape.Name); Assert.AreEqual(shapeToBeCopied.Count, newShape.Count); Slide expSlide = PpOperations.SelectSlide(expSlideNum); if (expShapeNameToDelete != "") { PpOperations.SelectShape(expShapeNameToDelete)[1].Delete(); } //Set the pasted shape location because the location of the pasted shape is flaky Shape expCopied = PpOperations.SelectShape(expCopiedShapeName)[1]; newShape.Top = expCopied.Top; newShape.Left = expCopied.Left; SlideUtil.IsSameLooking(expSlide, actualSlide); }
/// <summary> /// Tries to restore clipboard with provided SlideRange first, then ShapeRange then finally Shape. /// Note that clipboard cannot be restored if last copied item was a placeholder (for now) /// </summary> /// <returns>True if successfully restored</returns> private static void RestoreClipboard(Shape shape = null, ShapeRange shapes = null, SlideRange slides = null) { try { if (slides != null) { slides.Copy(); slides.Delete(); } else if (shapes != null && shapes.Count >= 1) { shapes.Copy(); shapes.Delete(); } else if (shape != null) { shape.Copy(); shape.Delete(); } } catch (COMException e) { // May be thrown when trying to copy Logger.LogException(e, "RestoreClipboard"); } }
public static ShapeRange SafeCopy(this Shapes shapes, ShapeRange shapeRange) { return(PPLClipboard.Instance.LockAndRelease(() => { shapeRange.Copy(); return shapes.Paste(); })); }
private static void AutoAnimateWithCopyPasteShapesSuccessfully() { PpOperations.SelectSlide(8); ShapeRange pastingShapes = PpOperations.SelectShapes(new List <string> { "Notched Right Arrow", "Group" }); PPLClipboard.Instance.LockAndRelease(() => { pastingShapes.Copy(); Slide targetSlide = PpOperations.SelectSlide(9); targetSlide.Shapes.Paste(); }); Assert.IsNotNull(PpOperations.SelectShape("Notched Right Arrow"), "Copy-Paste failed, this task is flaky so please re-run."); Shape sh1 = PpOperations.SelectShape("Notched Right Arrow")[1]; sh1.Rotation += 90; Shape sh2 = PpOperations.SelectShape("Group")[1]; sh2.Rotation += 90; // go back to slide 8 PpOperations.SelectSlide(8); PplFeatures.AutoAnimate(); Slide actualSlide = PpOperations.SelectSlide(9); // remove elements that affect comparing slides PpOperations.SelectShapesByPrefix("text").Delete(); Slide expSlide = PpOperations.SelectSlide(11); // remove elements that affect comparing slides PpOperations.SelectShapesByPrefix("text").Delete(); // TODO: actually this expected slide looks a bit strange.. SlideUtil.IsSameAnimations(expSlide, actualSlide); SlideUtil.IsSameLooking(expSlide, actualSlide); }
/// <summary> /// Tries to restore clipboard with provided SlideRange first, then ShapeRange then finally Shape. /// Note that clipboard cannot be restored if last copied item was a placeholder (for now) /// </summary> /// <returns>True if successfully restored</returns> private static void RestoreClipboard(ShapeRange shapes = null, SlideRange slides = null) { try { PPLClipboard.Instance.LockAndRelease(() => { if (slides != null) { slides.Copy(); slides.Delete(); } else if (shapes != null && shapes.Count >= 1) { shapes.Copy(); shapes.SafeDelete(); } }); } catch (COMException e) { // May be thrown when trying to copy Logger.LogException(e, "RestoreClipboard"); } }
// 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."); 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; // Save clipboard onto a temp slide, because CorruptionCorrrection uses Copy-Paste PowerPointSlide tempClipboardSlide = presentation.AddSlide(index: slide.Index); ShapeRange tempClipboardShapes = ClipboardUtil.PasteShapesFromClipboard(tempClipboardSlide); // Nothing is pasted, stop now if (tempClipboardShapes == null) { tempClipboardSlide.Delete(); return; } // 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); // Revert clipboard tempClipboardShapes.Copy(); tempClipboardSlide.Delete(); } ShapeRange result = ExecutePasteAction(ribbonId, presentation, slide, passedSelectedShapes, passedSelectedChildShapes); if (result != null) { result.Select(); } }