Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: stardust on March 07, 2007, 10:30:42 am

Title: Plugin::BuildMenu() called twice [resolved]
Post by: stardust on March 07, 2007, 10:30:42 am
When I install a plugin, then its method ::BuildMenu(wxMenuBar*) gets called twice. Is that OK or is it a bug?
I am creating new objects (menuitems, menues, ...) in this method so I will have a bunch of superflous stuff hanging around.
What is the recommended way to add new items? Shall I first remove/delete everything I just added and then create/add it again? Or just do not care about it?

I used Freeze and Thaw (whatever they do) on the menuBar, with no effect.
Title: Re: Plugin::BuildMenu() called twice
Post by: Pecan on March 07, 2007, 02:12:31 pm

When I install a plugin, then its method ::BuildMenu(wxMenuBar*) gets called twice. Is that OK or is it a bug?
::BuildMenu can be called at any time. Especially when some other plugin activates/deactivates etc. You have to plan for it.

Quote
I am creating new objects (menuitems, menues, ...) in this method so I will have a bunch of superflous stuff hanging around.
What is the recommended way to add new items? Shall I first remove/delete everything I just added and then create/add it again? Or just do not care about it?

In my plugins, I check to make sure all my "menure" has been removed, else I remove it myself, then re-add it just to make sure its in the correct position, with the correct separater etc.

This allows the ::BuildMenu to be re-entered at any time.

Quote
I used Freeze and Thaw (whatever they do) on the menuBar, with no effect.

At the time the menu is offered to you for your inspection, Freeze/Thaw has no effect. The main menu has not been set yet by the core CB.
Title: Re: Plugin::BuildMenu() called twice
Post by: stardust on March 07, 2007, 02:35:42 pm
Ok, thanks
Title: Re: Plugin::BuildMenu() called twice [resolved]
Post by: thomas on March 07, 2007, 02:55:48 pm
There is indeed a known bug in message passing (actually a wxWidgets problem, not a Code::Blocks one) that causes all other plugin events being fired twice, too. While this may in theory have quite nasty consequences (imagine a plugin doing an automatic commit on file save), it is luckily rather harmless in practice. A solution is being worked on, but no release date is known yet.

However, even if everything works correctly, you must be prepared for any of your callbacks to be called at any time, and more often than once.

Regarding BuildMenu(), you need to take care of keeping things you add/remove/modify sorted, unlike BuildModuleMenu()  (the former works on the menu bar owned by the application, the latter on a throwaway menu).