Exemplo n.º 1
0
        void m_scripts_Updated(object sender, EditableScriptsUpdatedEventArgs e)
        {
            m_helper.RaiseDirtyEvent(m_scripts.DisplayString());

            if (e.UpdatedScriptEventArgs != null)
            {
                // For nested script updates (e.g. an "if"'s "then" script), there's no need to repopulate the parent script control,
                // as the child script control will have already updated itself to reflect the change.
                if (e.UpdatedScriptEventArgs.IsNestedScriptUpdate)
                {
                    return;
                }

                if (e.UpdatedScriptEventArgs.IsParameterUpdate)
                {
                    // might be an update for a nested script, so check it's "ours" first, and if so, update the control
                    if (m_scriptParameterControlMap.ContainsKey(e.UpdatedScript))
                    {
                        // An entire script refresh would be overkill - we just need to update the specified parameter
                        IElementEditorControl control = GetScriptParameterControl(e.UpdatedScript, e.UpdatedScriptEventArgs.Index.ToString(CultureInfo.InvariantCulture));
                        if (e.UpdatedScript.Type == ScriptType.Normal)
                        {
                            control.Populate(m_controller.GetScriptEditorData(e.UpdatedScript));
                        }
                        else
                        {
                            ((IfEditor)control).Populate((EditableIfScript)e.UpdatedScript);
                        }
                    }
                    return;
                }

                if (e.UpdatedScriptEventArgs.IsNamedParameterUpdate)
                {
                    // might be an update for a nested script, so check it's "ours" first, and if so, update the control
                    if (m_scriptParameterControlMap.ContainsKey(e.UpdatedScript))
                    {
                        // currently, named parameter updates are only used for "else if" expressions. The entire "if" is
                        // registered for attribute "0".
                        IElementEditorControl control = GetScriptParameterControl(e.UpdatedScript, "0");
                        ((IfEditor)control).Populate((EditableIfScript)e.UpdatedScript);
                    }
                    return;
                }

                if (e.UpdatedScript.Type == ScriptType.If)
                {
                    // "If" scripts have their own events which the editor controls handle themselves to update
                    // appropriately, so there is nothing further to do in response to the Updated event.
                    return;
                }
            }

            RefreshScriptsList();
        }
Exemplo n.º 2
0
        public void TestIfThenElseIf()
        {
            // Create an "if (...) { } else if (...) { }" script
            EditableScripts newScripts = Controller.CreateNewEditableScripts("game", "somescript", "if (someExpression) { msg (\"Then script\") }", true);

            ((EditableIfScript)newScripts[0]).AddElseIf();
            EditableIfScript.EditableElseIf newElseIf = ((EditableIfScript)newScripts[0]).ElseIfScripts.First();
            newElseIf.Expression = "elseIfExpression";
            newElseIf.EditableScripts.AddNew("msg (\"test\")", "game");

            // Capture update events
            EditableScriptsUpdatedEventArgs lastArgs = null;

            newScripts.Updated += (object sender, EditableScriptsUpdatedEventArgs e) => { lastArgs = e; };

            // Check the initial display string is correct
            string initialExpectedDisplayString = "If (someExpression) Then (Print \"Then script\"), Else If (elseIfExpression) Then (Print \"test\")";

            Assert.AreEqual(initialExpectedDisplayString, newScripts.DisplayString());

            // Now change the expression
            Controller.StartTransaction("Change elseif expression");
            newElseIf.Expression = "newElseIfExpression";
            Controller.EndTransaction();

            // Check the new display string is correct, and that we received the update event
            string newExpectedDisplayString = "If (someExpression) Then (Print \"Then script\"), Else If (newElseIfExpression) Then (Print \"test\")";

            Assert.AreEqual(newExpectedDisplayString, newScripts.DisplayString());
            Assert.AreEqual(lastArgs.UpdatedScriptEventArgs.NewValue, "newElseIfExpression");

            // Now undo and redo, and check the display strings update correctly
            Controller.Undo();
            Assert.AreEqual(initialExpectedDisplayString, newScripts.DisplayString());
            Controller.Redo();
            Assert.AreEqual(newExpectedDisplayString, newScripts.DisplayString());

            // Now change the script. This automatically creates a transaction.
            newElseIf.EditableScripts.AddNew("msg (\"test2\")", "game");

            // Check the new display string is correct
            string newerExpectedDisplayString = "If (someExpression) Then (Print \"Then script\"), Else If (newElseIfExpression) Then (Print \"test\" / Print \"test2\")".Replace(" / ", Environment.NewLine);

            Assert.AreEqual(newerExpectedDisplayString, newScripts.DisplayString());

            // Now undo and redo, and check the display strings update correctly
            Controller.Undo();
            Assert.AreEqual(newExpectedDisplayString, newScripts.DisplayString());
            Controller.Redo();
            Assert.AreEqual(newerExpectedDisplayString, newScripts.DisplayString());
        }
Exemplo n.º 3
0
        private void TestUndoRedo(string initialScript, string initialDisplayString, string transactionDescription, Action <IEditableScript> changeValue, string newDisplayString)
        {
            EditableScriptsUpdatedEventArgs updatedEventArgs = null;

            // Nothing in the undo/redo lists to start with
            Assert.AreEqual(0, UndoList.Count);
            Assert.AreEqual(0, RedoList.Count);

            // Create a new script and apply it to game.somescript
            EditableScripts newScripts = Controller.CreateNewEditableScripts("game", "somescript", initialScript, true);

            // When the Updated event fires, store the event arguments locally
            newScripts.Updated += delegate(object sender, EditableScriptsUpdatedEventArgs e)
            {
                updatedEventArgs = e;
            };

            // We should now have one script, and the undo list should have one item
            Assert.AreEqual(1, newScripts.Scripts.Count());
            Assert.AreEqual(1, UndoList.Count);
            Assert.AreEqual(0, RedoList.Count);
            IEditableScript script = newScripts[0];

            Assert.AreEqual(initialDisplayString, script.DisplayString());

            // Now make a change to the script
            Controller.StartTransaction(transactionDescription);
            changeValue(script);

            // We expect the Updated event to have been triggered
            Assert.IsTrue(updatedEventArgs != null, "Expected Updated event to be triggered");

            // TO DO: Test the updated event args are correct

            Controller.EndTransaction();

            // We now have an additional undo list item
            Assert.AreEqual(2, UndoList.Count);
            Assert.AreEqual(0, RedoList.Count);
            Assert.AreEqual(transactionDescription, UndoList[0]);

            // Display string should be correct
            Assert.AreEqual(newDisplayString, script.DisplayString());

            // Now undo, and check the undo/redo lists are correct
            Controller.Undo();
            Assert.AreEqual(1, UndoList.Count);
            Assert.AreEqual(1, RedoList.Count);
            Assert.AreEqual(transactionDescription, RedoList[0]);

            // The display string should be back to what it was before the change
            Assert.AreEqual(initialDisplayString, script.DisplayString());

            // Now redo, and check the undo/redo lists are correct
            Controller.Redo();
            Assert.AreEqual(2, UndoList.Count);
            Assert.AreEqual(0, RedoList.Count);
            Assert.AreEqual(transactionDescription, UndoList[0]);

            // Display string should be back to the "changed" version
            Assert.AreEqual(newDisplayString, script.DisplayString());
        }
Exemplo n.º 4
0
        void m_scripts_Updated(object sender, EditableScriptsUpdatedEventArgs e)
        {
            m_helper.RaiseDirtyEvent(m_scripts.DisplayString());

            if (e.UpdatedScriptEventArgs != null)
            {
                // For nested script updates (e.g. an "if"'s "then" script), there's no need to repopulate the parent script control,
                // as the child script control will have already updated itself to reflect the change.
                if (e.UpdatedScriptEventArgs.IsNestedScriptUpdate)
                {
                    return;
                }

                if (e.UpdatedScriptEventArgs.IsParameterUpdate)
                {
                    // might be an update for a nested script, so check it's "ours" first, and if so, update the control
                    if (m_scriptParameterControlMap.ContainsKey(e.UpdatedScript))
                    {
                        // An entire script refresh would be overkill - we just need to update the specified parameter
                        IElementEditorControl control = GetScriptParameterControl(e.UpdatedScript, e.UpdatedScriptEventArgs.Index.ToString());
                        if (e.UpdatedScript.Type == ScriptType.Normal)
                        {
                            control.Populate(m_controller.GetScriptEditorData(e.UpdatedScript));
                        }
                        else
                        {
                            ((IfEditor)control).Populate((EditableIfScript)e.UpdatedScript);
                        }
                    }
                    return;
                }

                if (e.UpdatedScriptEventArgs.IsNamedParameterUpdate)
                {
                    // might be an update for a nested script, so check it's "ours" first, and if so, update the control
                    if (m_scriptParameterControlMap.ContainsKey(e.UpdatedScript))
                    {
                        // currently, named parameter updates are only used for "else if" expressions. The entire "if" is
                        // registered for attribute "0".
                        IElementEditorControl control = GetScriptParameterControl(e.UpdatedScript, "0");
                        ((IfEditor)control).Populate((EditableIfScript)e.UpdatedScript);
                    }
                    return;
                }

                if (e.UpdatedScript.Type == ScriptType.If)
                {
                    // "If" scripts have their own events which the editor controls handle themselves to update
                    // appropriately, so there is nothing further to do in response to the Updated event.
                    return;
                }
            }

            RefreshScriptsList();
        }