Example #1
0
        public void Initialise(EditorController controller, IEditorDefinition definition)
        {
            m_controller = controller;

            foreach (IEditorTab tabDefinition in definition.Tabs.Values)
            {
                InitialiseTab(tabDefinition);
            }
        }
Example #2
0
        public void Initialise(EditorController controller, IEditorDefinition definition)
        {
            m_controller = controller;

            foreach (IEditorTab tabDefinition in definition.Tabs.Values)
            {
                InitialiseTab(tabDefinition);
            }
        }
Example #3
0
        private void PopulateTemplate(string expression)
        {
            if (m_templateEditor == null)
            {
                m_templateEditor              = new ExpressionTemplate();
                m_templateEditor.Controller   = m_helper.Controller;
                m_templateEditor.Dirty       += m_templateEditor_Dirty;
                m_templateEditor.RequestSave += m_templateEditor_RequestSave;
                m_templateEditor.ExpressionTypeTemplateFilter = ExpressionTypeTemplateFilter;
                Grid.SetRow(m_templateEditor, Grid.GetRow(txtExpression));
                Grid.SetColumn(m_templateEditor, Grid.GetColumn(txtExpression));
                grid.Children.Add(m_templateEditor);
            }

            IEditorDefinition definition = m_helper.Controller.GetExpressionEditorDefinition(expression, ExpressionTypeTemplateFilter);

            m_updatingList   = true;
            lstTemplate.Text = m_helper.Controller.GetExpressionEditorDefinitionName(expression, ExpressionTypeTemplateFilter);
            m_updatingList   = false;

            m_templateEditor.Initialise(definition, expression, m_data);
        }
Example #4
0
        public void Initialise(IEditorDefinition definition, string expression, IEditorData parentData)
        {
            foreach (IElementEditorControl ctl in m_controls)
            {
                ctl.Helper.Dirty -= SubControl_Dirty;
            }

            m_controls.Clear();
            stackPanel.Children.Clear();

            if (m_data != null)
            {
                m_data.Changed -= m_data_Changed;
            }

            m_data = Controller.GetExpressionEditorData(expression, ExpressionTypeTemplateFilter, parentData);
            m_data.Changed += m_data_Changed;

            foreach (IEditorControl ctl in definition.Controls)
            {
                AddControl(ctl, expression);
            }
        }
        public void Initialise(IEditorDefinition definition, string expression, IEditorData parentData)
        {
            foreach (IElementEditorControl ctl in m_controls)
            {
                ctl.Helper.Dirty -= SubControl_Dirty;
            }

            m_controls.Clear();
            stackPanel.Children.Clear();

            if (m_data != null)
            {
                m_data.Changed -= m_data_Changed;
            }

            m_data          = Controller.GetExpressionEditorData(expression, ExpressionTypeTemplateFilter, parentData);
            m_data.Changed += m_data_Changed;

            foreach (IEditorControl ctl in definition.Controls)
            {
                AddControl(ctl, expression);
            }
        }
Example #6
0
        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);
                }
            }
        }
Example #7
0
        private object GetScriptParameterValue(ElementSaveData.ScriptSaveData scriptLine, EditorController controller, IValueProvider provider, string attributePrefix, string controlType, string simpleEditor, string templatesFilter, string oldValue, string ignoreExpression)
        {
            if (attributePrefix == ignoreExpression)
            {
                return(new IgnoredValue());
            }

            if (controlType == "expression")
            {
                if (templatesFilter == null)
                {
                    string dropdownKey = string.Format("{0}-expressioneditordropdown", attributePrefix);
                    ValueProviderResult dropdownKeyValueResult = provider.GetValue(dropdownKey);
                    string dropdownKeyValue = (dropdownKeyValueResult != null) ? dropdownKeyValueResult.ConvertTo(typeof(string)) as string : null;
                    if (dropdownKeyValue == "expression" || dropdownKeyValue == null)
                    {
                        string key = string.Format("{0}-expressioneditor", attributePrefix);
                        return(GetAndValidateValueProviderString(provider, key, oldValue, scriptLine, controller));
                    }
                    else
                    {
                        if (simpleEditor == "boolean")
                        {
                            return(dropdownKeyValue == "yes" ? "true" : "false");
                        }
                        else
                        {
                            string key         = string.Format("{0}-simpleeditor", attributePrefix);
                            string simpleValue = GetValueProviderString(provider, key);
                            if (simpleValue == null)
                            {
                                return(string.Empty);
                            }

                            switch (simpleEditor)
                            {
                            case "objects":
                            case "number":
                            case "numberdouble":
                                return(simpleValue);

                            default:
                                return(EditorUtility.ConvertFromSimpleStringExpression(simpleValue));
                            }
                        }
                    }
                }
                else
                {
                    string dropdownKey      = string.Format("{0}-templatedropdown", attributePrefix);
                    string dropdownKeyValue = provider.GetValue(dropdownKey).ConvertTo(typeof(string)) as string;
                    if (dropdownKeyValue == "expression")
                    {
                        string key = attributePrefix;
                        return(GetAndValidateValueProviderString(provider, key, oldValue, scriptLine, controller));
                    }
                    else
                    {
                        IEditorDefinition editorDefinition = controller.GetExpressionEditorDefinition(oldValue, templatesFilter);
                        IEditorData       data             = controller.GetExpressionEditorData(oldValue, templatesFilter, null);

                        foreach (IEditorControl ctl in editorDefinition.Controls.Where(c => c.Attribute != null))
                        {
                            string key   = attributePrefix + "-" + ctl.Attribute;
                            object value = GetScriptParameterValue(scriptLine, controller, provider, key, ctl.ControlType, ctl.GetString("simpleeditor") ?? "textbox", null, null, ignoreExpression);
                            data.SetAttribute(ctl.Attribute, value);
                        }

                        return(controller.GetExpression(data, null, null));
                    }
                }
            }
            else
            {
                string key = attributePrefix;
                return(GetValueProviderString(provider, key));
            }
        }
Example #8
0
        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++;
            }
        }