From 4f0c9b6b20f2bfa0deb69b310221ce00bbe471e1 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 12 Feb 2018 10:17:35 +0100 Subject: [PATCH] Fix double disambiguation menu when removing footprints Second disambiguation menu was caused by another call to SELECTION_TOOL::RequestSelection() meant to get the list of connected tracks. When there were only footprints under the cursor, it asked the user again to pick an item to remove. Fixes: lp:1748521 * https://bugs.launchpad.net/kicad/+bug/1748521 --- include/tool/selection.h | 17 +++++++++++++++++ pcbnew/tools/edit_tool.cpp | 19 ++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/include/tool/selection.h b/include/tool/selection.h index 28e7d8d0e1..39e56fcd4f 100644 --- a/include/tool/selection.h +++ b/include/tool/selection.h @@ -168,6 +168,23 @@ public: return nullptr; } + /** + * Checks if there is at least one item of requested kind. + * + * @param aType is the type to check for. + * @return True if there is at least one item of such kind. + */ + bool HasType( KICAD_T aType ) const + { + for( auto item : m_items ) + { + if( item->Type() == aType ) + return true; + } + + return false; + } + virtual const VIEW_GROUP::ITEMS updateDrawList() const override; bool HasReferencePoint() const diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index a8fe42ba88..6278911fea 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -843,29 +843,26 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) if( m_selectionTool->CheckLock() == SELECTION_LOCKED ) return 0; - if( selection.Empty() ) - return 0; - // is this "alternative" remove? - const bool isAlt = aEvent.Parameter() == - (int) PCB_ACTIONS::REMOVE_FLAGS::ALT; + const bool isAlt = aEvent.Parameter() == (int) PCB_ACTIONS::REMOVE_FLAGS::ALT; - // in "alternative" mode, deletion is not just a simple list - // of selected items, it is: - // - whole tracks, not just segments - if( isAlt && selection.IsHover() ) + // in "alternative" mode, deletion is not just a simple list of selected items, + // it removes whole tracks, not just segments + if( isAlt && selection.IsHover() + && ( selection.HasType( PCB_TRACE_T ) || selection.HasType( PCB_VIA_T ) ) ) { m_toolMgr->RunAction( PCB_ACTIONS::selectConnection, true ); selection = m_selectionTool->RequestSelection( SELECTION_DELETABLE | SELECTION_SANITIZE_PADS ); } + if( selection.Empty() ) + return 0; + // As we are about to remove items, they have to be removed from the selection first m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); for( auto item : selection ) - { m_commit->Remove( item ); - } m_commit->Push( _( "Delete" ) );