Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development

Plugin::BuildMenu() called twice [resolved]

(1/1)

stardust:
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.

Pecan:

--- Quote from: 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?

--- End quote ---
::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?

--- End quote ---

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.

--- End quote ---

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.

stardust:
Ok, thanks

thomas:
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).

Navigation

[0] Message Index

Go to full version