From 0ac6e0614f567674173551bf54e5bbd823b04994 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 5 Dec 2013 14:48:44 +0100 Subject: [PATCH] ClearHotKey() function. --- common/tool/action_manager.cpp | 12 ++++++++++++ include/tool/action_manager.h | 13 ++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/common/tool/action_manager.cpp b/common/tool/action_manager.cpp index d38ad1eccf..fde03fb510 100644 --- a/common/tool/action_manager.cpp +++ b/common/tool/action_manager.cpp @@ -53,7 +53,13 @@ void ACTION_MANAGER::RegisterAction( TOOL_ACTION* aAction ) m_actionIdIndex[aAction->m_id] = aAction; if( aAction->HasHotKey() ) + { + // Duplication of hot keys leads to unexpected behaviour + // The right way to change a hotkey is to use ACTION_MANAGER::ClearHotKey() first + assert( m_actionHotKeys.find( aAction->m_currentHotKey ) == m_actionHotKeys.end() ); + m_actionHotKeys[aAction->m_currentHotKey] = aAction; + } aAction->setActionMgr( this ); } @@ -107,6 +113,12 @@ bool ACTION_MANAGER::RunHotKey( int aHotKey ) const } +void ACTION_MANAGER::ClearHotKey( int aHotKey ) +{ + m_actionHotKeys.erase( aHotKey ); +} + + void ACTION_MANAGER::runAction( const TOOL_ACTION* aAction ) const { TOOL_EVENT event = aAction->MakeEvent(); diff --git a/include/tool/action_manager.h b/include/tool/action_manager.h index dbcb7b33b6..fa66a23eba 100644 --- a/include/tool/action_manager.h +++ b/include/tool/action_manager.h @@ -81,18 +81,21 @@ public: */ bool RunAction( const std::string& aActionName ) const; - // TODO to be considered - // bool RunAction( int aActionId ) const; - // bool RunAction( TOOL_ACTION* aAction ) const; - /** * Function RunHotKey() * Runs an action associated with a hotkey (if there is one available). - * @param aHotKey is the hotkey to be served. + * @param aHotKey is the hotkey to be handled. * @return True if there was an action associated with the hotkey, false otherwise. */ bool RunHotKey( int aHotKey ) const; + /** + * Function ClearHotKey() + * Removes an action associated with a hotkey. + * @param aHotKey is the hotkey to be cleared. + */ + void ClearHotKey( int aHotKey ); + private: ///> Tool manager needed to run actions TOOL_MANAGER* m_toolMgr;