Beispiel #1
0
        private void AddVerb(string selectedPattern, string selectedAttribute)
        {
            bool setSelection = true;

            if (!lstAttributes.Items.ContainsKey(selectedAttribute))
            {
                if (!CanAddVerb(selectedPattern, selectedAttribute))
                {
                    return;
                }

                Controller.StartTransaction(string.Format("Add '{0}' verb", selectedPattern));

                if (!Controller.IsVerbAttribute(selectedAttribute))
                {
                    CreateNewVerb(selectedPattern, selectedAttribute);
                }

                ValidationResult setAttrResult = Data.SetAttribute(selectedAttribute, String.Empty);
                if (!setAttrResult.Valid)
                {
                    PopupEditors.DisplayValidationError(setAttrResult, selectedAttribute, "Unable to add verb");
                    setSelection = false;
                }
                Controller.EndTransaction();
            }

            if (setSelection)
            {
                lstAttributes.Items[selectedAttribute].Selected = true;
                lstAttributes.SelectedItems[0].EnsureVisible();
            }
        }
Beispiel #2
0
        protected virtual void Add(string attributeName, Func <object> createAttributeValue)
        {
            if (attributeName.Length == 0)
            {
                PopupEditors.EditStringResult result = PopupEditors.EditString(L.T("EditorEnterNameAttribute"), string.Empty);
                if (result.Cancelled)
                {
                    return;
                }
                attributeName = result.Result;
            }

            bool setSelection = true;

            if (!lstAttributes.Items.ContainsKey(attributeName))
            {
                m_controller.StartTransaction(string.Format("Add '{0}' attribute", attributeName));

                ValidationResult setAttrResult = m_data.SetAttribute(attributeName, createAttributeValue());
                if (!setAttrResult.Valid)
                {
                    PopupEditors.DisplayValidationError(setAttrResult, attributeName, "Unable to add attribute");
                    setSelection = false;
                }

                m_controller.EndTransaction();
            }

            if (setSelection)
            {
                lstAttributes.Items[attributeName].Selected = true;
                lstAttributes.SelectedItems[0].EnsureVisible();
            }
        }
Beispiel #3
0
 private void AddNewPage()
 {
     m_manager.DoAddKeyAction((newKey) =>
     {
         ValidationResult result = m_controller.CanAdd(newKey);
         if (!result.Valid)
         {
             PopupEditors.DisplayValidationError(result, newKey, "Unable to add page");
             return(false);
         }
         m_controller.CreateNewObject(newKey, null, null);
         return(true);
     }, m_controller.GetUniqueElementName("Page1"));
 }
Beispiel #4
0
        private bool ValidateInput(string input)
        {
            if (m_list == null)
            {
                return(true);
            }
            ValidationResult result = m_list.CanAdd(input);

            if (result.Valid)
            {
                return(true);
            }

            PopupEditors.DisplayValidationError(result, input, "Unable to add item");
            return(false);
        }
Beispiel #5
0
        public void Save()
        {
            bool save = true;

            if (!m_helper.IsDirty)
            {
                return;
            }
            m_saving = true;
            string saveValue = null;

            if (SimpleMode)
            {
                saveValue = ConvertFromSimpleExpression(SimpleValue);
            }
            else if (TemplateMode)
            {
                saveValue = m_templateEditor.SaveExpression();
            }
            else
            {
                saveValue = txtExpression.Text;
            }
            ValidationResult result = m_helper.Controller.ValidateExpression(saveValue);

            save = result.Valid;
            if (!result.Valid)
            {
                PopupEditors.DisplayValidationError(result, saveValue, "Invalid expression");
            }
            if (m_helper.ControlDefinition.GetBool("nullable") && string.IsNullOrEmpty(saveValue))
            {
                saveValue = null;
            }
            if (save)
            {
                m_helper.Save(saveValue);
            }
            m_saving = false;
            if (!save)
            {
                Populate(m_data);
            }
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        private void cmdAddType_Click(object sender, EventArgs e)
        {
            if (m_readOnly)
            {
                return;
            }

            var availableTypes = m_controller.GetElementNames("type")
                                 .Where(t => !lstTypes.Items.ContainsKey(t))
                                 .Where(t => !m_controller.IsDefaultTypeName(t))
                                 .OrderBy(t => t);

            var result = PopupEditors.EditStringWithDropdown(L.T("EditorChooseTypeToAdd"), string.Empty, null, null,
                                                             string.Empty, availableTypes);

            if (result.Cancelled)
            {
                return;
            }

            if (!availableTypes.Contains(result.Result))
            {
                if (lstTypes.Items.ContainsKey(result.Result))
                {
                    MessageBox.Show(string.Format("Type '{0}' is already inherited", result.Result), "Invalid type",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    MessageBox.Show(string.Format("Type '{0}' does not exist", result.Result), "Invalid type",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                return;
            }

            var addResult = m_controller.AddInheritedTypeToElement(m_data.Name, result.Result, true);

            if (!addResult.Valid)
            {
                PopupEditors.DisplayValidationError(addResult, null, "Unable to add type");
            }
        }
Beispiel #8
0
        private void UserSelectedNewType(TypesListItem type)
        {
            m_controller.StartTransaction(string.Format("Change type of '{0}' {1} to '{2}'", m_data.Name, m_definition.Attribute, type.TypeDescription));

            object newValue;

            // If the user has previously selected this type, use the previous value, otherwise create a new
            // default value for that type. This allows the user to switch back and forth between different
            // types without the value being cleared out if they change their mind.

            if (m_storedValues.ContainsKey(type.TypeName))
            {
                newValue = m_storedValues[type.TypeName];
            }
            else
            {
                switch (type.TypeName)
                {
                case "boolean":
                    newValue = false;
                    break;

                case "string":
                    newValue = "";
                    break;

                case "int":
                    newValue = 0;
                    break;

                case "double":
                    newValue = 0.0;
                    break;

                case "script":
                    newValue = m_controller.CreateNewEditableScripts(m_data.Name, m_definition.Attribute, null, false);
                    break;

                case "stringlist":
                    newValue = m_controller.CreateNewEditableList(m_data.Name, m_definition.Attribute, null, false);
                    break;

                case "object":
                    newValue = m_controller.CreateNewEditableObjectReference(m_data.Name, m_definition.Attribute, false);
                    break;

                case "simplepattern":
                    newValue = m_controller.CreateNewEditableCommandPattern(m_data.Name, m_definition.Attribute, "", false);
                    break;

                case "stringdictionary":
                    newValue = m_controller.CreateNewEditableStringDictionary(m_data.Name, m_definition.Attribute, null, null, false);
                    break;

                case "scriptdictionary":
                    newValue = m_controller.CreateNewEditableScriptDictionary(m_data.Name, m_definition.Attribute, null, null, false);
                    break;

                case "null":
                    newValue = null;
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }

            var result = m_data.SetAttribute(m_definition.Attribute, newValue);

            if (!result.Valid)
            {
                PopupEditors.DisplayValidationError(result, newValue as string, "Unable to set attribute value");
            }

            m_controller.EndTransaction();
        }