/// <summary> /// Pastes the step from the system's copy buffer into the chapter at given <paramref name="position"/>. /// </summary> /// <returns>True if successful.</returns> public bool Paste(Vector2 position) { IStep step; try { step = SystemClipboard.PasteStep(); if (step == null) { return(false); } step.Data.Name = "Copy of " + step.Data.Name; step.StepMetadata.Position = position - new Vector2(0f, step.Data.Transitions.Data.Transitions.Count * 20f / 2f); } catch { return(false); } AddStepWithUndo(step); return(true); }
private void HandleCanvasContextClick(object sender, PointerGraphicalElementEventArgs e) { IList <TestableEditorElements.MenuOption> options = new List <TestableEditorElements.MenuOption>(); options.Add(new TestableEditorElements.MenuItem(new GUIContent("Add step"), false, () => { IStep step = EntityFactory.CreateStep("New Step"); step.StepMetadata.Position = e.PointerPosition; AddStepWithUndo(step); })); if (SystemClipboard.IsStepInClipboard()) { options.Add(new TestableEditorElements.MenuItem(new GUIContent("Paste step"), false, () => { Paste(e.PointerPosition); })); } else { options.Add(new TestableEditorElements.DisabledMenuItem(new GUIContent("Paste step"))); } TestableEditorElements.DisplayContextMenu(options); }
public void PasteWithName() { // Given a step with a name IStep step = new Step("Quite rare name"); // When I copy and paste it SystemClipboard.CopyStep(step); IStep copy = SystemClipboard.PasteStep(); // Then the copy has the same name Assert.AreEqual(step.Data.Name, copy.Data.Name); }
public void PasteNewInstance() { // Given a step IStep step = new Step("Step"); // When I copy and paste it SystemClipboard.CopyStep(step); IStep copy = SystemClipboard.PasteStep(); // Then it creates a new instance of the step. Assert.IsFalse(ReferenceEquals(step, copy)); }
public void CopyIntoBuffer() { // Given a step and a value in the system copy buffer IStep step = new Step("Step"); string testValue = "Hello!"; EditorGUIUtility.systemCopyBuffer = testValue; // When I copy that step SystemClipboard.CopyStep(step); // Then the system's copy buffer value has changed. Assert.AreNotEqual(testValue, EditorGUIUtility.systemCopyBuffer); }
public void PasteWithTransitionToItself() { // Given a step with a transition to itself, IStep step = new Step("Step"); step.Data.Transitions.Data.Transitions.Add(new Transition()); step.Data.Transitions.Data.Transitions.First().Data.TargetStep = step; // When I copy and paste it SystemClipboard.CopyStep(step); IStep copy = SystemClipboard.PasteStep(); // Then the copy's transition leads to the end of chapter. Assert.IsNull(copy.Data.Transitions.Data.Transitions.First().Data.TargetStep); }
public void PasteWithBehavior() { // Given a step with a behavior IStep step = new BasicStepBuilder("Step") .AddBehavior(new EmptyBehaviorMock()) .Build(); // When I copy and paste it SystemClipboard.CopyStep(step); IStep copy = SystemClipboard.PasteStep(); // The copy has a new copy of the behavior Assert.IsFalse(ReferenceEquals( step.Data.Behaviors.Data.Behaviors.First(), copy.Data.Behaviors.Data.Behaviors.First())); }
public void PasteMultipleTimes() { // Given a step IStep step = new Step("Step"); // When I copy and then paste it multiple times SystemClipboard.CopyStep(step); IStep copy1 = SystemClipboard.PasteStep(); IStep copy2 = SystemClipboard.PasteStep(); IStep copy3 = SystemClipboard.PasteStep(); // Then it creates multiple new instances. Assert.NotNull(copy1); Assert.NotNull(copy2); Assert.NotNull(copy3); }
public void PasteMultipleTransitions() { // Given a step with three transitions, IStep step = new Step("Step"); step.Data.Transitions.Data.Transitions.Add(new Transition()); step.Data.Transitions.Data.Transitions.Add(new Transition()); step.Data.Transitions.Data.Transitions.Add(new Transition()); // When I copy and paste it, SystemClipboard.CopyStep(step); IStep copy = SystemClipboard.PasteStep(); // Then the copy has three transitions, too Assert.AreEqual(3, copy.Data.Transitions.Data.Transitions.Count); }
public void PasteWithPropertyReference() { // Given a step with a behavior with a property reference IStep step = new BasicStepBuilder("Step") .AddBehavior(new ObjectReferenceBehaviorMock("Quite unique name")) .Build(); // When I copy and paste it SystemClipboard.CopyStep(step); IStep copy = SystemClipboard.PasteStep(); // Then the copy stores the same value as the original behavior. Assert.AreEqual( ((ObjectReferenceBehaviorMock)step.Data.Behaviors.Data.Behaviors.First()).Data.ReferenceObject.UniqueName, ((ObjectReferenceBehaviorMock)copy.Data.Behaviors.Data.Behaviors.First()).Data.ReferenceObject.UniqueName); }
public void PasteWithPrimitiveValue() { // Given a step with a behavior with a primitive value IStep step = new BasicStepBuilder("Step") .AddBehavior(new ValueBehaviorMock(5f)) .Build(); // When I copy and paste it SystemClipboard.CopyStep(step); IStep copy = SystemClipboard.PasteStep(); // Then the copy stores the same value as the original behavior. Assert.AreEqual( ((ValueBehaviorMock)step.Data.Behaviors.Data.Behaviors.First()).Data.Value, ((ValueBehaviorMock)copy.Data.Behaviors.Data.Behaviors.First()).Data.Value); }
public void PasteKeepBehaviorType() { // Given a step with a behavior IStep step = new BasicStepBuilder("Step") .AddBehavior(new EmptyBehaviorMock()) .Build(); // When I copy and paste it SystemClipboard.CopyStep(step); IStep copy = SystemClipboard.PasteStep(); // The copy of the behavior has the same type. Assert.AreEqual( step.Data.Behaviors.Data.Behaviors.First().GetType(), copy.Data.Behaviors.Data.Behaviors.First().GetType()); }
private bool CopyStep(IStep step) { if (step == null) { return(false); } try { SystemClipboard.CopyStep(step); return(true); } catch { return(false); } }
public void PasteMultipleTransitionsAndConditions() { // Given a step with three transitions with different conditions, IStep step = new Step("Step"); step.Data.Transitions.Data.Transitions.Add(new Transition()); step.Data.Transitions.Data.Transitions.Add(new Transition()); step.Data.Transitions.Data.Transitions.Add(new Transition()); step.Data.Transitions.Data.Transitions[0].Data.Conditions.Add(new EndlessConditionMock()); step.Data.Transitions.Data.Transitions[1].Data.Conditions.Add(new OptionalEndlessConditionMock()); step.Data.Transitions.Data.Transitions[2].Data.Conditions.Add(new AutoCompletedCondition()); // When I copy and paste it, SystemClipboard.CopyStep(step); IStep copy = SystemClipboard.PasteStep(); // Then the copy has three transitions, too Assert.AreEqual(typeof(EndlessConditionMock), copy.Data.Transitions.Data.Transitions[0].Data.Conditions[0].GetType()); Assert.AreEqual(typeof(OptionalEndlessConditionMock), copy.Data.Transitions.Data.Transitions[1].Data.Conditions[0].GetType()); Assert.AreEqual(typeof(AutoCompletedCondition), copy.Data.Transitions.Data.Transitions[2].Data.Conditions[0].GetType()); }
public void PasteWithCondition() { // Given a step with a transition with a condition, IStep step = new BasicStepBuilder("Step") .AddCondition(new EndlessConditionMock()) .Build(); IStep target = new Step("Step 2"); step.Data.Transitions.Data.Transitions.First().Data.TargetStep = target; // When I copy and paste it SystemClipboard.CopyStep(step); IStep copy = SystemClipboard.PasteStep(); // Then the copy's transition has a copy of the condition. Assert.AreEqual( step.Data.Transitions.Data.Transitions.First().Data.Conditions.First().GetType(), copy.Data.Transitions.Data.Transitions.First().Data.Conditions.First().GetType()); Assert.IsFalse(ReferenceEquals( step.Data.Transitions.Data.Transitions.First().Data.Conditions.First(), copy.Data.Transitions.Data.Transitions.First().Data.Conditions.First())); }
public void PasteWithTransitionsWithTargets() { // Given a step with three transitions to different steps, IStep step = new Step("Step"); IStep target1 = new Step("Target 1"); IStep target2 = new Step("Target 2"); IStep target3 = new Step("Target 3"); step.Data.Transitions.Data.Transitions.Add(new Transition()); step.Data.Transitions.Data.Transitions.Add(new Transition()); step.Data.Transitions.Data.Transitions.Add(new Transition()); step.Data.Transitions.Data.Transitions[0].Data.TargetStep = target1; step.Data.Transitions.Data.Transitions[1].Data.TargetStep = target2; step.Data.Transitions.Data.Transitions[2].Data.TargetStep = target3; // When I copy and paste it SystemClipboard.CopyStep(step); IStep copy = SystemClipboard.PasteStep(); // Then the all copy's transitions leads to the end of chapter. Assert.IsNull(copy.Data.Transitions.Data.Transitions[0].Data.TargetStep); Assert.IsNull(copy.Data.Transitions.Data.Transitions[1].Data.TargetStep); Assert.IsNull(copy.Data.Transitions.Data.Transitions[2].Data.TargetStep); }