private void AddControl(IEditorControl ctl, string expression) { Control newControl = ControlFactory.CreateEditorControl(Controller, ctl.ControlType); stackPanel.Children.Add(newControl); newControl.VerticalAlignment = VerticalAlignment.Top; if (newControl is LabelControl) { newControl.Padding = new Thickness(3, 3, 3, 0); } else { newControl.Padding = new Thickness(3, 0, 3, 0); } IElementEditorControl elementEditor = newControl as IElementEditorControl; if (elementEditor != null) { elementEditor.Helper.DoInitialise(Controller, ctl); elementEditor.Populate(m_data); elementEditor.Helper.Dirty += SubControl_Dirty; elementEditor.Helper.RequestParentElementEditorSave += SubControl_RequestParentElementEditorSave; m_controls.Add(elementEditor); } }
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(); }
private void HideOtherEditors() { foreach (Control ctl in m_loadedEditors.Values) { if (ctl != CurrentEditor) { ctl.Visibility = Visibility.Collapsed; IElementEditorControl editorCtl = ctl as IElementEditorControl; if (editorCtl != null) { editorCtl.Populate(null); editorCtl.Helper.DoUninitialise(); } } } }
internal void Save(T newValue) { if (m_populating) { return; } if (!m_dirty) { return; } if (m_saving) { return; } m_saving = true; // When we call m_data.SetAttribute below, that can trigger off a whole chain of events which may // cause us to be Unpopulated before we finish the function. We'll still need to finish the transaction, // so we make copies first. bool directlySaveable = m_data.IsDirectlySaveable; EditorController controller = Controller; string caption = ControlDefinition.Caption; if (directlySaveable) { controller.StartTransaction(string.Format("Set {0} to '{1}'", ControlDefinition.Caption, newValue == null ? "null" : newValue.ToString())); } ValidationResult result = m_data.SetAttribute(ControlDefinition.Attribute, newValue); if (!result.Valid) { string errorValue = newValue as string; PopupEditors.DisplayValidationError(result, errorValue, string.Format("Unable to set '{0}'", caption)); } if (directlySaveable) { controller.EndTransaction(); } m_saving = false; // Repopulating ensures we see the currently set value, and that dirty=false m_parent.Populate(m_data); }
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); } } }