"singleton" instance per plugin instance / determining plugin instance anywhere in code?


i want to replace all my modal windows with non modal ones. the idea is to have a generalized plugin frame component and then showing a pseudo modal dialog insinde it from anywhere in the code.

my idea is to have a pointer to the plugin window of the current plugin instance and go from there (broadly speaking, not the raw pointer of course).

I read a few things about "static" and share librarys, and it seems kind of hopeless with regular singletons. is there any way i can determine the current instance of my plugin form anywhere(!) in the code?

I have a way to do it form anywhere in the UI (going upwards the hirarchy that is), but not from the backend.

any other ideas about this?




There's no such thing as a "current" plugin instance. The host may have dozens of instances open, and be using all of them. If you have an object that needs to refer to a particular instance, you need to make sure it has some kind of pointer to it.

yes, of course it might have multiple instances. with standalone applications there is of course the "getInstance" method, which gets me the "current" instance. i suppose in this case the instances are differentiated by their proccess(handle)?

anyway, i was afraid that this is the case, but still can't quite believe it. so if i want to do what i proposed, it is happy pointer passing time i guess?

is there really no way of instance wide "global" variables :O ?  i suppose my internal design is not the best, but the software is great from a user perspective, so i'd like to fix and release it :).

thanks for the reply jules! :)



Hi, facing the same problem I just made a PluginContext object that I can retrieve from everywhere in either the ui or the processor part of the plugin. Then just store your semi-singleton like instance into that pluginContext object. It is very temptating to use a host singleton instance instead but as it might be relevant to either have a "one plugin scope" or that each host might in some case run the plugin in a separated thread it's just unsafe.