Customise properties for certain file types

Oct 13, 2009 at 10:50 AM

Hi,

My team use a custom project type and I want to add custom properties to the properties window depending on the file extension or file type. e.g. if its a css file then I want to see an extra property that is specific to that file type. Same would apply to js files etc.

So we have our own version of the SingleFileGeneratorNodeProperties class which allows us to add properties, but this will mean that these properties are available for all file types, when we would like to make them specific as mentioned above.

Please help.

Thanks,

Mike

 

Developer
Oct 13, 2009 at 11:02 AM

Hi Mike,

I'm not I understood the situation yet, so I'd like to ask some questions to understand it:

1. Do you use custom project type based or you extend C# or other project types?

2. In case your answer for Q1 - did you tried to create different custom FileNode inheritors and override NodeProperties for them with specific set of properties for different file types?

Best wishes,

Dmitry Pavlov

Oct 13, 2009 at 12:12 PM

Hi Dmitry,

We use a custom project type.

Your suggestion in point 2 is exactly what I was looking for!

Thanks very much!

Mike

Developer
Oct 13, 2009 at 12:26 PM

You are welcome, Mike!

1. You should write in you custom project class code like this:

public override FileNode CreateFileNode(ProjectElement item)
    {
      if (item == null)
      {
        throw new ArgumentNullException("item");
      }
      return new YourCustomFileNode(this, item);
    }

2. Inherit YourCustomFileNode class from MPF FileNode class

3. Override NodeProperties creation in custom file node:

protected override NodeProperties CreatePropertiesObject()
    {
      return new YourCustomFileNodeProperties(this);
    }

4. And inherit YourCustomFileNodeProperties from MPF FileNodeProperties class

NOTE: I'm not sure it is correct but I remember right I had problems with custom properties class until I added this property to it:

     [Browsable(false)]
        public string SubType
        {
            get
            {
                return Node.SubType;
            }
            set
            {
                Node.SubType = value;
            }
        }

Hope that saves the time.

Another tip - to understand how to expose properties - look at the implementation of some MPF NodeProperties class inheritors.

 

Best wishes,

Dmitry Pavlov