SonyWWS / ATF

Authoring Tools Framework (ATF) is a set of C#/.NET components for making tools on Windows. ATF has been in continuous development in Sony Computer Entertainment's (SCE) Worldwide Studios central tools group since early 2005. ATF has been used by most SCE first party studios to make many custom tools such as Naughty Dog’s level editor and shader editor for The Last of Us, Guerrilla Games’ sequence editor for Killzone games (including the Killzone: Shadow Fall PS4 launch title), an animation blending tool at Santa Monica Studio, a level editor at Bend Studio, a visual state machine editor for Quantic Dream, sound editing tools, and many others.
Apache License 2.0
1.89k stars 262 forks source link

PropertyEditor expose ControlInfo getter #29

Closed ColinCren closed 9 years ago

ColinCren commented 9 years ago

I'd like to change the title of the Property Control in a PropertyEditor, but I don't have access to the ControlInfo to change it's Name, and it's marked as private readonly as well so I have no workaround

Could I get an accessor for m_controlInfo please?

Ron2 commented 9 years ago

Hello,

To customize that ControlInfo, you have to create a derived class from PropertyEditor and override the Configure() method, like this:

[Export(typeof(IInitializable))]
[Export(typeof(IControlHostClient))]
[Export(typeof(PropertyEditor))]
[Export(typeof(MyPropertyEditor))]
[PartCreationPolicy(CreationPolicy.Any)]
public class MyPropertyEditor : PropertyEditor
{
    [ImportingConstructor]
    public MyPropertyEditor(
        ICommandService commandService,
        IControlHostService controlHostService,
        IContextRegistry contextRegistry)
        : base(commandService, controlHostService, contextRegistry)
    {
    }

    protected override void Configure(out PropertyGrid propertyGrid, out ControlInfo controlInfo)
    {
        base.Configure(out propertyGrid, out controlInfo);
        controlInfo.Name = "My Name";
    }
}

Then in your TypeCatalog, replace 'PropertyEditor' with 'MyPropertyEditor'.

I know creating a derived class can be a pain, but an accessor would have the problem where for some of the ControlInfo's properties, you would have to set them at the right time (before the RegisterControl() method gets called on the ControlHostService). That Configure() method makes sure that the ControlInfo gets customized at the correct time.

ColinCren commented 9 years ago

I can't do that because I'm trying to pass into the MyPropertyEditor the title to begin with so as to share it among a multitude of propertyEditors, and since base calls Configure before any of the contents of the constructor I can't do it like that.

What about passing in the title as a parameter of a PropertyEditor constructor?

Ron2 commented 9 years ago

You could pass the title string as a parameter to MyPropertyEditor's constructor and then store it in a field and then use that string in the Configure method, right?

ColinCren commented 9 years ago

I don't think that works: http://www.csharp411.com/c-object-initialization/

The base class's constructor is called before the derived class's constructor

Ron2 commented 9 years ago

Doh! You're absolutely right. I didn't think that all the way through.

I looked at a couple of work-arounds and I think I have a good solution. Since calling a virtual method in a constructor is bad practice anyway, how about we move the call to Configure() to be from the Initialize() method? Then you can pass the title string or even a whole ControlInfo object into your constructor and Configure will be able to work with whatever fields/properties it needs.

I checked in an updated PropertyEditor.cs. Would you mind trying it out?

ColinCren commented 9 years ago

That works. I still think taking an extra constructor parameter is better because then I don't have to derive a new class to change the text from "Property Editor", but it'll do.

Ron2 commented 9 years ago

Thanks, Colin.

ColinCren commented 9 years ago

Did this get rolled back out? One of our guys took latest from the repository and it doesn't appear to be in PropertyEditor?

ColinCren commented 9 years ago

It appears to have disappeared after Nov 8, 2014. Our theory is that it got merged over and the changes from Oct 7th to Nov 8 may have been blitzed? None of us over here use git much.

Ron2 commented 9 years ago

Weird! I don't know what happened, but my changes from 10/16/2014 and 10/30/2014 to this file were lost or did I really never check it in? I'm not sure. I just checked in the changes (again?).

ColinCren commented 9 years ago

You did check them in because that's how I got them to test them. Look at the parent branches for the merge on Nov 8. It seems suspect to me?

I'd also look at the other changes between those dates to be sure.

ColinCren commented 9 years ago

https://github.com/SonyWWS/ATF/commit/a944cc54ad59e64f23e94d16c4ab4315e80dea24 original commit.

Ron2 commented 9 years ago

Thanks, Colin. I thought I was going crazy for a minute there. It looks like the commit on 11/8 has the wrong parent somehow. I don't know Git well enough to understand how this happened. So, we lost changes from 10/7, 10/16, 10/30, and 10/31. I'll have to figure this out tomorrow.

ColinCren commented 9 years ago

Thanks Ron.

Ron2 commented 9 years ago

Jeez, what a mess. I restored 'master' to how I think it should be, but I've lost a bunch of commit messages.