diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 3f3039cba4..e3e9d10758 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -111,7 +111,6 @@ void SELECTION_TOOL::Reset( RESET_REASON aReason ) // Remove pointers to the selected items from containers // without changing their properties (as they are already deleted // while a new board is loaded) - m_selection.group->Clear(); m_selection.clear(); } else @@ -120,6 +119,7 @@ void SELECTION_TOOL::Reset( RESET_REASON aReason ) m_frame = getEditFrame(); m_locked = true; + m_preliminary = true; // Reinsert the VIEW_GROUP, in case it was removed from the VIEW getView()->Remove( m_selection.group ); @@ -155,10 +155,13 @@ 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 ) ) { - if( m_selection.Empty() ) + bool emptySelection = m_selection.Empty(); + + if( emptySelection ) selectCursor( evt->Position() ); generateMenu(); + m_preliminary = emptySelection; } // double click? Display the properties window @@ -175,10 +178,14 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { if( m_additive ) { + m_preliminary = false; + selectMultiple(); } else if( m_selection.Empty() ) { + m_preliminary = false; + // There is nothing selected, so try to select something if( !selectCursor( getView()->ToWorld( getViewControls()->GetMousePosition() ), false ) ) { @@ -249,6 +256,12 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { selectNet( *evt ); } + + else if( evt->Action() == TA_CONTEXT_MENU_CLOSED ) + { + if( m_preliminary ) + clearSelection(); + } } // This tool is supposed to be active forever diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index fffa8790ac..fce960470d 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -122,8 +122,10 @@ public: * * Returns the set of currently selected items. */ - const SELECTION& GetSelection() const + const SELECTION& GetSelection() { + // The selected items list has been requested, so it is no longer preliminary + m_preliminary = false; return m_selection; } @@ -356,6 +358,9 @@ private: /// Can other tools modify locked items. bool m_locked; + /// Determines if the selection is preliminary or final. + bool m_preliminary; + /// Conditions for specific context menu entries. std::deque m_menuConditions; };