From 18898fe807aa5f57bbed9e410498c0872c71f68a Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 21 Nov 2014 11:28:34 +0100 Subject: [PATCH] tool: Added a generic parameter for RunAction(). --- common/tool/tool_manager.cpp | 24 ++++++++++-------------- include/tool/tool_event.h | 33 ++++++++++++++++++++++++++++++--- include/tool/tool_manager.h | 8 ++++++-- 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 6aec0a9002..f3705d8ac8 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -292,21 +292,19 @@ void TOOL_MANAGER::UnregisterAction( TOOL_ACTION* aAction ) } -bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow ) +bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* aParam ) { TOOL_ACTION* action = m_actionMgr->FindAction( aActionName ); if( action ) { + TOOL_EVENT event = action->MakeEvent(); + event.SetParameter( aParam ); + if( aNow ) - { - TOOL_EVENT event = action->MakeEvent(); ProcessEvent( event ); - } else - { - PostEvent( action->MakeEvent() ); - } + PostEvent( event ); return true; } @@ -315,17 +313,15 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow ) } -void TOOL_MANAGER::RunAction( const TOOL_ACTION& aAction, bool aNow ) +void TOOL_MANAGER::RunAction( const TOOL_ACTION& aAction, bool aNow, void* aParam ) { + TOOL_EVENT event = aAction.MakeEvent(); + event.SetParameter( aParam ); + if( aNow ) - { - TOOL_EVENT event = aAction.MakeEvent(); ProcessEvent( event ); - } else - { - PostEvent( aAction.MakeEvent() ); - } + PostEvent( event ); } diff --git a/include/tool/tool_event.h b/include/tool/tool_event.h index 21ee2afd68..435451b676 100644 --- a/include/tool/tool_event.h +++ b/include/tool/tool_event.h @@ -165,7 +165,8 @@ public: m_scope( aScope ), m_mouseButtons( 0 ), m_keyCode( 0 ), - m_modifiers( 0 ) {} + m_modifiers( 0 ), + m_param( NULL ) {} TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory, TOOL_ACTIONS aAction, int aExtraParam, TOOL_ACTION_SCOPE aScope = AS_GLOBAL ) : @@ -174,7 +175,8 @@ public: m_scope( aScope ), m_mouseButtons( 0 ), m_keyCode( 0 ), - m_modifiers( 0 ) + m_modifiers( 0 ), + m_param( NULL ) { if( aCategory == TC_MOUSE ) { @@ -202,7 +204,8 @@ public: m_scope( aScope ), m_mouseButtons( 0 ), m_keyCode( 0 ), - m_modifiers( 0 ) + m_modifiers( 0 ), + m_param( NULL ) { if( aCategory == TC_COMMAND || aCategory == TC_MESSAGE ) m_commandStr = aExtraParam; @@ -352,6 +355,27 @@ public: */ bool IsAction( const TOOL_ACTION* aAction ) const; + /** + * Function Parameter() + * Returns a non-standard parameter assigned to the event. Its meaning depends on the + * target tool. + */ + void* Parameter() const + { + return m_param; + } + + /** + * Function SetParameter() + * Sets a non-standard parameter assigned to the event. Its meaning depends on the + * target tool. + * @param aParam is the new parameter. + */ + void SetParameter(void* aParam) + { + m_param = aParam; + } + boost::optional GetCommandId() const { return m_commandId; @@ -388,6 +412,9 @@ private: ///> State of key modifierts (Ctrl/Alt/etc.) int m_modifiers; + ///> Generic parameter used for passing non-standard data. + void* m_param; + boost::optional m_commandId; boost::optional m_commandStr; }; diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index 9e2dfdee50..3805fe85a8 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -108,9 +108,11 @@ public: * @param aActionName is the name of action to be invoked. * @param aNow decides if the action has to be run immediately or after the current coroutine * is preemptied. + * @param aParam is an optional parameter that might be used by the invoked action. Its meaning + * depends on the action. * @return False if the action was not found. */ - bool RunAction( const std::string& aActionName, bool aNow = false ); + bool RunAction( const std::string& aActionName, bool aNow = false, void* aParam = NULL ); /** * Function RunAction() @@ -119,8 +121,10 @@ public: * @param aAction is the action to be invoked. * @param aNow decides if the action has to be run immediately or after the current coroutine * is preemptied. + * @param aParam is an optional parameter that might be used by the invoked action. Its meaning + * depends on the action. */ - void RunAction( const TOOL_ACTION& aAction, bool aNow = false ); + void RunAction( const TOOL_ACTION& aAction, bool aNow = false, void* aParam = NULL ); /** * Function FindTool()