TOOL_ACTIONs are automagically registered by TOOL_MANAGER upon its construction.

This commit is contained in:
Maciej Suminski 2014-07-09 11:22:42 +02:00
parent f5325f8d79
commit 3fd26b6dd2
4 changed files with 7 additions and 29 deletions

View File

@ -44,8 +44,6 @@ ACTION_MANAGER::~ACTION_MANAGER()
void ACTION_MANAGER::RegisterAction( TOOL_ACTION* aAction )
{
// Check if the TOOL_ACTION was not registered before
assert( aAction->GetId() == -1 );
// TOOL_ACTIONs are supposed to be named [appName.]toolName.actionName (with dots between)
// action name without specifying at least toolName is not valid
assert( aAction->GetName().find( '.', 0 ) != std::string::npos );
@ -54,15 +52,14 @@ void ACTION_MANAGER::RegisterAction( TOOL_ACTION* aAction )
assert( m_actionNameIndex.find( aAction->m_name ) == m_actionNameIndex.end() );
assert( m_actionIdIndex.find( aAction->m_id ) == m_actionIdIndex.end() );
aAction->setId( MakeActionId( aAction->m_name ) );
if( aAction->m_id == -1 )
aAction->m_id = MakeActionId( aAction->m_name );
m_actionNameIndex[aAction->m_name] = aAction;
m_actionIdIndex[aAction->m_id] = aAction;
if( aAction->HasHotKey() )
m_actionHotKeys[aAction->m_currentHotKey].push_back( aAction );
aAction->setActionMgr( this );
}
@ -71,10 +68,6 @@ void ACTION_MANAGER::UnregisterAction( TOOL_ACTION* aAction )
m_actionNameIndex.erase( aAction->m_name );
m_actionIdIndex.erase( aAction->m_id );
// Indicate that the ACTION_MANAGER no longer care about the object
aAction->setActionMgr( NULL );
aAction->setId( -1 );
if( aAction->HasHotKey() )
{
std::list<TOOL_ACTION*>& actions = m_actionHotKeys[aAction->m_currentHotKey];

View File

@ -99,6 +99,11 @@ TOOL_MANAGER::TOOL_MANAGER() :
m_model( NULL ), m_view( NULL ), m_viewControls( NULL ), m_editFrame( NULL )
{
m_actionMgr = new ACTION_MANAGER( this );
// Register known actions
std::list<TOOL_ACTION*>& actionList = GetActionList();
BOOST_FOREACH( TOOL_ACTION* action, actionList )
RegisterAction( action );
}

View File

@ -189,18 +189,6 @@ public:
private:
friend class ACTION_MANAGER;
/// Assigns an unique identifier. It is given by an instance of ACTION_MANAGER.
void setId( int aId )
{
m_id = aId;
}
/// Assigns ACTION_MANAGER object that handles the TOOL_ACTION.
void setActionMgr( ACTION_MANAGER* aManager )
{
m_actionMgr = aManager;
}
/// Name of the action (convention is: app.[tool.]action.name)
std::string m_name;
@ -225,9 +213,6 @@ private:
/// Unique ID for fast matching. Assigned by ACTION_MANAGER.
int m_id;
/// Action manager that handles this TOOL_ACTION.
ACTION_MANAGER* m_actionMgr;
/// Origin of the action
// const TOOL_BASE* m_origin;

View File

@ -60,11 +60,6 @@ void PCB_EDIT_FRAME::setupTools()
wxCommandEventHandler( PCB_EDIT_FRAME::onGenericCommand ), NULL, this );
#endif
// Register actions
std::list<TOOL_ACTION*>& actionList = m_toolManager->GetActionList();
BOOST_FOREACH( TOOL_ACTION* action, actionList )
m_toolManager->RegisterAction( action );
// Register tools
m_toolManager->RegisterTool( new SELECTION_TOOL );
m_toolManager->RegisterTool( new ROUTER_TOOL );