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

Selection clearing is invoked using TOOL_ACTION object rather than its name.
This commit is contained in:
Maciej Suminski 2014-02-28 15:46:05 +01:00
parent 94cfed4b9e
commit c5c83bd271
7 changed files with 41 additions and 26 deletions

View File

@ -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 );
}

View File

@ -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 );

View File

@ -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_ */

View File

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

View File

@ -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 );

View File

@ -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() )
{

View File

@ -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