From 1d8730752ce3dc58cf328a6ad512574aad8e229f Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 2 Mar 2017 12:02:10 +0100 Subject: [PATCH] Restore valid force cursor setting before saving VIEW_CONTROLS settings There are times, when TOOL_MANAGER has to force cursor position to make tools work as expected (e.g. when popping up a menu, so tools get the right click position instead of current position pointing to an entry in the menu). If another tool is invoked, VIEW_CONTROLS settings have to be stored in the TOOL_STATE object. In such case, it is necessary to revert the force cursor setting when saving VIEW_CONTROLS settings. Fixes: lp:1668712 * https://bugs.launchpad.net/kicad/+bug/1668712 --- common/tool/tool_manager.cpp | 32 ++++++++++++++++++++------------ include/tool/tool_manager.h | 7 +++++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 5048da41c3..f4b7221e81 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -562,7 +562,7 @@ void TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent ) { // store the VIEW_CONTROLS settings if we launch a subtool if( GetCurrentToolState() == st ) - st->vcSettings = m_viewControls->GetSettings(); + saveViewControls( st ); st->Push(); } @@ -697,17 +697,7 @@ TOOL_MANAGER::ID_LIST::iterator TOOL_MANAGER::finishTool( TOOL_STATE* aState ) // Store the current VIEW_CONTROLS settings if( TOOL_STATE* state = GetCurrentToolState() ) - { - state->vcSettings = m_viewControls->GetSettings(); - - // If context menu has overridden the cursor position, restore the original one - // (see dispatchContextMenu()) - if( m_origCursor ) - { - state->vcSettings.m_forceCursorPosition = true; - state->vcSettings.m_forcedPosition = *m_origCursor; - } - } + saveViewControls( state ); if( !aState->Pop() ) { @@ -827,3 +817,21 @@ bool TOOL_MANAGER::isActive( TOOL_BASE* aTool ) // Just check if the tool is on the active tools stack return std::find( m_activeTools.begin(), m_activeTools.end(), aTool->GetId() ) != m_activeTools.end(); } + + +void TOOL_MANAGER::saveViewControls( TOOL_STATE* aState ) +{ + aState->vcSettings = m_viewControls->GetSettings(); + + // If context menu has overridden the cursor position, reaStateore the original one + // (see dispatchContextMenu()) + if( m_origCursor ) + { + aState->vcSettings.m_forceCursorPosition = true; + aState->vcSettings.m_forcedPosition = *m_origCursor; + } + else + { + aState->vcSettings.m_forceCursorPosition = false; + } +} diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index da2552952c..6e93c77389 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -450,6 +450,13 @@ private: */ bool isActive( TOOL_BASE* aTool ); + /** + * Function saveViewControls() + * Saves the VIEW_CONTROLS settings to the tool state object. If VIEW_CONTROLS + * settings are affected by TOOL_MANAGER, the original settings are saved. + */ + void saveViewControls( TOOL_STATE* aState ); + /// Index of registered tools current states, associated by tools' objects. TOOL_STATE_MAP m_toolState;