News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Issue using EVT_UPDATE_UI to track AUI dock window state

Started by dmoore, January 20, 2014, 07:24:02 PM

Previous topic - Next topic

dmoore

See the code here: https://github.com/spillz/codeblocks-python/blob/master/PythonInterpreter/PythonInterpreter.cpp#L39

Relevant snippet:


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?
Python plugins: [url="https://github.com/spillz/codeblocks-python"]https://github.com/spillz/codeblocks-python[/url]
Code::Blocks Daily Builds -- Ubuntu PPA: [url="https://launchpad.net/~damien-moore/+archive/codeblocks"]https://launchpad.net/~damien-moore/+archive/codeblocks[/url]

sodev

The problem lies a little further upwards


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