Jump to content

CreateInitialToken in EffectConfigDialog


midora

Recommended Posts

I derived a dialog from EffectConfigDialog. The constructor of the dialog gets a description list of controls to create. The list contains the default values of the controls too.

 

What's the right way to access the list in CreateInitialToken() to set the values of the new token to defaults?

 

The problem is that the base class constructor of the dialog seems to call CreateInitialToken() to request the new token. But because this constructor will be executed before I can store the list in the new dialog instance , I don't know how to solve this issue.

 

OK, temporary I'm using a static variable in the dialog class to provide the list to CreateInitialToken(), but this is just to allow me to continue coding...

midoras signature.gif

Link to comment
Share on other sites

There's a way to get around this although it's a little wonky. The trick is to use the same pattern that the internal effects use (rather, PropertyBasedEffect) via a separate non-public (internal) constructor. The constructor's parameter isn't interesting other than that it lets you call another method before the base constructor gets called. You can then set the value of a private field and then use it in CreateInitialToken.

 

You'll need to create an additional base class:

 

class DescriptionListOfControlsToCreate { ... }

 

class EffectConfigDialogTrampoline : EffectConfigDialog 
{

    protected EffectConfigDialogTrampoline(object context)
       : base()
    {

        // We don't actually do anything with context

    }
}

 

class MyEffectConfigDialog : EffectConfigDialogTrampoline
{

    private DescriptionListOfControlsToCreate info;

 

    private object InitializeStuff(DescriptionListOfControlsToCreate info)
    {

        this.info = info;

        return null;

    }

 

    public MyEffectConfigDialog(DescriptionListOfControlsToCreate info) : base(InitializeStuff(info))
    {

    }

 

    protected overried CreateInitialToken()
    {

        ... use this.info to do whatever you need
    }
}

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

On second thought, that won't work, I think -- I don't think it'll let you call an instance method (InitializeStuff) before the body of your constructor. However, it might give you a kickstart toward finding something that will work?

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Thanks taking the time looking in this issue. It drives me crazy ;-)

 

Nothing is ready during CreateInitialToken.

Even the Effect Property of the ConfigDialog is not set at this time.

Or the service to access the userdata path.

 

Means PropertyBasedEffect can use an other constructor in the assembly but it is internal and can not be used from dlls?

Because I would expect that the PropertyBasedEffect has the same issue to access the list of properties.

midoras signature.gif

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...