private void RemoveElseIfChildControl(EditableIfScript.EditableElseIf elseIfData) { RemoveElseIfEditor(m_elseIfEditors[elseIfData.Id]); m_elseIfEditors.Remove(elseIfData.Id); }
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); }
void RemovedElseIf(object sender, EditableIfScript.ElseIfEventArgs e) { RemoveElseIfChildControl(e.Script); }
void AddedElseIf(object sender, EditableIfScript.ElseIfEventArgs e) { AddElseIfChildControl(e.Script); }
public void Populate(EditableIfScript data) { if (m_data != null) { m_data.AddedElse -= AddedElse; m_data.AddedElseIf -= AddedElseIf; m_data.RemovedElse -= RemovedElse; m_data.RemovedElseIf -= RemovedElseIf; } m_data = data; if (data != null) { data.AddedElse += AddedElse; data.AddedElseIf += AddedElseIf; data.RemovedElse += RemovedElse; data.RemovedElseIf += RemovedElseIf; } // remove all existing "else if" and "else" child controls RemoveElseChildControl(); RemoveAllElseIfChildControls(); // The expression is contained in the "expression" attribute of the data IEditorData ctlChild.ReadOnly = m_readOnly; ctlChild.Populate(data, data == null ? null : data.ThenScript); if (data != null) { // add else if controls foreach (var elseIfScript in data.ElseIfScripts) { AddElseIfChildControl(elseIfScript); } // add else control if (data.ElseScript != null) { AddElseChildControl(); } } if (m_readOnly) { cmdAddElse.Visibility = Visibility.Collapsed; cmdAddElseIf.Visibility = Visibility.Collapsed; } }
public void Populate(EditableIfScript data) { if (data == m_data) { // If repopulating with the same editable "if" script, we only // need to refresh the conditions, not the "Then", "Else" scripts etc. ctlChild.RefreshExpression(data); foreach (var elseIf in data.ElseIfScripts) { m_elseIfEditors[elseIf.Id].RefreshExpression(elseIf); } return; } if (m_data != null) { m_data.AddedElse -= AddedElse; m_data.AddedElseIf -= AddedElseIf; m_data.RemovedElse -= RemovedElse; m_data.RemovedElseIf -= RemovedElseIf; } m_data = data; if (data != null) { data.AddedElse += AddedElse; data.AddedElseIf += AddedElseIf; data.RemovedElse += RemovedElse; data.RemovedElseIf += RemovedElseIf; } // remove all existing "else if" and "else" child controls RemoveElseChildControl(); RemoveAllElseIfChildControls(); // The expression is contained in the "expression" attribute of the data IEditorData ctlChild.ReadOnly = m_readOnly; ctlChild.Populate(data, data == null ? null : data.ThenScript); if (data != null) { // add else if controls foreach (var elseIfScript in data.ElseIfScripts) { AddElseIfChildControl(elseIfScript); } // add else control if (data.ElseScript != null) { AddElseChildControl(); } } if (m_readOnly) { cmdAddElse.Visibility = Visibility.Collapsed; cmdAddElseIf.Visibility = Visibility.Collapsed; } }
private void BindScriptLines(IValueProvider provider, string attribute, EditorController controller, IEditableScripts originalScript, ElementSaveData.ScriptsSaveData result, string ignoreExpression) { if (originalScript == null) { return; } int count = 0; foreach (IEditableScript script in originalScript.Scripts) { ElementSaveData.ScriptSaveData scriptLine = new ElementSaveData.ScriptSaveData(); scriptLine.IsSelected = (bool)provider.GetValue(string.Format("selected-{0}-{1}", attribute, count)).ConvertTo(typeof(bool)); if (script.Type != ScriptType.If) { IEditorDefinition definition = controller.GetEditorDefinition(script); foreach (IEditorControl ctl in definition.Controls.Where(c => c.Attribute != null)) { string key = string.Format("{0}-{1}-{2}", attribute, count, ctl.Attribute); if (ctl.ControlType == "script") { IEditorData scriptEditorData = controller.GetScriptEditorData(script); IEditableScripts originalSubScript = (IEditableScripts)scriptEditorData.GetAttribute(ctl.Attribute); ElementSaveData.ScriptsSaveData scriptResult = new ElementSaveData.ScriptsSaveData(); BindScriptLines(provider, key, controller, originalSubScript, scriptResult, ignoreExpression); scriptLine.Attributes.Add(ctl.Attribute, scriptResult); } else if (ctl.ControlType == "scriptdictionary") { IEditorData dictionaryData = controller.GetScriptEditorData(script); IEditableDictionary <IEditableScripts> dictionary = (IEditableDictionary <IEditableScripts>)dictionaryData.GetAttribute(ctl.Attribute); ElementSaveData.ScriptSaveData switchResult = BindScriptDictionary(provider, controller, ignoreExpression, dictionary, key); scriptLine.Attributes.Add(ctl.Attribute, switchResult); } else if (ctl.ControlType == "list") { // do nothing } else { object value = GetScriptParameterValue( scriptLine, controller, provider, key, ctl.ControlType, ctl.GetString("simpleeditor") ?? "textbox", ctl.GetString("usetemplates"), (string)script.GetParameter(ctl.Attribute), ignoreExpression ); scriptLine.Attributes.Add(ctl.Attribute, value); } } } else { EditableIfScript ifScript = (EditableIfScript)script; object expressionValue = GetScriptParameterValue( scriptLine, controller, provider, string.Format("{0}-{1}-expression", attribute, count), "expression", null, "if", (string)ifScript.GetAttribute("expression"), ignoreExpression ); scriptLine.Attributes.Add("expression", expressionValue); ElementSaveData.ScriptsSaveData thenScriptResult = new ElementSaveData.ScriptsSaveData(); BindScriptLines(provider, string.Format("{0}-{1}-then", attribute, count), controller, ifScript.ThenScript, thenScriptResult, ignoreExpression); scriptLine.Attributes.Add("then", thenScriptResult); int elseIfCount = 0; foreach (EditableIfScript.EditableElseIf elseIf in ifScript.ElseIfScripts) { object elseIfExpressionValue = GetScriptParameterValue( scriptLine, controller, provider, string.Format("{0}-{1}-elseif{2}-expression", attribute, count, elseIfCount), "expression", null, "if", elseIf.Expression, ignoreExpression ); scriptLine.Attributes.Add(string.Format("elseif{0}-expression", elseIfCount), elseIfExpressionValue); ElementSaveData.ScriptsSaveData elseIfScriptResult = new ElementSaveData.ScriptsSaveData(); BindScriptLines(provider, string.Format("{0}-{1}-elseif{2}", attribute, count, elseIfCount), controller, elseIf.EditableScripts, elseIfScriptResult, ignoreExpression); scriptLine.Attributes.Add(string.Format("elseif{0}-then", elseIfCount), elseIfScriptResult); elseIfCount++; } if (ifScript.ElseScript != null) { ElementSaveData.ScriptsSaveData elseScriptResult = new ElementSaveData.ScriptsSaveData(); BindScriptLines(provider, string.Format("{0}-{1}-else", attribute, count), controller, ifScript.ElseScript, elseScriptResult, ignoreExpression); scriptLine.Attributes.Add("else", elseScriptResult); } } result.ScriptLines.Add(scriptLine); count++; } }