private void AddElseIfChildControl(EditableIfScript.EditableElseIf elseIfData) { IfEditorChild newChild = new IfEditorChild(); newChild.Mode = IfEditorChild.IfEditorChildMode.ElseIf; newChild.Margin = new Thickness(0, 10, 0, 0); newChild.Dirty += RaiseDirtyEvent; newChild.RequestParentElementEditorSave += RaiseRequestParentElementEditorSaveEvent; newChild.Delete += IfEditorChild_Delete; newChild.Initialise(m_controller); newChild.ReadOnly = m_readOnly; newChild.Populate(elseIfData, elseIfData.EditableScripts); newChild.ElseIfData = elseIfData; m_elseIfEditors.Add(elseIfData.Id, newChild); // First ElseIf script is at Row 1 int rowIndex = m_elseIfEditors.Count; if (m_elseIfEditors.Count > m_elseIfGridRows.Count) { RowDefinition newRow = new RowDefinition(); newRow.Height = GridLength.Auto; grid.RowDefinitions.Insert(rowIndex, newRow); m_elseIfGridRows.Add(newRow); Grid.SetRow(cmdAddElseIf, Grid.GetRow(cmdAddElseIf) + 1); Grid.SetRow(cmdAddElse, Grid.GetRow(cmdAddElse) + 1); Grid.SetRow(ctlElse, Grid.GetRow(ctlElse) + 1); } Grid.SetRow(newChild, rowIndex); grid.Children.Add(newChild); }
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()); }
private void RemoveElseIfChildControl(EditableIfScript.EditableElseIf elseIfData) { RemoveElseIfEditor(m_elseIfEditors[elseIfData.Id]); m_elseIfEditors.Remove(elseIfData.Id); }