public ScriptCommandEditorData(EditorController controller, IEditableScript script) { m_controller = controller; m_script = script; m_script.Updated += m_script_Updated; }
public ScriptCommandEditorData(EditorController controller, IEditableScript script) { m_controller = controller; m_script = script; m_script.Updated += m_script_Updated; }
private void AddToScriptParameterControlMap(IEditableScript script, string parameter, IElementEditorControl control) { if (parameter == null) { return; } if (!m_scriptParameterControlMap.ContainsKey(script)) { m_scriptParameterControlMap.Add(script, new Dictionary <string, IElementEditorControl>()); } m_scriptParameterControlMap[script].Add(parameter, control); }
private void AddScript(IEditableScript script) { ListBoxItem newItem = new ListBoxItem { HorizontalAlignment = HorizontalAlignment.Stretch }; // a DockPanel is used as the ItemsPanel, so that when nested Expanders are collapsed, // they don't leave a blank space DockPanel.SetDock(newItem, Dock.Top); lstScripts.Items.Add(newItem); if (script.Type != ScriptType.If) { Grid parentGrid = new Grid(); parentGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); parentGrid.HorizontalAlignment = HorizontalAlignment.Stretch; newItem.Content = parentGrid; AddScriptControls(newItem, parentGrid, script); } else { IfEditor newIfEditor = new IfEditor { Padding = new Thickness(3), HorizontalAlignment = HorizontalAlignment.Stretch }; AddEditorControl(newIfEditor, newItem, null); newItem.Content = newIfEditor; newIfEditor.ReadOnly = m_readOnly; newIfEditor.Populate((EditableIfScript)script); // Ensure the expression responds to updates e.g. from undo/redo. The nested scripts will take // care of themselves. // TO DO: This isn't particularly efficient, as when m_scripts_Updated is triggered it repopulates // the entire "if" script when an if/elseif expression changes. It should only need to update the // changed expression. AddToScriptParameterControlMap(script, "0", newIfEditor); } }
private void AddNewScriptCommand(string script) { if (m_scripts == null) { if (m_parentScript != null) { m_scripts = m_controller.CreateNewEditableScriptsChild(m_parentScript, m_helper.ControlDefinition.Attribute, script, true); } else { m_scripts = m_controller.CreateNewEditableScripts(ElementName, m_helper.ControlDefinition.Attribute, script, true, true); } } else { m_scripts.AddNew(script, ElementName); } int newScriptIndex = m_scripts.Count - 1; RefreshScriptsList(); SetSelectedIndex(newScriptIndex); lstScripts.Focus(); IEditableScript newScript = m_scripts[newScriptIndex]; if (m_scriptParameterControlMap.ContainsKey(newScript) && m_scriptParameterControlMap[newScript].ContainsKey("0")) { IElementEditorControl ctl = m_scriptParameterControlMap[newScript]["0"]; Control focusControl = ctl.FocusableControl; if (focusControl != null) { Thread newThread = new Thread(() => SetFocusAfterDelay(focusControl)); newThread.Start(); } } }
public IEditorData GetScriptEditorData(IEditableScript script) { switch (script.Type) { case ScriptType.Normal: return new ScriptCommandEditorData(this, script); default: throw new NotImplementedException(); } }
public IEditorDefinition GetEditorDefinition(IEditableScript script) { if (script.EditorName.StartsWith("(function)")) { // see if we have a specific editor definition for this function EditorDefinition result; if (m_editorDefinitions.TryGetValue(script.EditorName, out result)) { return result; } // if not, return the default function call editor definition, and reset // the EditorName for the script so it knows to get/set parameters via a // parameter dictionary instead of individually. script.EditorName = "()"; } return m_editorDefinitions[script.EditorName]; }
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()); }
private IElementEditorControl GetScriptParameterControl(IEditableScript script, string parameter) { return(m_scriptParameterControlMap[script][parameter]); }
private void AddScriptControls(ListBoxItem listItem, Grid parentGrid, IEditableScript script) { IEditorDefinition definition = m_controller.GetEditorDefinition(script); IEditorData data = m_controller.GetScriptEditorData(script); data.ReadOnly = m_readOnly; Grid grid = NewScriptControlGrid(parentGrid); foreach (IEditorControl ctl in definition.Controls) { bool isFullWidthControl = false; string controlType = ctl.ControlType; if (ctl.ControlType == "script") { controlType = "scriptexpander"; isFullWidthControl = true; } if (ctl.ControlType == "scriptdictionary" || ctl.ControlType == "list" || ctl.Expand) { isFullWidthControl = true; } Control newControl = ControlFactory.CreateEditorControl(m_controller, controlType); newControl.VerticalAlignment = VerticalAlignment.Top; if (newControl is LabelControl) { newControl.Padding = new Thickness(3, 6, 3, 3); } else { newControl.Padding = new Thickness(3); } if (isFullWidthControl) { newControl.HorizontalAlignment = HorizontalAlignment.Stretch; } if (ctl.GetBool("breakbefore")) { // Create a "line break" by putting this and subsequent controls in a new horizontal grid, // underneath the previous one. We're using a grid instead of a StackPanel as script expanders // won't take the full width of the list otherwise. grid = NewScriptControlGrid(parentGrid); // Indent the new line newControl.Padding = new Thickness(newControl.Padding.Left + 20, newControl.Padding.Top, newControl.Padding.Right, newControl.Padding.Bottom); } grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, isFullWidthControl ? GridUnitType.Star : GridUnitType.Auto) }); Grid.SetColumn(newControl, grid.ColumnDefinitions.Count - 1); grid.Children.Add(newControl); IElementEditorControl editorCtl = newControl as IElementEditorControl; if (editorCtl != null) { AddEditorControl(editorCtl, listItem, ctl); editorCtl.Populate(data); AddToScriptParameterControlMap(script, ctl.Attribute, editorCtl); } } }
private IElementEditorControl GetScriptParameterControl(IEditableScript script, string parameter) { return m_scriptParameterControlMap[script][parameter]; }
private void AddToScriptParameterControlMap(IEditableScript script, string parameter, IElementEditorControl control) { if (parameter == null) return; if (!m_scriptParameterControlMap.ContainsKey(script)) { m_scriptParameterControlMap.Add(script, new Dictionary<string, IElementEditorControl>()); } m_scriptParameterControlMap[script].Add(parameter, control); }
private void AddScriptControls(ListBoxItem listItem, Grid parentGrid, IEditableScript script) { IEditorDefinition definition = m_controller.GetEditorDefinition(script); IEditorData data = m_controller.GetScriptEditorData(script); data.ReadOnly = m_readOnly; Grid grid = NewScriptControlGrid(parentGrid); foreach (IEditorControl ctl in definition.Controls) { bool isFullWidthControl = false; string controlType = ctl.ControlType; if (ctl.ControlType == "script") { controlType = "scriptexpander"; isFullWidthControl = true; } if (ctl.ControlType == "scriptdictionary" || ctl.ControlType == "list") { isFullWidthControl = true; } Control newControl = ControlFactory.CreateEditorControl(m_controller, controlType); newControl.VerticalAlignment = VerticalAlignment.Top; if (newControl is LabelControl) { newControl.Padding = new Thickness(3, 6, 3, 3); } else { newControl.Padding = new Thickness(3); } if (isFullWidthControl) { newControl.HorizontalAlignment = HorizontalAlignment.Stretch; } if (ctl.GetBool("breakbefore")) { // Create a "line break" by putting this and subsequent controls in a new horizontal grid, // underneath the previous one. We're using a grid instead of a StackPanel as script expanders // won't take the full width of the list otherwise. grid = NewScriptControlGrid(parentGrid); // Indent the new line newControl.Padding = new Thickness(newControl.Padding.Left + 20, newControl.Padding.Top, newControl.Padding.Right, newControl.Padding.Bottom); } grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, isFullWidthControl ? GridUnitType.Star : GridUnitType.Auto) }); Grid.SetColumn(newControl, grid.ColumnDefinitions.Count - 1); grid.Children.Add(newControl); IElementEditorControl editorCtl = newControl as IElementEditorControl; if (editorCtl != null) { AddEditorControl(editorCtl, listItem, ctl); editorCtl.Populate(data); AddToScriptParameterControlMap(script, ctl.Attribute, editorCtl); } } }
private void AddScript(IEditableScript script) { ListBoxItem newItem = new ListBoxItem(); newItem.HorizontalAlignment = HorizontalAlignment.Stretch; // a DockPanel is used as the ItemsPanel, so that when nested Expanders are collapsed, // they don't leave a blank space DockPanel.SetDock(newItem, Dock.Top); lstScripts.Items.Add(newItem); if (script.Type != ScriptType.If) { Grid parentGrid = new Grid(); parentGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); parentGrid.HorizontalAlignment = HorizontalAlignment.Stretch; newItem.Content = parentGrid; AddScriptControls(newItem, parentGrid, script); } else { IfEditor newIfEditor = new IfEditor(); newIfEditor.Padding = new Thickness(3); newIfEditor.HorizontalAlignment = HorizontalAlignment.Stretch; AddEditorControl(newIfEditor, newItem, null); newItem.Content = newIfEditor; newIfEditor.ReadOnly = m_readOnly; newIfEditor.Populate((EditableIfScript)script); // Ensure the expression responds to updates e.g. from undo/redo. The nested scripts will take // care of themselves. // TO DO: This isn't particularly efficient, as when m_scripts_Updated is triggered it repopulates // the entire "if" script when an if/elseif expression changes. It should only need to update the // changed expression. AddToScriptParameterControlMap(script, "0", newIfEditor); } }
internal EditableScriptsUpdatedEventArgs(IEditableScript updatedScript, EditableScriptUpdatedEventArgs args) { UpdatedScript = updatedScript; UpdatedScriptEventArgs = args; }
internal EditableScriptsUpdatedEventArgs(IEditableScript updatedScript, EditableScriptUpdatedEventArgs args) { UpdatedScript = updatedScript; UpdatedScriptEventArgs = args; }