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); } }
private void AddEditorControl(IElementEditorControl control, ListBoxItem listItem, IEditorControl ctl) { m_subControls.Add(control); ((Control)control).Tag = listItem; ((Control)control).GotFocus += SubControl_GotFocus; control.Helper.Dirty += SubControl_Dirty; control.Helper.RequestParentElementEditorSave += SubControl_RequestParentElementEditorSave; control.Helper.DoInitialise(m_controller, ctl); }
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(); }
public static Control CreateEditorControl(EditorController controller, string controlType) { Type newControlType = controller.GetControlType(controlType); if (newControlType == null) { Label tempLabel = new Label(); tempLabel.Content = controlType + " not implemented"; return(tempLabel); } IElementEditorControl newControl = (IElementEditorControl)Activator.CreateInstance(newControlType); return((Control)newControl); }
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(); } } } }
private Control InitialiseEditorControl(IEditorControl ctl) { Control newControl = ControlFactory.CreateEditorControl(m_controller, ctl.ControlType); IElementEditorControl newElementEditorControl = newControl as IElementEditorControl; if (newElementEditorControl != null) { m_controls.Add(newElementEditorControl); newElementEditorControl.Helper.Dirty += Control_Dirty; newElementEditorControl.Helper.RequestParentElementEditorSave += Control_RequestParentElementEditorSave; newElementEditorControl.Helper.DoInitialise(m_controller, ctl); } return((Control)newControl); }
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 void Uninitialise() { foreach (List <UIElement> ctlList in m_controlUIElements.Values) { foreach (UIElement element in ctlList) { IElementEditorControl elementEditor = element as IElementEditorControl; if (elementEditor != null) { elementEditor.Helper.Dirty -= Control_Dirty; elementEditor.Helper.RequestParentElementEditorSave -= Control_RequestParentElementEditorSave; elementEditor.Helper.DoUninitialise(); } Grid grid = element as Grid; if (grid != null) { grid.Children.Clear(); } IDisposable disposableElement = element as IDisposable; } ctlList.Clear(); } m_controlUIElements.Clear(); foreach (TabItem tab in m_tabs.Values) { tab.Content = null; } tabControl.Items.Clear(); m_tabs.Clear(); m_controls.Clear(); m_controller = null; }
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" || 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 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 AddControlToGrid(Grid grid, IEditorControl ctl) { m_controlUIElements.Add(ctl, new List <UIElement>()); // Add row int currentRow = AddRowToGrid(grid, ctl.Expand); bool controlDisplaysOwnCaption = false; bool resizableRow = false; bool scrollableControl = false; Control newControl = InitialiseEditorControl(ctl); m_controlUIElements[ctl].Add(newControl); newControl.Padding = new Thickness(6); if (ctl.ControlType == "title") { m_titleControls.Add(newControl); } IElementEditorControl elementEditorControl = newControl as IElementEditorControl; if (elementEditorControl != null) { controlDisplaysOwnCaption = elementEditorControl.Helper.Options.DisplaysOwnCaption; resizableRow = elementEditorControl.Helper.Options.Resizable; scrollableControl = elementEditorControl.Helper.Options.Scrollable; } if (!controlDisplaysOwnCaption && !string.IsNullOrEmpty(ctl.Caption)) { Label newLabel = new Label(); m_controlUIElements[ctl].Add(newLabel); newLabel.Content = ctl.Caption + ":"; newLabel.Target = newControl; if (ctl.Caption.Length > 17) { newLabel.Padding = new Thickness(5, 5, 5, 0); newControl.Padding = new Thickness(5, 3, 5, 5); // Create StackPanel, label at top and control underneath Grid subGrid = new Grid(); AddRowToGrid(subGrid, false); AddRowToGrid(subGrid, ctl.Expand || resizableRow); m_controlUIElements[ctl].Add(subGrid); // Add label and new control to subgrid Grid.SetRow(newLabel, 0); Grid.SetRow(newControl, 1); subGrid.Children.Add(newLabel); subGrid.Children.Add(newControl); // Add subgrid to parent editor grid Grid.SetColumn(subGrid, 0); Grid.SetRow(subGrid, currentRow); Grid.SetColumnSpan(subGrid, 2); grid.Children.Add(subGrid); } else { newLabel.Padding = new Thickness(5, 7, 5, 5); // Add label to first column Grid.SetColumn(newLabel, 0); Grid.SetRow(newLabel, currentRow); grid.Children.Add(newLabel); // Add control to second column Grid.SetColumn(newControl, 1); Grid.SetRow(newControl, currentRow); grid.Children.Add(newControl); } } else { // Add control to grid row, colspan=2 Grid.SetColumn(newControl, 0); Grid.SetRow(newControl, currentRow); Grid.SetColumnSpan(newControl, 2); grid.Children.Add(newControl); } if (resizableRow) { // TO DO: Enforce minimum height for resizable rows int gridRow = AddRowToGrid(grid); GridSplitter splitter = new GridSplitter(); splitter.Height = 3; splitter.HorizontalAlignment = HorizontalAlignment.Stretch; splitter.VerticalAlignment = VerticalAlignment.Center; Grid.SetColumnSpan(splitter, 2); Grid.SetRow(splitter, gridRow); grid.Children.Add(splitter); m_controlUIElements[ctl].Add(splitter); } m_lastRowIsResizable = resizableRow; m_lastRowIsScrollableAndExpands = scrollableControl && ctl.Expand; }
internal ControlDataHelper(IElementEditorControl parent) { m_parent = parent; ExpectedType = typeof(T); }