Example #1
0
        public void Populate(IEditableScripts script)
        {
            if (m_scripts != null)
            {
                m_scripts.Updated -= m_scripts_Updated;
            }
            m_scripts = script;
            if (m_scripts != null)
            {
                m_scripts.Updated += m_scripts_Updated;
            }

            bool fromInheritedType = IsScriptFromInheritedType();

            if (fromInheritedType)
            {
                m_readOnly = true;
            }
            ctlToolbar.CanMakeEditable = fromInheritedType;

            textEditor.IsReadOnly = m_readOnly;

            m_populating = true;
            CodeView     = false;
            m_populating = false;

            RefreshScriptsList();
        }
Example #2
0
        // Note there are two "Populate" methods, so EITHER m_script OR m_data will be set.

        public void Populate(IEditorData data, IEditableScripts script)
        {
            m_script = script;
            if (script == null)
            {
                ctlScript.Populate(script);
            }
            else if (ctlExpander.IsExpanded)
            {
                PopulateScript();
            }
        }
Example #3
0
        // Note there are two "Populate" methods, so EITHER m_script OR m_data will be set.

        public void Populate(IEditorData data, IEditableScripts script)
        {
            m_script = script;
            if (script == null)
            {
                ctlScript.Populate(script);
            }
            else if (ctlExpander.IsExpanded)
            {
                PopulateScript();
            }
        }
Example #4
0
        public void Populate(IEditorData data, IEditableScripts script)
        {
            if (data != null)
            {
                data.ReadOnly = m_readOnly;
            }
            ctlExpression.Populate(data);

            ctlScriptExpander.ReadOnly = m_readOnly;
            ctlScriptExpander.Populate(data, script);

            cmdDelete.IsEnabled = !m_readOnly;
        }
Example #5
0
        public static void EditScript(EditorController controller, ref IEditableScripts scripts, string attribute, string element, bool isReadOnly, Action dirtyAction)
        {
            ScriptEditorPopOut popOut = new ScriptEditorPopOut();

            popOut.ctlScriptEditor.HidePopOutButton();
            popOut.ctlScriptEditor.Helper.DoInitialise(controller, null);
            popOut.ctlScriptEditor.Populate(scripts);
            popOut.ctlScriptEditor.Helper.Dirty += (object sender, DataModifiedEventArgs e) => dirtyAction.Invoke();

            popOut.ShowDialog();
            scripts = popOut.ctlScriptEditor.Scripts;
            popOut.ctlScriptEditor.Save();
        }
Example #6
0
        public void Populate(IEditorData data, IEditableScripts script)
        {
            if (data != null)
            {
                data.ReadOnly = m_readOnly;
            }
            ctlExpression.Populate(data);

            ctlScriptExpander.ReadOnly = m_readOnly;
            ctlScriptExpander.Populate(data, script);

            cmdDelete.IsEnabled = !m_readOnly;
        }
Example #7
0
        void ctlToolbar_Paste()
        {
            if (m_readOnly)
            {
                return;
            }
            if (CodeView)
            {
                textEditor.Paste();
            }
            else
            {
                int index;
                if (lstScripts.SelectedIndex < 0)
                {
                    index = lstScripts.Items.Count;
                }
                else
                {
                    index = lstScripts.SelectedIndex + 1;
                }

                Save();

                if (m_scripts == null)
                {
                    m_controller.StartTransaction("Paste script");

                    if (m_parentScript != null)
                    {
                        m_scripts = m_controller.CreateNewEditableScriptsChild(m_parentScript, m_helper.ControlDefinition.Attribute, null, false);
                    }
                    else
                    {
                        m_scripts = m_controller.CreateNewEditableScripts(ElementName, m_helper.ControlDefinition.Attribute, null, false);
                    }

                    m_scripts.Paste(index, false);
                    m_controller.EndTransaction();
                    RefreshScriptsList();
                }
                else
                {
                    m_scripts.Paste(index, true);
                }
                Save();
                SetSelectedIndex(index);
            }
        }
Example #8
0
        private object BindScript(IValueProvider provider, string attribute, IEditorData data, EditorController controller, string ignoreExpression)
        {
            IEditableScripts originalScript = (IEditableScripts)data.GetAttribute(attribute);

            if (originalScript == null)
            {
                return(null);
            }

            ElementSaveData.ScriptsSaveData result = new ElementSaveData.ScriptsSaveData();

            BindScriptLines(provider, attribute, controller, originalScript, result, ignoreExpression);

            return(result);
        }
Example #9
0
        private void PrepareForEditing()
        {
            // If we're currently displaying script which belongs to a type we inherit from,
            // we must clone the script before we can edit it.

            if (!IsScriptFromInheritedType())
            {
                return;
            }

            m_controller.StartTransaction(string.Format("Copy {0} script to {1}", m_helper.ControlDefinition.Attribute, m_data.Name));
            m_scripts = m_scripts.Clone(m_data.Name, m_helper.ControlDefinition.Attribute);
            m_controller.EndTransaction();
            RefreshScriptsList();
        }
Example #10
0
        public string DisplayString(IEditableScripts modifiedSection, int index, string newValue)
        {
            // If we've updated the "then" script, then we need to get an updated "then" script where attribute "index" has been updated to "newValue"
            string result = (modifiedSection == ThenScript) ? ThenDisplayStringFragment(index, newValue) : ThenDisplayStringFragment(-1, string.Empty);

            foreach (EditableElseIf elseIf in m_elseIfScripts.Values)
            {
                result += (modifiedSection == elseIf.EditableScripts) ? ElseIfDisplayStringFragment(elseIf, index, newValue) : ElseIfDisplayStringFragment(elseIf, -1, string.Empty);
            }

            if (ElseScript != null)
            {
                result += (modifiedSection == ElseScript) ? ElseDisplayStringFragment(index, newValue) : ElseDisplayStringFragment(-1, string.Empty);
            }
            return(result);
        }
Example #11
0
        public static void EditScript(EditorController controller, ref IEditableScripts scripts, string attribute, string element, bool isReadOnly, Action dirtyAction)
        {
            ScriptEditorPopOut popOut = new ScriptEditorPopOut();

            popOut.ctlScriptEditor.HidePopOutButton();
            popOut.ctlScriptEditor.Helper.DoInitialise(controller, null);
            popOut.ctlScriptEditor.Populate(scripts);
            System.EventHandler <DataModifiedEventArgs> dirtyEventHandler = (object sender, DataModifiedEventArgs e) => dirtyAction.Invoke();
            popOut.ctlScriptEditor.Helper.Dirty += dirtyEventHandler;

            popOut.ShowDialog();
            scripts = popOut.ctlScriptEditor.Scripts;
            popOut.ctlScriptEditor.Save();
            popOut.ctlScriptEditor.Populate((IEditableScripts)null);
            popOut.ctlScriptEditor.Helper.DoUninitialise();
            popOut.ctlScriptEditor.Helper.Dirty -= dirtyEventHandler;
        }
Example #12
0
        private string GetDisplayString(object value)
        {
            IEditableScripts                       scriptValue           = value as IEditableScripts;
            IEditableList <string>                 listStringValue       = value as IEditableList <string>;
            IEditableDictionary <string>           dictionaryStringValue = value as IEditableDictionary <string>;
            IEditableDictionary <IEditableScripts> dictionaryScriptValue = value as IEditableDictionary <IEditableScripts>;
            IDataWrapper wrappedValue = value as IDataWrapper;
            string       result       = null;

            if (scriptValue != null)
            {
                result = scriptValue.DisplayString();
            }
            else if (listStringValue != null)
            {
                result = GetListDisplayString(listStringValue.DisplayItems);
            }
            else if (dictionaryStringValue != null)
            {
                result = GetDictionaryDisplayString(dictionaryStringValue.DisplayItems);
            }
            else if (dictionaryScriptValue != null)
            {
                result = GetDictionaryDisplayString(dictionaryScriptValue.DisplayItems);
            }
            else if (wrappedValue != null)
            {
                result = wrappedValue.DisplayString();
            }
            else if (value == null)
            {
                result = "(null)";
            }
            else
            {
                result = value.ToString();
            }

            return(EditorUtility.FormatAsOneLine(result));
        }
Example #13
0
        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();
                }
            }
        }
Example #14
0
        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();
                }
            }
        }
Example #15
0
        public void Populate(IEditableScripts script)
        {
            if (m_scripts != null)
            {
                m_scripts.Updated -= m_scripts_Updated;
            }
            m_scripts = script;
            if (m_scripts != null)
            {
                m_scripts.Updated += m_scripts_Updated;
            }

            bool fromInheritedType = IsScriptFromInheritedType();
            if (fromInheritedType) m_readOnly = true;
            ctlToolbar.CanMakeEditable = fromInheritedType;

            textEditor.IsReadOnly = m_readOnly;

            m_populating = true;
            CodeView = false;
            m_populating = false;

            RefreshScriptsList();
        }
Example #16
0
        private void PrepareForEditing()
        {
            // If we're currently displaying script which belongs to a type we inherit from,
            // we must clone the script before we can edit it.

            if (!IsScriptFromInheritedType()) return;

            m_controller.StartTransaction(string.Format("Copy {0} script to {1}", m_helper.ControlDefinition.Attribute, m_data.Name));
            m_scripts = m_scripts.Clone(m_data.Name, m_helper.ControlDefinition.Attribute);
            m_controller.EndTransaction();
            RefreshScriptsList();
        }
Example #17
0
 public PartialViewResult EditScriptValue(int id, string key, IEditableScripts script, string attribute)
 {
     return PartialView("ScriptEditor", EditorDictionary[id].GetScriptModel(id, key, script, attribute, ModelState));
 }
Example #18
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++;
            }
        }
Example #19
0
        public IEditableDictionary<IEditableScripts> CreateNewEditableScriptDictionary(string parent, string attribute, string key, IEditableScripts script, bool useTransaction)
        {
            if (useTransaction)
            {
                WorldModel.UndoLogger.StartTransaction(string.Format("Set '{0}' {1} to '{2}'", parent, attribute, script.DisplayString()));
            }

            Element element = (parent == null) ? null : m_worldModel.Elements.Get(parent);

            QuestDictionary<IScript> newDictionary = new QuestDictionary<IScript>();

            if (key != null)
            {
                newDictionary.Add(key, (IScript)script.GetUnderlyingValue());
            }

            if (element != null)
            {
                element.Fields.Set(attribute, newDictionary);

                // setting an element field will clone the value, so we want to return the new dictionary
                newDictionary = element.Fields.GetAsType<QuestDictionary<IScript>>(attribute);
            }

            IEditableDictionary<IEditableScripts> newValue = (IEditableDictionary<IEditableScripts>)WrapValue(newDictionary);

            if (useTransaction)
            {
                WorldModel.UndoLogger.EndTransaction();
            }

            return newValue;
        }
Example #20
0
        private void BindControl(ModelBindingContext bindingContext, ElementSaveData result, int gameId, string ignoreExpression, Dictionary <int, Services.EditorService> editorDictionary, Models.Element originalElement, IEditorControl ctl, string controlType, string attribute = null)
        {
            object saveValue            = null;
            bool   addSaveValueToResult = true;

            if (attribute == null)
            {
                attribute = ctl.Attribute;
            }

            // check to see if attribute changes from attribute editor is being passed along
            // if so, use the attribute editor value

            if (bindingContext.ValueProvider.ContainsPrefix("attr_" + attribute))
            {
                attribute = "attr_" + attribute;
            }

            switch (controlType)
            {
            case "textbox":
            case "dropdown":
            case "file":
                saveValue = GetValueProviderString(bindingContext.ValueProvider, attribute);
                break;

            case "number":
                string stringValue = GetValueProviderString(bindingContext.ValueProvider, attribute);
                int    intValue;
                int.TryParse(stringValue, out intValue);
                int?min = ctl.GetInt("minimum");
                int?max = ctl.GetInt("maximum");
                if (min.HasValue && intValue < min)
                {
                    intValue = min.Value;
                }
                if (max.HasValue && intValue > max)
                {
                    intValue = max.Value;
                }
                saveValue = intValue;
                break;

            case "numberdouble":
                string stringDoubleValue = GetValueProviderString(bindingContext.ValueProvider, attribute);
                double doubleValue;
                double.TryParse(stringDoubleValue, System.Globalization.NumberStyles.AllowDecimalPoint | System.Globalization.NumberStyles.AllowLeadingSign, System.Globalization.CultureInfo.InvariantCulture, out doubleValue);
                double?doubleMin = ctl.GetDouble("minimum");
                double?doubleMax = ctl.GetDouble("maximum");
                if (doubleMin.HasValue && doubleValue < doubleMin)
                {
                    doubleValue = doubleMin.Value;
                }
                if (doubleMax.HasValue && doubleValue > doubleMax)
                {
                    doubleValue = doubleMax.Value;
                }
                saveValue = doubleValue;
                break;

            case "richtext":
                // Replace all new line characters with a <Br/> tag here
                string richtextValue = GetValueProviderString(bindingContext.ValueProvider, attribute);
                saveValue = StripHTMLComments(HttpUtility.HtmlDecode(richtextValue.Replace(Environment.NewLine, "<br/>")));
                break;

            case "checkbox":
                ValueProviderResult value = bindingContext.ValueProvider.GetValue(attribute);
                if (value == null)
                {
                    Logging.Log.ErrorFormat("Expected true/false value for '{0}', but got null", attribute);
                    saveValue = false;
                }
                else
                {
                    saveValue = value.ConvertTo(typeof(bool));
                }
                break;

            case "script":
                saveValue = BindScript(bindingContext.ValueProvider, attribute, originalElement.EditorData, editorDictionary[gameId].Controller, ignoreExpression);
                break;

            case "multi":
                string type           = WebEditor.Views.Edit.ControlHelpers.GetTypeName(originalElement.EditorData.GetAttribute(attribute));
                string subControlType = WebEditor.Views.Edit.ControlHelpers.GetEditorNameForType(type, ctl.GetDictionary("editors"));
                BindControl(bindingContext, result, gameId, ignoreExpression, editorDictionary, originalElement, ctl, subControlType);
                addSaveValueToResult = false;
                break;

            case "objects":
                saveValue = new ElementSaveData.ObjectReferenceSaveData
                {
                    Reference = GetValueProviderString(bindingContext.ValueProvider, "dropdown-" + attribute)
                };
                break;

            case "verbs":
                IEditorDataExtendedAttributeInfo extendedData = (IEditorDataExtendedAttributeInfo)originalElement.EditorData;
                foreach (IEditorAttributeData attr in extendedData.GetAttributeData().Where(a => !a.IsInherited))
                {
                    if (editorDictionary[gameId].Controller.IsVerbAttribute(attr.AttributeName))
                    {
                        object           attrValue       = extendedData.GetAttribute(attr.AttributeName);
                        string           attrStringValue = attrValue as string;
                        IEditableScripts attrScriptValue = attrValue as IEditableScripts;
                        IEditableDictionary <IEditableScripts> attrDictionaryValue = attrValue as IEditableDictionary <IEditableScripts>;
                        if (attrStringValue != null)
                        {
                            BindControl(bindingContext, result, gameId, ignoreExpression, editorDictionary, originalElement, ctl, "textbox", attr.AttributeName);
                        }
                        else if (attrScriptValue != null)
                        {
                            BindControl(bindingContext, result, gameId, ignoreExpression, editorDictionary, originalElement, ctl, "script", attr.AttributeName);
                        }
                        else if (attrDictionaryValue != null)
                        {
                            BindControl(bindingContext, result, gameId, ignoreExpression, editorDictionary, originalElement, ctl, "scriptdictionary", attr.AttributeName);
                        }
                    }
                }
                addSaveValueToResult = false;
                break;

            case "list":
                addSaveValueToResult = false;
                break;

            case "pattern":
                saveValue = new ElementSaveData.PatternSaveData
                {
                    Pattern = GetValueProviderString(bindingContext.ValueProvider, attribute)
                };
                break;

            case "scriptdictionary":
                var originalDictionary = originalElement.EditorData.GetAttribute(attribute) as IEditableDictionary <IEditableScripts>;
                saveValue = BindScriptDictionary(bindingContext.ValueProvider, editorDictionary[gameId].Controller, ignoreExpression, originalDictionary, attribute);
                break;

            case "stringdictionary":
            case "gamebookoptions":
                var originalStringDictionary = originalElement.EditorData.GetAttribute(attribute) as IEditableDictionary <string>;
                saveValue = BindStringDictionary(bindingContext.ValueProvider, editorDictionary[gameId].Controller, ignoreExpression, originalStringDictionary, attribute, ctl);
                break;

            default:
                if (attribute == null || controlType == null)
                {
                    addSaveValueToResult = false;
                }
                else
                {
                    throw new ArgumentException(string.Format("Save data model binder not implemented for control type {0}", controlType));
                }
                break;
            }

            if (addSaveValueToResult)
            {
                if (result.Values.ContainsKey(attribute))
                {
                    Logging.Log.ErrorFormat("SaveData already contains attribute \"{0}\" - saveValue (\"{1}\") discarded", attribute, saveValue);
                }
                else
                {
                    // remove attr prefix if it is in the attribute name:
                    if (attribute.StartsWith("attr_"))
                    {
                        attribute = attribute.Substring(5);
                    }

                    result.Values.Add(attribute, saveValue);
                }
            }
        }
Example #21
0
        public string DisplayString(IEditableScripts modifiedSection, int index, string newValue)
        {
            // If we've updated the "then" script, then we need to get an updated "then" script where attribute "index" has been updated to "newValue"
            string result = (modifiedSection == ThenScript) ? ThenDisplayStringFragment(index, newValue) : ThenDisplayStringFragment(-1, string.Empty);

            foreach (EditableElseIf elseIf in m_elseIfScripts.Values)
            {
                result += (modifiedSection == elseIf.EditableScripts) ? ElseIfDisplayStringFragment(elseIf, index, newValue) : ElseIfDisplayStringFragment(elseIf, - 1, string.Empty);
            }

            if (ElseScript != null)
            {
                result += (modifiedSection == ElseScript) ? ElseDisplayStringFragment(index, newValue) : ElseDisplayStringFragment(-1, string.Empty);
            }
            return result;
        }
Example #22
0
        void ctlToolbar_Paste()
        {
            if (m_readOnly) return;
            if (CodeView)
            {
                textEditor.Paste();
            }
            else
            {
                int index;
                if (lstScripts.SelectedIndex < 0)
                {
                    index = lstScripts.Items.Count;
                }
                else
                {
                    index = lstScripts.SelectedIndex + 1;
                }

                Save();

                if (m_scripts == null)
                {
                    m_controller.StartTransaction("Paste script");

                    if (m_parentScript != null)
                    {
                        m_scripts = m_controller.CreateNewEditableScriptsChild(m_parentScript, m_helper.ControlDefinition.Attribute, null, false);
                    }
                    else
                    {
                        m_scripts = m_controller.CreateNewEditableScripts(ElementName, m_helper.ControlDefinition.Attribute, null, false);
                    }
                
                    m_scripts.Paste(index, false);
                    m_controller.EndTransaction();
                    RefreshScriptsList();
                }
                else
                {
                    m_scripts.Paste(index, true);
                }
                Save();
                SetSelectedIndex(index);
            }
        }
Example #23
0
 // Note there are two "Populate" methods, so EITHER m_script OR m_data will be set.
 public void Populate(IEditorData data, IEditableScripts script)
 {
     m_script = script;
 }
Example #24
0
 public PartialViewResult EditScriptValue(int id, string key, IEditableScripts script, string attribute)
 {
     return(PartialView("ScriptEditor", EditorDictionary[id].GetScriptModel(id, key, script, attribute, ModelState)));
 }
Example #25
0
 void ctlToolbar_Paste()
 {
     int index = lstScripts.SelectedIndex;
     if (index < 0) return;
     Save();
     if (m_scripts == null)
     {
         m_controller.StartTransaction("Paste script");
         m_scripts = m_controller.CreateNewEditableScripts(ElementName, m_helper.ControlDefinition.Attribute, null, false);
         m_scripts.Paste(index, false);
         m_controller.EndTransaction();
         RefreshScriptsList();
     }
     else
     {
         m_scripts.Paste(index, true);
     }
     Save();
     SetSelectedIndex(index);
 }
Example #26
0
        public void Populate(IEditableScripts script)
        {
            if (m_scripts != null)
            {
                m_scripts.Updated -= m_scripts_Updated;
            }
            m_scripts = script;
            if (m_scripts != null)
            {
                m_scripts.Updated += m_scripts_Updated;
            }

            RefreshScriptsList();
        }
Example #27
0
 void ctlToolbar_PopOut()
 {
     ScriptEditorPopOut popOut = new ScriptEditorPopOut();
     popOut.ScriptEditor.Helper.Dirty += PopOut_Dirty;
     popOut.ScriptEditor.Helper.RequestParentElementEditorSave += PopOut_RequestParentElementEditorSave;
     popOut.ScriptEditor.Helper.DoInitialise(m_helper.Controller, m_helper.ControlDefinition);
     popOut.ScriptEditor.ReadOnly = m_readOnly;
     popOut.ScriptEditor.Populate(m_scripts);
     popOut.ShowDialog();
     m_scripts = popOut.ScriptEditor.m_scripts;
 }
Example #28
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++;
            }
        }