internal EditableIfScript(EditorController controller, IIfScript script, UndoLogger undoLogger) : base(controller, script, undoLogger) { m_ifScript = script; m_ifScript.IfScriptUpdated += m_ifScript_IfScriptUpdated; if (m_ifScript.ThenScript == null) { m_ifScript.ThenScript = new MultiScript(Controller.WorldModel); } m_thenScript = EditableScripts.GetInstance(Controller, m_ifScript.ThenScript); m_thenScript.Updated += nestedScript_Updated; foreach (var elseIfScript in m_ifScript.ElseIfScripts) { EditableElseIf newEditableElseIf = new EditableElseIf(elseIfScript, this); m_elseIfScripts.Add(elseIfScript.Script, newEditableElseIf); newEditableElseIf.EditableScripts.Updated += nestedScript_Updated; } if (m_ifScript.ElseScript != null) { m_elseScript = EditableScripts.GetInstance(Controller, m_ifScript.ElseScript); m_elseScript.Updated += nestedScript_Updated; } }
void m_ifScript_IfScriptUpdated(object sender, IfScriptUpdatedEventArgs e) { switch (e.EventType) { case IfScriptUpdatedEventArgs.IfScriptUpdatedEventType.AddedElse: m_elseScript = EditableScripts.GetInstance(Controller, m_ifScript.ElseScript); m_elseScript.Updated += nestedScript_Updated; if (AddedElse != null) { AddedElse(this, new EventArgs()); } break; case IfScriptUpdatedEventArgs.IfScriptUpdatedEventType.RemovedElse: m_elseScript.Updated -= nestedScript_Updated; m_elseScript = null; if (RemovedElse != null) { RemovedElse(this, new EventArgs()); } break; case IfScriptUpdatedEventArgs.IfScriptUpdatedEventType.AddedElseIf: EditableScripts editableNewScript = EditableScripts.GetInstance(Controller, e.Data.Script); editableNewScript.Updated += nestedScript_Updated; // Wrap the newly created elseif in an EditableElseIf and add it to our internal dictionary EditableElseIf newEditableElseIf = new EditableElseIf(e.Data, this); m_elseIfScripts.Add(e.Data.Script, newEditableElseIf); // Raise the update to display in the UI if (AddedElseIf != null) { AddedElseIf(this, new ElseIfEventArgs(newEditableElseIf)); } break; case IfScriptUpdatedEventArgs.IfScriptUpdatedEventType.RemovedElseIf: EditableScripts.GetInstance(Controller, e.Data.Script).Updated -= nestedScript_Updated; if (RemovedElseIf != null) { RemovedElseIf(this, new ElseIfEventArgs(m_elseIfScripts[e.Data.Script])); } m_elseIfScripts.Remove(e.Data.Script); break; default: throw new Exception("Unhandled event"); } RaiseUpdated(new EditableScriptUpdatedEventArgs(DisplayString())); }
public override string DisplayString(int index, object newValue) { // This version of DisplayString is used while we are editing an attribute value // as we don't want to save updates for every keypress if (string.IsNullOrEmpty(m_displayTemplate)) { return((Script == null) ? null : Script.Save()); } string result = m_displayTemplate; int startAt = 1; while (startAt < result.Length && s_regex.IsMatch(result, startAt)) { Match m = s_regex.Match(result); int attributeNum = int.Parse(m.Groups["attribute"].Value); string attributeValue; object value; if (attributeNum == index) { value = newValue; } else { value = GetParameter(attributeNum.ToString()); } if (value is IDataWrapper) { value = ((IDataWrapper)value).GetUnderlyingValue(); } IScript scriptValue = value as IScript; string stringValue = value as string; ICollection collectionValue = value as ICollection; if (stringValue != null) { attributeValue = (stringValue.Length == 0) ? "?" : stringValue; } else if (scriptValue != null) { EditableScripts editableScripts = EditableScripts.GetInstance(Controller, scriptValue); RegisterNestedScriptForUpdates(editableScripts); attributeValue = (editableScripts.Count == 0) ? "(nothing)" : editableScripts.DisplayString(); } else if (collectionValue != null) { attributeValue = collectionValue.Count.ToString(); } else if (value == null) { attributeValue = "(nothing)"; } else { System.Diagnostics.Debug.Assert(false, "Unknown attribute type for DisplayString"); attributeValue = "<unknown>"; } result = s_regex.Replace(result, attributeValue, 1, startAt); startAt = m.Groups["attribute"].Index + attributeValue.Length; } return(result); }