From af976b2d36e0b4bd323c3b6da3081bb794f50d7b Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 28 Nov 2013 15:24:19 +0100 Subject: [PATCH] Automatic unregistration of tool actions during ACTION_MANAGER destruction. --- common/tool/action_manager.cpp | 7 +++++++ include/tool/action_manager.h | 6 ++++++ pcbnew/tools/pcb_tools.cpp | 7 +------ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/common/tool/action_manager.cpp b/common/tool/action_manager.cpp index be90ef055f..63aa99f8d8 100644 --- a/common/tool/action_manager.cpp +++ b/common/tool/action_manager.cpp @@ -34,6 +34,13 @@ ACTION_MANAGER::ACTION_MANAGER( TOOL_MANAGER* aToolManager ) : } +ACTION_MANAGER::~ACTION_MANAGER() +{ + while( !m_actionIdIndex.empty() ) + UnregisterAction( m_actionIdIndex.begin()->second ); +} + + void ACTION_MANAGER::RegisterAction( TOOL_ACTION* aAction ) { assert( aAction->GetId() == -1 ); // Check if the TOOL_ACTION was not registered before diff --git a/include/tool/action_manager.h b/include/tool/action_manager.h index 239ad606b7..dbcb7b33b6 100644 --- a/include/tool/action_manager.h +++ b/include/tool/action_manager.h @@ -47,6 +47,12 @@ public: */ ACTION_MANAGER( TOOL_MANAGER* aToolManager ); + /** + * Destructor. + * Unregisters every registered action. + */ + ~ACTION_MANAGER(); + /** * Function RegisterAction() * Adds a tool action to the manager and sets it up. After that is is possible to invoke diff --git a/pcbnew/tools/pcb_tools.cpp b/pcbnew/tools/pcb_tools.cpp index f3749a0c94..2f9676cb94 100644 --- a/pcbnew/tools/pcb_tools.cpp +++ b/pcbnew/tools/pcb_tools.cpp @@ -61,13 +61,8 @@ void PCB_EDIT_FRAME::setupTools() void PCB_EDIT_FRAME::destroyTools() { - m_toolManager->UnregisterAction( &COMMON_ACTIONS::moveActivate ); - m_toolManager->UnregisterAction( &COMMON_ACTIONS::selectionActivate ); - m_toolManager->UnregisterAction( &COMMON_ACTIONS::rotate ); - m_toolManager->UnregisterAction( &COMMON_ACTIONS::flip ); - - delete m_toolDispatcher; delete m_toolManager; + delete m_toolDispatcher; }