Fixed invoking TOOL_ACTIONs in submenus
Fixes: lp:1663101 * https://bugs.launchpad.net/kicad/+bug/1663101
This commit is contained in:
parent
6dec72b3c6
commit
060e163511
|
@ -286,15 +286,14 @@ void CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent )
|
||||||
// One of menu entries was selected..
|
// One of menu entries was selected..
|
||||||
else if( type == wxEVT_COMMAND_MENU_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();
|
m_selected = aEvent.GetId();
|
||||||
|
|
||||||
// Check if there is a TOOL_ACTION for the given ID
|
// Check if there is a TOOL_ACTION for the given ID
|
||||||
if( m_toolActions.count( aEvent.GetId() ) == 1 )
|
if( m_selected >= ACTION_ID )
|
||||||
{
|
evt = findToolAction( m_selected );
|
||||||
evt = m_toolActions[aEvent.GetId()]->MakeEvent();
|
|
||||||
}
|
if( !evt )
|
||||||
else
|
|
||||||
{
|
{
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
if( !evt )
|
if( !evt )
|
||||||
|
@ -344,7 +343,10 @@ void CONTEXT_MENU::runOnSubmenus( std::function<void(CONTEXT_MENU*)> aFunction )
|
||||||
{
|
{
|
||||||
try
|
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 )
|
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 )
|
void CONTEXT_MENU::copyFrom( const CONTEXT_MENU& aMenu )
|
||||||
{
|
{
|
||||||
SetTitle( aMenu.GetTitle() );
|
SetTitle( aMenu.GetTitle() );
|
||||||
|
|
|
@ -199,6 +199,9 @@ private:
|
||||||
///> Runs a function on the menu and all its submenus.
|
///> Runs a function on the menu and all its submenus.
|
||||||
void runOnSubmenus( std::function<void(CONTEXT_MENU*)> aFunction );
|
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.
|
///> Flag indicating that the menu title was set up.
|
||||||
bool m_titleDisplayed;
|
bool m_titleDisplayed;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue