Exemplo n.º 1
0
        /// <summary>
        /// Adds a child DomNode representing a user-defined dynamic property to each of the currently selected objects,
        /// or updates the existing dynamic properties.</summary>
        /// <param name="propertyName">The user-defined dynamic property's name that is displayed in a property editor</param>
        /// <param name="category">The optional property category name</param>
        /// <param name="description">The optional description of the user-defined dynamic property</param>
        /// <param name="converter">e.g., "Sce.Atf.Controls.PropertyEditing.FloatArrayConverter, Atf.Gui"</param>
        /// <param name="editor">e.g., "Sce.Atf.Controls.PropertyEditing.NumericTupleEditor, Atf.Gui.WinForms:System.Single,x,y,z"</param>
        /// <param name="valueType">e.g., customAttributeType.stringValueAttribute.Name</param>
        /// <param name="add">Whether to add a new dynamic property or to update an existing one</param>
        /// <returns>True if successful and false if there was a problem with the input, in which case no
        /// changes were made to the DOM.</returns>
        protected virtual bool AddOrSetDynamicPropertyDomNode(string propertyName, string category, string description,
                                                              string converter, string editor, string valueType, bool add)
        {
            // Check for duplicate dynamic properties.
            foreach (ScriptNode module in EditingContext.Items.AsIEnumerable <ScriptNode>())
            {
                if (!add)
                {
                    DomNode node = GetDynamicDomNode(module);
                    if (node == module.DomNode)
                    {
                        continue;
                    }
                }

                foreach (DomNode childNode in module.DomNode.GetChildren(moduleType.dynamicPropertyChild))
                {
                    // Copies the logic of PropertyUtil.PropertyDescriptorsEqual()
                    if ((string)childNode.GetAttribute(dynamicPropertyType.nameAttribute) == propertyName &&
                        (string)childNode.GetAttribute(dynamicPropertyType.categoryAttribute) == category &&
                        (string)childNode.GetAttribute(dynamicPropertyType.valueTypeAttribute) == valueType)
                    {
                        MessageBox.Show("This dynamic property is a duplicate of another dynamic property on the same object".Localize());
                        return(false);
                    }
                }
            }

            // Construct the command name for the undo/redo menu.
            string commandName = add
                ? string.Format("Add: {0}".Localize(), category + '/' + propertyName)
                : string.Format("Edit: {0}".Localize(), category + '/' + propertyName);

            // Make the DOM changes.
            ITransactionContext transactionContext = EditingContext.Cast <ITransactionContext>();
            bool success = transactionContext.DoTransaction(delegate
            {
                foreach (ScriptNode module in EditingContext.Items.AsIEnumerable <ScriptNode>())
                {
                    DomNode node;
                    if (add)
                    {
                        node = new DomNode(dynamicPropertyType.Type, moduleType.dynamicPropertyChild);
                    }
                    else
                    {
                        node = GetDynamicDomNode(module);
                    }

                    SetDynamicPropertyDomNode(propertyName, category, description, converter, editor, valueType, node);

                    if (add)
                    {
                        module.DomNode.GetChildList(moduleType.dynamicPropertyChild).Add(node);
                    }
                }
            }, commandName);

            return(success);
        }
Exemplo n.º 2
0
        protected virtual bool RemoveProperty()
        {
            ITransactionContext transactionContext = EditingContext.Cast <ITransactionContext>();
            bool success = transactionContext.DoTransaction(delegate
            {
                foreach (ScriptNode module in EditingContext.Items.AsIEnumerable <ScriptNode>())
                {
                    DomNode node = GetDynamicDomNode(module);
                    node.RemoveFromParent();
                }
            }, string.Format("Remove: {0}".Localize(), Descriptor.Category + '/' + Descriptor.DisplayName));

            return(success);
        }