From f76e7568bcffdae3b5ae63e841858222b3dfce55 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 1 Jan 2018 20:50:50 +0000 Subject: [PATCH] Don't warp cursor if the disambiguation menu is cancelled. Also fixes the empty-selection-context-menu coming up after a cancelled disambiguation menu. Fixes: lp:1738339 * https://bugs.launchpad.net/kicad/+bug/1738339 --- common/tool/tool_manager.cpp | 9 +++++---- pcbnew/tools/selection_tool.cpp | 21 ++++++++++++++------- pcbnew/tools/selection_tool.h | 8 +++++--- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index e3da75ec6a..669b62f11c 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -674,10 +674,11 @@ void TOOL_MANAGER::dispatchContextMenu( const TOOL_EVENT& aEvent ) m_menuActive = false; - m_viewControls->WarpCursor( cursor, true, false ); - - // If nothing was chosen from the context menu, we must notify the tool as well - if( menu->GetSelected() < 0 ) + // Warp the cursor as long as the menu wasn't clicked out of + if( menu->GetSelected() >= 0 ) + m_viewControls->WarpCursor( cursor, true, false ); + // Otherwise notify the tool of a cancelled menu + else { TOOL_EVENT evt( TC_COMMAND, TA_CONTEXT_MENU_CHOICE, -1 ); evt.SetParameter( m ); diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 2584b095c1..230a023de4 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -271,13 +271,16 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) // right click? if there is any object - show the context menu else if( evt->IsClick( BUT_RIGHT ) ) { + bool selectionCancelled = false; + if( m_selection.Empty() ) { - selectPoint( evt->Position() ); + selectPoint( evt->Position(), false, &selectionCancelled ); m_selection.SetIsHover( true ); } - m_menu.ShowContextMenu( m_selection ); + if( !selectionCancelled ) + m_menu.ShowContextMenu( m_selection ); } // double click? Display the properties window @@ -432,7 +435,9 @@ const GENERAL_COLLECTORS_GUIDE SELECTION_TOOL::getCollectorsGuide() const return guide; } -bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag ) + +bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag, + bool* aSelectionCancelledFlag ) { BOARD_ITEM* item; auto guide = getCollectorsGuide(); @@ -460,12 +465,10 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag ) { clearSelection(); } - return false; case 1: toggleSelection( collector[0] ); - return true; default: @@ -476,7 +479,6 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag ) if( collector.GetCount() == 1 ) { toggleSelection( collector[0] ); - return true; } else if( collector.GetCount() > 1 ) @@ -491,9 +493,14 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag ) if( item ) { toggleSelection( item ); - return true; } + else + { + if( aSelectionCancelledFlag ) + *aSelectionCancelledFlag = true; + return false; + } } break; } diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index c0cee1fbc9..83a2f7ca60 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -145,11 +145,13 @@ private: * place, there is a menu displayed that allows to choose the item. * * @param aWhere is the place where the item should be selected. - * @param aAllowDisambiguation decides what to do in case of disambiguation. If true, then - * a menu is shown, otherise function finishes without selecting anything. + * @param aOnDrag indicates whether a drag operation is being performed. + * @param aSelectionCancelledFlag allows the function to inform its caller that a selection + * was cancelled (for instance, by clicking outside of the disambiguation menu). * @return True if an item was selected, false otherwise. */ - bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false ); + bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false, + bool* aSelectionCancelledFlag = NULL ); /** * Function selectCursor()