Fixed invoking TOOL_ACTIONs in submenus

Fixes: lp:1663101
* https://bugs.launchpad.net/kicad/+bug/1663101
This commit is contained in:
Maciej Suminski 2017-02-09 21:37:23 +01:00
parent 6dec72b3c6
commit 060e163511
2 changed files with 35 additions and 7 deletions

View File

@ -286,15 +286,14 @@ void CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent )
// One of menu entries was selected..
else if( type == wxEVT_COMMAND_MENU_SELECTED )
{
// Store the selected position
// Store the selected position, so it can be checked by the tools
m_selected = aEvent.GetId();
// Check if there is a TOOL_ACTION for the given ID
if( m_toolActions.count( aEvent.GetId() ) == 1 )
{
evt = m_toolActions[aEvent.GetId()]->MakeEvent();
}
else
if( m_selected >= ACTION_ID )
evt = findToolAction( m_selected );
if( !evt )
{
#ifdef __WINDOWS__
if( !evt )
@ -344,7 +343,10 @@ void CONTEXT_MENU::runOnSubmenus( std::function<void(CONTEXT_MENU*)> aFunction )
{
try
{
std::for_each( m_submenus.begin(), m_submenus.end(), aFunction );
std::for_each( m_submenus.begin(), m_submenus.end(), [&]( CONTEXT_MENU* m ) {
aFunction( m );
m->runOnSubmenus( aFunction );
} );
}
catch( std::exception& e )
{
@ -353,6 +355,29 @@ void CONTEXT_MENU::runOnSubmenus( std::function<void(CONTEXT_MENU*)> aFunction )
}
OPT_TOOL_EVENT CONTEXT_MENU::findToolAction( int aId )
{
OPT_TOOL_EVENT evt;
auto findFunc = [&]( CONTEXT_MENU* m ) {
if( evt )
return;
const auto it = m->m_toolActions.find( aId );
if( it != m->m_toolActions.end() )
evt = it->second->MakeEvent();
};
findFunc( this );
if( !evt )
runOnSubmenus( findFunc );
return evt;
}
void CONTEXT_MENU::copyFrom( const CONTEXT_MENU& aMenu )
{
SetTitle( aMenu.GetTitle() );

View File

@ -199,6 +199,9 @@ private:
///> Runs a function on the menu and all its submenus.
void runOnSubmenus( std::function<void(CONTEXT_MENU*)> aFunction );
///> Checks if any of submenus contains a TOOL_ACTION with a specific ID.
OPT_TOOL_EVENT findToolAction( int aId );
///> Flag indicating that the menu title was set up.
bool m_titleDisplayed;