Example #1
0
            public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
            {
                PropertiesContainer obj = (value as PropertiesContainer);

                if (obj == null)
                {
                    return(new PropertyDescriptorCollection(new PropertyDescriptor[] {}));
                }

                List <Property> propertyList = obj.PropertyList;

                PropertyDescriptor[] props = new PropertyDescriptor[propertyList.Count];

                // Create the list of property descriptors.
                for (int i = 0; i < propertyList.Count; i++)
                {
                    Property              property      = propertyList[i];
                    string                name          = property.Name;
                    UITypeEditor          editor        = null;
                    PropertyDocumentation documentation = property.GetDocumentation();

                    // Find the editor.
                    if (documentation != null)
                    {
                        editor = obj.PropertyGrid.GetUITypeEditor(documentation.EditorType);
                    }

                    // Create the property descriptor.
                    props[i] = new CustomPropertyDescriptor(
                        documentation, editor, property.Name, obj.Properties);
                }

                return(new PropertyDescriptorCollection(props));
            }
        public void PropertyWithPropertyAnnotationAttributesShouldSetAnnotations()
        {
            var doc = new PropertyDocumentation(new ResourceKeyStack(bundle), typeof(TestTag).GetProperty("Color"));

            Assert.That(doc.Annotations.Length, Is.EqualTo(2));
            Assert.That(doc.Annotations[0], Is.EqualTo("test1"));
            Assert.That(doc.Annotations[1], Is.EqualTo("test2"));
        }
        //-----------------------------------------------------------------------------
        // Constructor
        //-----------------------------------------------------------------------------

        public CustomPropertyDescriptor(PropertyDocumentation documentation, UITypeEditor editor, string propertyName, Properties modifiedProperties) :
            base(documentation == null ? propertyName : documentation.ReadableName, null)
        {
            this.documentation      = documentation;
            this.editor             = editor;
            this.propertyName       = propertyName;
            this.modifiedProperties = modifiedProperties;
        }
Example #4
0
 public void AddProperties(Properties properties)
 {
     foreach (Property property in  properties.GetAllProperties())
     {
         PropertyDocumentation doc = property.GetDocumentation();
         if (doc == null || !doc.IsHidden)
         {
             propertyList.Add(property);
         }
     }
 }
Example #5
0
        public void PropertyShouldReturnDescriptionKeyOfDeclaringType()
        {
            ResourceKeyStack key = new ResourceKeyStack(bundle);

            key = key.BranchFor(new Core());
            key = key.BranchFor(new Set());
            var property = new PropertyDocumentation(key,
                                                     typeof(Set).GetProperty("Var"));

            Assert.That(property.DescriptionKey, Is.EqualTo("description_BaseCoreTagWithVariable_Var"));
        }
Example #6
0
        public void PropertyShouldReturnDescriptionKey()
        {
            var key = new ResourceKeyStack(bundle);

            key = key.BranchFor(new Core());
            key = key.BranchFor(new Out());
            var property = new PropertyDocumentation(key,
                                                     typeof(Out).GetProperty("Value"));

            Assert.That(property.DescriptionKey, Is.EqualTo("description_Core_Out_Value"));
        }
Example #7
0
        public void PropertyShouldReturnDescriptionKeyOfDeclaringGroup()
        {
            var key = new ResourceKeyStack(bundle);

            key = key.BranchFor(new Format());
            key = key.BranchFor(new Message());

            var property = new PropertyDocumentation(key,
                                                     typeof(Message).GetProperty("Scope"));

            Assert.That(property.DescriptionKey, Is.EqualTo("description_BaseCoreTagWithOptionalVariable_Scope"));
        }
Example #8
0
        public void OnDeleteObject(IPropertyObject propertyObject)
        {
            // Remove any hidden scripts referenced in the tile's propreties.
            foreach (Property property in propertyObject.Properties.GetProperties())
            {
                PropertyDocumentation doc = property.GetDocumentation();

                // Remove hidden scripts referenced by this property.
                if (doc.EditorType == "script")
                {
                    string scriptID = property.StringValue;
                    Script script   = world.GetScript(scriptID);
                    if (script != null && script.IsHidden)
                    {
                        world.RemoveScript(script);
                        Console.WriteLine("Removed hidden script: " + scriptID);
                    }
                }
            }
        }
Example #9
0
        //-----------------------------------------------------------------------------
        // Events
        //-----------------------------------------------------------------------------

        private void OnPropertyChange(object sender, PropertyValueChangedEventArgs e)
        {
            CustomPropertyDescriptor propertyDescriptor = e.ChangedItem.PropertyDescriptor as CustomPropertyDescriptor;
            Property property = propertyDescriptor.Property;
            PropertyDocumentation propertyDoc = property.GetRootDocumentation();

            // Handle special property editor-types.
            if (propertyDoc != null && propertyDoc.EditorType == "script")
            {
                string oldValue = e.OldValue.ToString();
                string newValue = e.ChangedItem.Value.ToString();

                Script oldScript          = editorControl.World.GetScript(oldValue);
                Script newScript          = editorControl.World.GetScript(newValue);
                bool   isNewScriptInvalid = (newScript == null && newValue.Length > 0);

                // When a script property is changed from a hidden script to something else.
                if (oldScript != null && oldScript.IsHidden && newScript != oldScript)
                {
                    // Delete the old script from the world (because it is now unreferenced).
                    editorControl.World.RemoveScript(oldScript);
                    Console.WriteLine("Deleted unreferenced script '" + oldValue + "'");

                    // Don't allow the user to reference other hidden scripts.
                    if (newScript != null && newScript.IsHidden)
                    {
                        isNewScriptInvalid = true;
                    }
                }

                // Show a message if the script is invalid.
                if (isNewScriptInvalid)
                {
                    MessageBox.Show("'" + newValue + "' is not a valid script name.");
                }
            }
        }
        public void PropertyWithNumberPropertyAttributeShouldSetNumberDataType()
        {
            var doc = new PropertyDocumentation(new ResourceKeyStack(bundle), typeof(TestTag).GetProperty("Id"));

            Assert.That(doc.DataType, Is.EqualTo(TagAttributeDataType.Number));
        }
Example #11
0
        public void SetupObject(IPropertyObject propertyObject)
        {
            // Create a list of all event properties.
            List <Property> eventProperties = new List <Property>();

            foreach (Property property in propertyObject.Properties.GetAllProperties())
            {
                PropertyDocumentation doc = property.GetDocumentation();
                if (doc != null && doc.EditorType == "script")
                {
                    eventProperties.Add(property);
                }
            }

            objectEvents.Clear();
            listBoxEvents.Items.Clear();

            IEventObject eventObject = objectEditor.PropertyObject as IEventObject;

            if (eventObject != null)
            {
                foreach (KeyValuePair <string, ObjectEvent> entry in eventObject.Events.Events)
                {
                    listBoxEvents.Items.Add(entry.Value.ReadableName);

                    Property property = objectEditor.PropertyObject.Properties.GetProperty(entry.Value.Name, true);

                    InternalObjectEvent objEvent = new InternalObjectEvent();
                    objEvent.Property           = property;
                    objEvent.Id                 = entry.Value.Name;
                    objEvent.Name               = entry.Value.ReadableName;
                    objEvent.Description        = entry.Value.Description;
                    objEvent.CustomScriptExists = false;
                    objEvent.Event              = entry.Value;

                    if (property != null)
                    {
                        string scriptName = property.StringValue;
                        Script script     = null;
                        if (scriptName.Length > 0)
                        {
                            script = EditorControl.World.GetScript(scriptName);
                        }

                        if (script == null)
                        {
                            objEvent.RadioButtonIndex = RedioButtonIndex.None;
                            objEvent.CustomScript     = null;
                            objEvent.ReferencedScript = null;
                        }
                        else if (script.IsHidden)
                        {
                            objEvent.RadioButtonIndex   = RedioButtonIndex.CustomCode;
                            objEvent.CustomScript       = script;
                            objEvent.ReferencedScript   = null;
                            objEvent.CustomScriptExists = true;
                        }
                        else
                        {
                            objEvent.RadioButtonIndex = RedioButtonIndex.Script;
                            objEvent.CustomScript     = null;
                            objEvent.ReferencedScript = script;
                        }
                    }
                    else
                    {
                        objEvent.RadioButtonIndex = RedioButtonIndex.None;
                        objEvent.CustomScript     = null;
                        objEvent.ReferencedScript = null;
                    }

                    objectEvents.Add(objEvent);
                }
            }
            else
            {
                for (int i = 0; i < eventProperties.Count; i++)
                {
                    Property property         = eventProperties[i];
                    PropertyDocumentation doc = property.GetRootDocumentation();
                    string name = (doc != null ? doc.ReadableName : property.Name);
                    listBoxEvents.Items.Add(name);

                    InternalObjectEvent objEvent = new InternalObjectEvent();
                    objEvent.Property           = property;
                    objEvent.Id                 = property.Name;
                    objEvent.Name               = (doc != null ? doc.ReadableName : property.Name);
                    objEvent.Description        = (doc != null ? doc.Description : "");
                    objEvent.CustomScriptExists = false;
                    objEvent.Event              = null;
                    if (objectEditor.PropertyObject is IEventObject)
                    {
                        objEvent.Event = ((IEventObject)objectEditor.PropertyObject).Events.GetEvent(property.Name);
                    }

                    string scriptName = property.StringValue;
                    Script script     = null;
                    if (scriptName.Length > 0)
                    {
                        script = EditorControl.World.GetScript(scriptName);
                    }

                    if (script == null)
                    {
                        objEvent.RadioButtonIndex = RedioButtonIndex.None;
                        objEvent.CustomScript     = null;
                        objEvent.ReferencedScript = null;
                    }
                    else if (script.IsHidden)
                    {
                        objEvent.RadioButtonIndex   = RedioButtonIndex.CustomCode;
                        objEvent.CustomScript       = script;
                        objEvent.ReferencedScript   = null;
                        objEvent.CustomScriptExists = true;
                    }
                    else
                    {
                        objEvent.RadioButtonIndex = RedioButtonIndex.Script;
                        objEvent.CustomScript     = null;
                        objEvent.ReferencedScript = script;
                    }

                    objectEvents.Add(objEvent);
                }
            }

            if (listBoxEvents.Items.Count > 0)
            {
                listBoxEvents.SelectedIndex = 0;
                objectEvent = objectEvents[0];
            }
            else
            {
                listBoxEvents.SelectedIndex = -1;
                objectEvent = null;
            }
        }
 public PropertyDocBuilder(PropertyDocumentation propertyDocumentation, TypeDocumentation typeDocumentation, AssemblyDocumentation assemblyDocumentation)
     : base(propertyDocumentation, typeDocumentation, assemblyDocumentation)
 {
 }
 public void RequiredPropertyShouldHaveRequiredFlag()
 {
     var doc = new PropertyDocumentation(new ResourceKeyStack(bundle), typeof (Set).GetProperty("Var"));
     Assert.That(doc.Required, Is.True);
 }
        public void NotRequiredPropertyShouldHaveNotRequiredFlag()
        {
            var doc = new PropertyDocumentation(new ResourceKeyStack(bundle), typeof(Out).GetProperty("EscapeXml"));

            Assert.That(doc.Required, Is.False);
        }
 public void NotRequiredPropertyShouldHaveNotRequiredFlag()
 {
     var doc = new PropertyDocumentation(new ResourceKeyStack(bundle), typeof (Out).GetProperty("EscapeXml"));
     Assert.That(doc.Required, Is.False);
 }
        public void RequiredPropertyShouldHaveRequiredFlag()
        {
            var doc = new PropertyDocumentation(new ResourceKeyStack(bundle), typeof(Set).GetProperty("Var"));

            Assert.That(doc.Required, Is.True);
        }
        public void PropertyWithEnumPropertyAttributeShouldSetEnumDataType()
        {
            var doc = new PropertyDocumentation(new ResourceKeyStack(bundle), typeof(TestTag).GetProperty("Color"));

            Assert.That(doc.DataType, Is.EqualTo(TagAttributeDataType.Enum));
        }
        public void PropertyWithBooleanPropertyAttributeShouldSetBooleanDataType()
        {
            var doc = new PropertyDocumentation(new ResourceKeyStack(bundle), typeof(TestTag).GetProperty("Visible"));

            Assert.That(doc.DataType, Is.EqualTo(TagAttributeDataType.Boolean));
        }
        public void PropertyWithoutDataTypePropertyAttributeShouldSetTextDataType()
        {
            var doc = new PropertyDocumentation(new ResourceKeyStack(bundle), typeof(Set).GetProperty("Var"));

            Assert.That(doc.DataType, Is.EqualTo(TagAttributeDataType.Text));
        }