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
This commit is contained in:
Jeff Young 2018-01-01 20:50:50 +00:00 committed by Wayne Stambaugh
parent 44d4559f84
commit f76e7568bc
3 changed files with 24 additions and 14 deletions

View File

@ -674,10 +674,11 @@ void TOOL_MANAGER::dispatchContextMenu( const TOOL_EVENT& aEvent )
m_menuActive = false; m_menuActive = false;
m_viewControls->WarpCursor( cursor, true, false ); // Warp the cursor as long as the menu wasn't clicked out of
if( menu->GetSelected() >= 0 )
// If nothing was chosen from the context menu, we must notify the tool as well m_viewControls->WarpCursor( cursor, true, false );
if( menu->GetSelected() < 0 ) // Otherwise notify the tool of a cancelled menu
else
{ {
TOOL_EVENT evt( TC_COMMAND, TA_CONTEXT_MENU_CHOICE, -1 ); TOOL_EVENT evt( TC_COMMAND, TA_CONTEXT_MENU_CHOICE, -1 );
evt.SetParameter( m ); evt.SetParameter( m );

View File

@ -271,13 +271,16 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
// right click? if there is any object - show the context menu // right click? if there is any object - show the context menu
else if( evt->IsClick( BUT_RIGHT ) ) else if( evt->IsClick( BUT_RIGHT ) )
{ {
bool selectionCancelled = false;
if( m_selection.Empty() ) if( m_selection.Empty() )
{ {
selectPoint( evt->Position() ); selectPoint( evt->Position(), false, &selectionCancelled );
m_selection.SetIsHover( true ); m_selection.SetIsHover( true );
} }
m_menu.ShowContextMenu( m_selection ); if( !selectionCancelled )
m_menu.ShowContextMenu( m_selection );
} }
// double click? Display the properties window // double click? Display the properties window
@ -432,7 +435,9 @@ const GENERAL_COLLECTORS_GUIDE SELECTION_TOOL::getCollectorsGuide() const
return guide; 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; BOARD_ITEM* item;
auto guide = getCollectorsGuide(); auto guide = getCollectorsGuide();
@ -460,12 +465,10 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag )
{ {
clearSelection(); clearSelection();
} }
return false; return false;
case 1: case 1:
toggleSelection( collector[0] ); toggleSelection( collector[0] );
return true; return true;
default: default:
@ -476,7 +479,6 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag )
if( collector.GetCount() == 1 ) if( collector.GetCount() == 1 )
{ {
toggleSelection( collector[0] ); toggleSelection( collector[0] );
return true; return true;
} }
else if( collector.GetCount() > 1 ) else if( collector.GetCount() > 1 )
@ -491,9 +493,14 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag )
if( item ) if( item )
{ {
toggleSelection( item ); toggleSelection( item );
return true; return true;
} }
else
{
if( aSelectionCancelledFlag )
*aSelectionCancelledFlag = true;
return false;
}
} }
break; break;
} }

View File

@ -145,11 +145,13 @@ private:
* place, there is a menu displayed that allows to choose the item. * place, there is a menu displayed that allows to choose the item.
* *
* @param aWhere is the place where the item should be selected. * @param aWhere is the place where the item should be selected.
* @param aAllowDisambiguation decides what to do in case of disambiguation. If true, then * @param aOnDrag indicates whether a drag operation is being performed.
* a menu is shown, otherise function finishes without selecting anything. * @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. * @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() * Function selectCursor()