diff --git a/common/tool/context_menu.cpp b/common/tool/context_menu.cpp index 4c7c2d61eb..294bb19fc0 100644 --- a/common/tool/context_menu.cpp +++ b/common/tool/context_menu.cpp @@ -194,6 +194,14 @@ void CONTEXT_MENU::UpdateAll() } +void CONTEXT_MENU::SetTool( TOOL_INTERACTIVE* aTool ) +{ + m_tool = aTool; + + runOnSubmenus( boost::bind( &CONTEXT_MENU::SetTool, _1, aTool ) ); +} + + TOOL_MANAGER* CONTEXT_MENU::getToolManager() { assert( m_tool ); @@ -293,14 +301,6 @@ void CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent ) } -void CONTEXT_MENU::setTool( TOOL_INTERACTIVE* aTool ) -{ - m_tool = aTool; - - runOnSubmenus( boost::bind( &CONTEXT_MENU::setTool, _1, aTool ) ); -} - - void CONTEXT_MENU::runEventHandlers( const wxMenuEvent& aMenuEvent, OPT_TOOL_EVENT& aToolEvent ) { aToolEvent = m_menu_handler( aMenuEvent ); diff --git a/common/tool/tool_interactive.cpp b/common/tool/tool_interactive.cpp index 14ea61a86a..86a2c71b50 100644 --- a/common/tool/tool_interactive.cpp +++ b/common/tool/tool_interactive.cpp @@ -66,6 +66,6 @@ void TOOL_INTERACTIVE::goInternal( TOOL_STATE_FUNC& aState, const TOOL_EVENT_LIS void TOOL_INTERACTIVE::SetContextMenu( CONTEXT_MENU* aMenu, CONTEXT_MENU_TRIGGER aTrigger ) { - aMenu->setTool( this ); + aMenu->SetTool( this ); m_toolMgr->ScheduleContextMenu( this, aMenu, aTrigger ); } diff --git a/include/tool/context_menu.h b/include/tool/context_menu.h index 3e02ace78f..819cb5eeba 100644 --- a/include/tool/context_menu.h +++ b/include/tool/context_menu.h @@ -147,6 +147,13 @@ public: m_update_handler = aUpdateHandler; } + /** + * Function SetTool() + * Sets a tool that is the creator of the menu. + * @param aTool is the tool that created the menu. + */ + void SetTool( TOOL_INTERACTIVE* aTool ); + protected: ///> Returns an instance of TOOL_MANAGER class. TOOL_MANAGER* getToolManager(); @@ -177,13 +184,6 @@ private: ///> The default menu event handler. void onMenuEvent( wxMenuEvent& aEvent ); - /** - * Function setTool() - * Sets a tool that is the creator of the menu. - * @param aTool is the tool that created the menu. - */ - void setTool( TOOL_INTERACTIVE* aTool ); - ///> Updates hot key settings for TOOL_ACTIONs in this menu. void updateHotKeys(); diff --git a/pcbnew/tools/conditional_menu.cpp b/pcbnew/tools/conditional_menu.cpp index 97c6ff4c35..2184f36d6b 100644 --- a/pcbnew/tools/conditional_menu.cpp +++ b/pcbnew/tools/conditional_menu.cpp @@ -49,6 +49,7 @@ void CONDITIONAL_MENU::AddSeparator( const SELECTION_CONDITION& aCondition, int CONTEXT_MENU* CONDITIONAL_MENU::Generate( SELECTION& aSelection ) { CONTEXT_MENU* m_menu = new CONTEXT_MENU; + m_menu->SetTool( m_tool ); for( std::list::iterator it = m_entries.begin(); it != m_entries.end(); ++it ) { diff --git a/pcbnew/tools/conditional_menu.h b/pcbnew/tools/conditional_menu.h index fe49a28bc7..af9ef2f1ce 100644 --- a/pcbnew/tools/conditional_menu.h +++ b/pcbnew/tools/conditional_menu.h @@ -31,6 +31,7 @@ class SELECTION_TOOL; class TOOL_ACTION; +class TOOL_INTERACTIVE; class CONTEXT_MENU; class CONDITIONAL_MENU @@ -39,6 +40,10 @@ public: ///> Constant to indicate that we do not care about an ENTRY location in the menu. static const int ANY_ORDER = -1; + CONDITIONAL_MENU( TOOL_INTERACTIVE* aTool ) : + m_tool( aTool ) + {} + /** * Function AddItem() * @@ -208,6 +213,9 @@ private: ///> List of all menu entries. std::list m_entries; + + ///> tool owning the menu + TOOL_INTERACTIVE* m_tool; }; #endif /* CONDITIONAL_MENU_H */ diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 9ff589b938..aa230f5020 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -117,6 +117,7 @@ bool PCB_EDITOR_CONTROL::Init() if( selTool ) { m_zoneMenu = new ZONE_CONTEXT_MENU; + m_zoneMenu->SetTool( this ); selTool->GetMenu().AddMenu( m_zoneMenu, _( "Zones" ), false, SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) ); } diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 44e9a01e74..7fe2c48bda 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -70,8 +70,8 @@ public: SELECTION_TOOL::SELECTION_TOOL() : TOOL_INTERACTIVE( "pcbnew.InteractiveSelection" ), - m_frame( NULL ), m_additive( false ), m_multiple( false ), - m_editModules( false ), m_locked( true ), m_contextMenu( NULL ), m_selectMenu( NULL ) + m_frame( NULL ), m_additive( false ), m_multiple( false ), m_editModules( false ), + m_locked( true ), m_menu( this ), m_contextMenu( NULL ), m_selectMenu( NULL ) { // Do not leave uninitialized members: m_preliminary = false; @@ -91,6 +91,8 @@ bool SELECTION_TOOL::Init() m_selection.group = new KIGFX::VIEW_GROUP; m_selectMenu = new SELECT_MENU; + m_selectMenu->SetTool( this ); + m_menu.AddMenu( m_selectMenu, _( "Select..." ), false, ( SELECTION_CONDITIONS::OnlyType( PCB_VIA_T ) || SELECTION_CONDITIONS::OnlyType( PCB_TRACE_T ) ) && SELECTION_CONDITIONS::Count( 1 ) );