Author Topic: Plugin::BuildMenu() called twice [resolved]  (Read 3474 times)

Offline stardust

  • Multiple posting newcomer
  • *
  • Posts: 55
    • http://www.hightec-rt.com
Plugin::BuildMenu() called twice [resolved]
« 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.
« Last Edit: March 07, 2007, 02:35:58 pm by stardust »
Own SVN builds (quite new) SuSE Linux 10.0 Linux kernel 2.6.13-15-default
gcc 4.0.2 (20050901)
wxGTK-2.6.1.0-4 KDE 3.4.2b gtk2 2.8.3-4

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2259
Re: Plugin::BuildMenu() called twice
« Reply #1 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.

Offline stardust

  • Multiple posting newcomer
  • *
  • Posts: 55
    • http://www.hightec-rt.com
Re: Plugin::BuildMenu() called twice
« Reply #2 on: March 07, 2007, 02:35:42 pm »
Ok, thanks
Own SVN builds (quite new) SuSE Linux 10.0 Linux kernel 2.6.13-15-default
gcc 4.0.2 (20050901)
wxGTK-2.6.1.0-4 KDE 3.4.2b gtk2 2.8.3-4

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Plugin::BuildMenu() called twice [resolved]
« Reply #3 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).
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."