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_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 );

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
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;
}

View File

@ -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()