[wx-dev] Commands in menus are always enabled
Michael Hieke
michael.hieke at elwi-elektronik.de
Mon Apr 21 00:09:26 PDT 2008
Yazhuk, Andrey (NIH/NLM/NCBI) [C] wrote:
>>> How about providing a fallback menu update handler (e.g. in the
>>> application object) that always disables the menu item? So if no
>>> update event handler is provided, the command will be disabled.
>
> I can probably do this, but it may be difficult to maintain these
> handlers.
I tried the same approach a few weeks ago, and it seems to work for me
for wxMSW and wxGTK2 at least. There is a problem with wxMAC (where it
doesn't work at all ATM), but I already created a tracker item in SF bug
tracker, assigned to Stefan C.
What I have is basically:
void Application::OnUpdateUIDisable(wxUpdateUIEvent& event)
{
event.Enable(false);
}
with dynamic connection of these event ids via
Connect(wxID_LOWEST, wxID_HIGHEST, wxEVT_UPDATE_UI,
wxUpdateUIEventHandler(Application::OnUpdateUIDisable));
Connect(CmdIdFirst, CmdIdLast, wxEVT_UPDATE_UI,
wxUpdateUIEventHandler(Application::OnUpdateUIDisable));
where CmdIdFirst to CmdIdLast is the range used for menu and toolbar
command ids in my application. Not much to maintain there, really.
Thanks
--
Michael Hieke
More information about the wx-dev
mailing list