Cleanup problems with fighting event loops.

This commit is contained in:
Jeff Young 2019-04-25 21:25:44 +01:00
parent 8049c07a34
commit f9dd1324da
3 changed files with 18 additions and 9 deletions

View File

@ -131,7 +131,8 @@ public:
/** /**
* Constructor SCH_COLLECTOR * Constructor SCH_COLLECTOR
*/ */
SCH_COLLECTOR( const KICAD_T* aScanTypes = SCH_COLLECTOR::AllItems ) SCH_COLLECTOR( const KICAD_T* aScanTypes = SCH_COLLECTOR::AllItems ) :
m_MenuCancelled( false )
{ {
SetScanTypes( aScanTypes ); SetScanTypes( aScanTypes );
} }
@ -193,6 +194,10 @@ public:
* @return True if the collection is a draggable junction. * @return True if the collection is a draggable junction.
*/ */
bool IsDraggableJunction() const; bool IsDraggableJunction() const;
public:
wxString m_MenuTitle; // The title of selection disambiguation menu (if needed)
bool m_MenuCancelled; // Indicates selection disambiguation menu was cancelled
}; };

View File

@ -259,7 +259,11 @@ SCH_ITEM* SCH_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, const KICAD_T
// If still more than one item we're going to have to ask the user. // If still more than one item we're going to have to ask the user.
if( collector.GetCount() > 1 ) if( collector.GetCount() > 1 )
{ {
if( !doSelectionMenu( &collector, _( "Clarify Selection" ) ) ) collector.m_MenuTitle = _( "Clarify Selection" );
// Must call selectionMenu via RunAction() to avoid event-loop contention
m_toolMgr->RunAction( SCH_ACTIONS::selectionMenu, true, &collector );
if( collector.m_MenuCancelled )
{ {
if( aSelectionCancelledFlag ) if( aSelectionCancelledFlag )
*aSelectionCancelledFlag = true; *aSelectionCancelledFlag = true;
@ -442,13 +446,14 @@ int SCH_SELECTION_TOOL::SelectionMenu( const TOOL_EVENT& aEvent )
{ {
SCH_COLLECTOR* collector = aEvent.Parameter<SCH_COLLECTOR*>(); SCH_COLLECTOR* collector = aEvent.Parameter<SCH_COLLECTOR*>();
doSelectionMenu( collector, wxEmptyString ); if( !doSelectionMenu( collector ) )
collector->m_MenuCancelled = true;
return 0; return 0;
} }
bool SCH_SELECTION_TOOL::doSelectionMenu( SCH_COLLECTOR* aCollector, const wxString& aTitle ) bool SCH_SELECTION_TOOL::doSelectionMenu( SCH_COLLECTOR* aCollector )
{ {
SCH_ITEM* current = nullptr; SCH_ITEM* current = nullptr;
#if 1 #if 1
@ -471,7 +476,7 @@ bool SCH_SELECTION_TOOL::doSelectionMenu( SCH_COLLECTOR* aCollector, const wxStr
m_frame->GetScreen()->SetCurItem( nullptr ); m_frame->GetScreen()->SetCurItem( nullptr );
int idx = m_frame->GetPopupMenuSelectionFromUser( selectMenu ); int idx = m_frame->GetPopupMenuSelectionFromUser( selectMenu );
if( idx == wxNOT_FOUND ) if( idx == wxID_NONE )
{ {
m_frame->GetScreen()->SetCurItem( nullptr ); m_frame->GetScreen()->SetCurItem( nullptr );
return false; return false;
@ -502,8 +507,8 @@ bool SCH_SELECTION_TOOL::doSelectionMenu( SCH_COLLECTOR* aCollector, const wxStr
menu.Add( menuText, i + 1, item->GetMenuImage() ); menu.Add( menuText, i + 1, item->GetMenuImage() );
} }
if( aTitle.Length() ) if( aCollector->m_MenuTitle.Length() )
menu.SetTitle( aTitle ); menu.SetTitle( aCollector->m_MenuTitle );
menu.SetIcon( info_xpm ); menu.SetIcon( info_xpm );
menu.DisplayTitle( true ); menu.DisplayTitle( true );

View File

@ -133,10 +133,9 @@ private:
* Allows the selection of a single item from a list via pop-up menu. The items are * Allows the selection of a single item from a list via pop-up menu. The items are
* highlighted on the canvas when hovered in the menu. The collector is trimmed to * highlighted on the canvas when hovered in the menu. The collector is trimmed to
* the picked item. * the picked item.
* @param aTitle (optional) Allows the menu to be titled (ie: "Clarify Selection").
* @return true if an item was picked * @return true if an item was picked
*/ */
bool doSelectionMenu( SCH_COLLECTOR* aItems, const wxString& aTitle ); bool doSelectionMenu( SCH_COLLECTOR* aItems );
/** /**
* Function clearSelection() * Function clearSelection()