diff --git a/eeschema/sch_collectors.h b/eeschema/sch_collectors.h index 0893c43eaf..38da98a4bc 100644 --- a/eeschema/sch_collectors.h +++ b/eeschema/sch_collectors.h @@ -131,7 +131,8 @@ public: /** * 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 ); } @@ -193,6 +194,10 @@ public: * @return True if the collection is a draggable junction. */ bool IsDraggableJunction() const; + +public: + wxString m_MenuTitle; // The title of selection disambiguation menu (if needed) + bool m_MenuCancelled; // Indicates selection disambiguation menu was cancelled }; diff --git a/eeschema/tools/sch_selection_tool.cpp b/eeschema/tools/sch_selection_tool.cpp index c6632bb320..8a43d26270 100644 --- a/eeschema/tools/sch_selection_tool.cpp +++ b/eeschema/tools/sch_selection_tool.cpp @@ -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( 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 ) *aSelectionCancelledFlag = true; @@ -442,13 +446,14 @@ int SCH_SELECTION_TOOL::SelectionMenu( const TOOL_EVENT& aEvent ) { SCH_COLLECTOR* collector = aEvent.Parameter(); - doSelectionMenu( collector, wxEmptyString ); + if( !doSelectionMenu( collector ) ) + collector->m_MenuCancelled = true; 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; #if 1 @@ -471,7 +476,7 @@ bool SCH_SELECTION_TOOL::doSelectionMenu( SCH_COLLECTOR* aCollector, const wxStr m_frame->GetScreen()->SetCurItem( nullptr ); int idx = m_frame->GetPopupMenuSelectionFromUser( selectMenu ); - if( idx == wxNOT_FOUND ) + if( idx == wxID_NONE ) { m_frame->GetScreen()->SetCurItem( nullptr ); return false; @@ -502,8 +507,8 @@ bool SCH_SELECTION_TOOL::doSelectionMenu( SCH_COLLECTOR* aCollector, const wxStr menu.Add( menuText, i + 1, item->GetMenuImage() ); } - if( aTitle.Length() ) - menu.SetTitle( aTitle ); + if( aCollector->m_MenuTitle.Length() ) + menu.SetTitle( aCollector->m_MenuTitle ); menu.SetIcon( info_xpm ); menu.DisplayTitle( true ); diff --git a/eeschema/tools/sch_selection_tool.h b/eeschema/tools/sch_selection_tool.h index 3a8d31eea6..bd1a04f20c 100644 --- a/eeschema/tools/sch_selection_tool.h +++ b/eeschema/tools/sch_selection_tool.h @@ -133,10 +133,9 @@ private: * 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 * the picked item. - * @param aTitle (optional) Allows the menu to be titled (ie: "Clarify Selection"). * @return true if an item was picked */ - bool doSelectionMenu( SCH_COLLECTOR* aItems, const wxString& aTitle ); + bool doSelectionMenu( SCH_COLLECTOR* aItems ); /** * Function clearSelection()