Commit c5c83bd2 authored by Maciej Suminski's avatar Maciej Suminski

Added TOOL_MANAGER & ACTION_MANAGER::RunAction( const TOOL_ACTION aAction ).

Selection clearing is invoked using TOOL_ACTION object rather than its name.
parent 94cfed4b
......@@ -94,12 +94,20 @@ bool ACTION_MANAGER::RunAction( const std::string& aActionName ) const
if( it == m_actionNameIndex.end() )
return false; // no action with given name found
runAction( it->second );
RunAction( it->second );
return true;
}
void ACTION_MANAGER::RunAction( const TOOL_ACTION* aAction ) const
{
TOOL_EVENT event = aAction->MakeEvent();
m_toolMgr->ProcessEvent( event );
}
bool ACTION_MANAGER::RunHotKey( int aHotKey ) const
{
std::map<int, TOOL_ACTION*>::const_iterator it = m_actionHotKeys.find( aHotKey );
......@@ -107,7 +115,7 @@ bool ACTION_MANAGER::RunHotKey( int aHotKey ) const
if( it == m_actionHotKeys.end() )
return false; // no appropriate action found for the hotkey
runAction( it->second );
RunAction( it->second );
return true;
}
......@@ -117,11 +125,3 @@ void ACTION_MANAGER::ClearHotKey( int aHotKey )
{
m_actionHotKeys.erase( aHotKey );
}
void ACTION_MANAGER::runAction( const TOOL_ACTION* aAction ) const
{
TOOL_EVENT event = aAction->MakeEvent();
m_toolMgr->ProcessEvent( event );
}
......@@ -196,6 +196,12 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName )
}
void TOOL_MANAGER::RunAction( const TOOL_ACTION& aAction )
{
m_actionMgr->RunAction( &aAction );
}
bool TOOL_MANAGER::invokeTool( TOOL_BASE* aTool )
{
wxASSERT( aTool != NULL );
......
......@@ -81,6 +81,14 @@ public:
*/
bool RunAction( const std::string& aActionName ) const;
/**
* Function RunAction()
* Prepares an appropriate event and sends it to the destination specified in a TOOL_ACTION
* object.
* @param aAction is the action to be run.
*/
void RunAction( const TOOL_ACTION* aAction ) const;
/**
* Function RunHotKey()
* Runs an action associated with a hotkey (if there is one available).
......@@ -108,14 +116,6 @@ private:
///> Map for indexing actions by their hotkeys
std::map<int, TOOL_ACTION*> m_actionHotKeys;
/**
* Function runAction()
* Prepares an appropriate event and sends it to the destination specified in a TOOL_ACTION
* object.
* @param aAction is the action to be run.
*/
void runAction( const TOOL_ACTION* aAction ) const;
};
#endif /* ACTION_MANAGER_H_ */
......@@ -101,13 +101,21 @@ public:
/**
* Function RunAction()
* Runs the specified action. The common format is "application.ToolName.Action".
* Runs the specified action. The common format for action names is "application.ToolName.Action".
*
* @param aActionName is the name of action to be invoked.
* @return True if the action finished successfully, false otherwise.
*/
bool RunAction( const std::string& aActionName );
/**
* Function RunAction()
* Runs the specified action.
*
* @param aAction is the action to be invoked.
*/
void RunAction( const TOOL_ACTION& aAction );
/**
* Function FindTool()
* Searches for a tool with given ID.
......
......@@ -1458,6 +1458,7 @@ void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
if( IsGalCanvasActive() )
{
std::string actionName = COMMON_ACTIONS::TranslateLegacyId( id );
if( !actionName.empty() )
m_toolManager->RunAction( actionName );
......
......@@ -172,7 +172,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent )
}
if( unselect )
m_toolMgr->RunAction( "pcbnew.InteractiveSelection.Clear" );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
RN_DATA* ratsnest = getModel<BOARD>( PCB_T )->GetRatsnest();
ratsnest->ClearSimple();
......@@ -230,7 +230,7 @@ int EDIT_TOOL::Properties( TOOL_EVENT& aEvent )
getModel<BOARD>( PCB_T )->GetRatsnest()->Recalculate();
if( unselect )
m_toolMgr->RunAction( "pcbnew.InteractiveSelection.Clear" );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
}
setTransitions();
......@@ -277,7 +277,7 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent )
getModel<BOARD>( PCB_T )->GetRatsnest()->Recalculate();
if( unselect )
m_toolMgr->RunAction( "pcbnew.InteractiveSelection.Clear" );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
return 0;
}
......@@ -321,7 +321,7 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent )
getModel<BOARD>( PCB_T )->GetRatsnest()->Recalculate();
if( unselect )
m_toolMgr->RunAction( "pcbnew.InteractiveSelection.Clear" );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
return 0;
}
......@@ -339,7 +339,7 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent )
PCB_EDIT_FRAME* editFrame = static_cast<PCB_EDIT_FRAME*>( m_toolMgr->GetEditFrame() );
// As we are about to remove items, they have to be removed from the selection first
m_toolMgr->RunAction( "pcbnew.InteractiveSelection.Clear" );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
// Save them
for( unsigned int i = 0; i < selectedItems.GetCount(); ++i )
......@@ -461,7 +461,7 @@ bool EDIT_TOOL::makeSelection( const SELECTION_TOOL::SELECTION& aSelection )
if( aSelection.Empty() )
{
// Try to find an item that could be modified
m_toolMgr->RunAction( "pcbnew.InteractiveSelection.Single" );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionSingle );
if( aSelection.Empty() )
{
......
......@@ -123,7 +123,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
if( m_selection.Empty() )
selectSingle( evt->Position() );
m_toolMgr->RunAction( "pcbnew.InteractiveEdit.properties" );
m_toolMgr->RunAction( COMMON_ACTIONS::properties );
}
// drag with LMB? Select multiple objects (or at least draw a selection box) or drag them
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment