Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: dmoore on January 20, 2014, 07:24:02 pm

Title: Issue using EVT_UPDATE_UI to track AUI dock window state
Post by: dmoore on January 20, 2014, 07:24:02 pm
See the code here: https://github.com/spillz/codeblocks-python/blob/master/PythonInterpreter/PythonInterpreter.cpp#L39

Relevant snippet:

Code
BEGIN_EVENT_TABLE(PythonInterpreter, cbPlugin)
        // add any events you want to handle here
    EVT_MENU(ID_INTERP_WINDOW_TOGGLE,PythonInterpreter::OnToggleInterpreterWindow)
    EVT_UPDATE_UI(wxID_ANY/*ID_INTERP_WINDOW_TOGGLE*/, PythonInterpreter::OnUpdateUI) //<#######################
    EVT_COMMAND(0,wxEVT_SHELL_ADD_CLICKED, PythonInterpreter::AddNewInterpreter)
END_EVENT_TABLE()


void PythonInterpreter::OnUpdateUI(wxUpdateUIEvent& event)
{
#ifndef TOOLSPLUSLINK
    if(m_ViewMenu)
    {
        m_ViewMenu->Check(ID_INTERP_WINDOW_TOGGLE,IsWindowReallyShown(m_shellmgr));
        // allow other UpdateUI handlers to process this event
        // *very* important! don't forget it...
        event.Skip();
    }
#endif // TOOLSPLUSLINK
}

Note the line marked with ###. If I change wxID_ANY to the ID of the actual menu item I want to update (i.e. ID_INTERP_WINDOW_TOGGLE) I won't get updates when I close the associated dock window. But it works fine for wxID_ANY.

A similar issue affects Tools+ plugin, which isn't set for wxID_ANY and so doesn't update correctly. Any thoughts on what's going on here?
Title: Re: Issue using EVT_UPDATE_UI to track AUI dock window state
Post by: sodev on January 21, 2014, 11:53:47 pm
The problem lies a little further upwards

Code
int ID_INTERP_WINDOW_TOGGLE=wxNewId();

The ID gets generated at runtime but the event table gets generated at compile time. Actually i wonder why this compiles at all, and also the menu eventhandler shouldn't be called as well. So either use a compile time constant for the event table (like an enum value), or use dynamic event handler registration (Bind<> is so amazing, i totally stopped using event tables at all. However this doesn't work if you still need to be compatible to wxWidgets 2.8 ;D).