From 7c812664f36170a3c2549f5e11cf64f5f0795db0 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 9 Jul 2014 11:22:42 +0200 Subject: [PATCH] TOOL_ACTIONs are automagically registered by TOOL_MANAGER upon its construction. --- common/tool/action_manager.cpp | 11 ++--------- common/tool/tool_manager.cpp | 5 +++++ include/tool/tool_action.h | 15 --------------- pcbnew/tools/pcb_tools.cpp | 5 ----- 4 files changed, 7 insertions(+), 29 deletions(-) diff --git a/common/tool/action_manager.cpp b/common/tool/action_manager.cpp index 444143b0fb..b065cb2d55 100644 --- a/common/tool/action_manager.cpp +++ b/common/tool/action_manager.cpp @@ -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& actions = m_actionHotKeys[aAction->m_currentHotKey]; diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 605f8505b3..abfd66b566 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -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& actionList = GetActionList(); + BOOST_FOREACH( TOOL_ACTION* action, actionList ) + RegisterAction( action ); } diff --git a/include/tool/tool_action.h b/include/tool/tool_action.h index 4097fd2f7f..152cf52928 100644 --- a/include/tool/tool_action.h +++ b/include/tool/tool_action.h @@ -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; diff --git a/pcbnew/tools/pcb_tools.cpp b/pcbnew/tools/pcb_tools.cpp index cde76c1591..df0fc1a4ab 100644 --- a/pcbnew/tools/pcb_tools.cpp +++ b/pcbnew/tools/pcb_tools.cpp @@ -60,11 +60,6 @@ void PCB_EDIT_FRAME::setupTools() wxCommandEventHandler( PCB_EDIT_FRAME::onGenericCommand ), NULL, this ); #endif - // Register actions - std::list& 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 );