diff --git a/common/tool/actions.cpp b/common/tool/actions.cpp index 79d1e29c1f..c9470d9a68 100644 --- a/common/tool/actions.cpp +++ b/common/tool/actions.cpp @@ -167,8 +167,7 @@ TOOL_ACTION ACTIONS::paste( "common.Interactive.paste", TOOL_ACTION ACTIONS::selectAll( "common.Interactive.selectAll", AS_GLOBAL, MD_CTRL + 'A', "", - _( "Select All" ), _( "Paste clipboard into schematic" ), - paste_xpm ); + _( "Select All" ), _( "Paste clipboard into schematic" ) ); TOOL_ACTION ACTIONS::pasteSpecial( "common.Interactive.pasteSpecial", AS_GLOBAL, 0, "", diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index 8a631683c0..5c62f1dbe5 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -335,6 +335,7 @@ void LIB_EDIT_FRAME::setupUIConditions() mgr->SetConditions( ACTIONS::paste, ENABLE( haveSymbolCond && SELECTION_CONDITIONS::Idle ) ); mgr->SetConditions( ACTIONS::doDelete, ENABLE( haveSymbolCond && SELECTION_CONDITIONS::NotEmpty ) ); mgr->SetConditions( ACTIONS::duplicate, ENABLE( haveSymbolCond && SELECTION_CONDITIONS::NotEmpty ) ); + mgr->SetConditions( ACTIONS::selectAll, ENABLE( haveSymbolCond ) ); mgr->SetConditions( ACTIONS::zoomTool, CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) ); mgr->SetConditions( ACTIONS::selectionTool, CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) ); diff --git a/eeschema/libedit/menubar_libedit.cpp b/eeschema/libedit/menubar_libedit.cpp index 0ada2de16e..edcf66ecb1 100644 --- a/eeschema/libedit/menubar_libedit.cpp +++ b/eeschema/libedit/menubar_libedit.cpp @@ -87,6 +87,9 @@ void LIB_EDIT_FRAME::ReCreateMenuBar() editMenu->Add( ACTIONS::doDelete ); editMenu->Add( ACTIONS::duplicate ); + editMenu->AppendSeparator(); + editMenu->Add( ACTIONS::selectAll ); + editMenu->AppendSeparator(); editMenu->Add( EE_ACTIONS::symbolProperties ); editMenu->Add( EE_ACTIONS::pinTable ); diff --git a/eeschema/menubar.cpp b/eeschema/menubar.cpp index 28f6ebacea..9be1fcb579 100644 --- a/eeschema/menubar.cpp +++ b/eeschema/menubar.cpp @@ -142,6 +142,9 @@ void SCH_EDIT_FRAME::ReCreateMenuBar() editMenu->Add( ACTIONS::doDelete ); editMenu->Add( ACTIONS::duplicate ); + editMenu->AppendSeparator(); + editMenu->Add( ACTIONS::selectAll ); + editMenu->AppendSeparator(); editMenu->Add( ACTIONS::find ); editMenu->Add( ACTIONS::findAndReplace ); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index e102c6872a..9e318e6fad 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -361,6 +361,12 @@ void SCH_EDIT_FRAME::setupUIConditions() wxASSERT( mgr ); + auto hasElements = + [ this ] ( const SELECTION& aSel ) + { + return !GetScreen()->Items().empty(); + }; + #define ENABLE( x ) ACTION_CONDITIONS().Enable( x ) #define CHECK( x ) ACTION_CONDITIONS().Check( x ) @@ -381,6 +387,7 @@ void SCH_EDIT_FRAME::setupUIConditions() mgr->SetConditions( ACTIONS::pasteSpecial, ENABLE( SELECTION_CONDITIONS::Idle ) ); mgr->SetConditions( ACTIONS::doDelete, ENABLE( SELECTION_CONDITIONS::NotEmpty ) ); mgr->SetConditions( ACTIONS::duplicate, ENABLE( SELECTION_CONDITIONS::NotEmpty ) ); + mgr->SetConditions( ACTIONS::selectAll, ENABLE( hasElements ) ); mgr->SetConditions( ACTIONS::zoomTool, CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) ); mgr->SetConditions( ACTIONS::selectionTool, CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) ); diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index 1ea9ed1d91..59caaff14b 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -110,6 +110,7 @@ EE_SELECTION_TOOL::EE_SELECTION_TOOL() : m_unit( 0 ), m_convert( 0 ) { + m_selection.Clear(); } @@ -562,6 +563,52 @@ bool EE_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, const KICAD_T* aFil } +int EE_SELECTION_TOOL::SelectAll( const TOOL_EVENT& aEvent ) +{ + m_multiple = true; // Multiple selection mode is active + KIGFX::VIEW* view = getView(); + + // hold all visible items + std::vector selectedItems; + std::vector sheetPins; + + // Filter the view items based on the selection box + BOX2I selectionBox; + + selectionBox.SetMaximum(); + view->Query( selectionBox, selectedItems ); // Get the list of selected items + + // Sheet pins aren't in the view; add them by hand + for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems ) + { + SCH_SHEET* sheet = dynamic_cast( pair.first ); + + if( sheet ) + { + int layer = pair.second; + + for( SCH_SHEET_PIN* pin : sheet->GetPins() ) + sheetPins.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( pin, layer ) ); + } + } + + selectedItems.insert( selectedItems.end(), sheetPins.begin(), sheetPins.end() ); + + for( auto& item_pair : selectedItems ) + { + if( EDA_ITEM* item = dynamic_cast( item_pair.first ) ) + { + if( Selectable( item ) ) + select( item ); + } + } + + m_multiple = false; + + return 0; +} + + void EE_SELECTION_TOOL::GuessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aPos ) { // There are certain parent/child and enclosure combinations that can be handled @@ -1466,6 +1513,8 @@ void EE_SELECTION_TOOL::setTransitions() Go( &EE_SELECTION_TOOL::RemoveItemFromSel, EE_ACTIONS::removeItemFromSel.MakeEvent() ); Go( &EE_SELECTION_TOOL::RemoveItemsFromSel, EE_ACTIONS::removeItemsFromSel.MakeEvent() ); Go( &EE_SELECTION_TOOL::SelectionMenu, EE_ACTIONS::selectionMenu.MakeEvent() ); + + Go( &EE_SELECTION_TOOL::SelectAll, EE_ACTIONS::selectAll.MakeEvent() ); } diff --git a/eeschema/tools/ee_selection_tool.h b/eeschema/tools/ee_selection_tool.h index 4b9645144a..79a19396aa 100644 --- a/eeschema/tools/ee_selection_tool.h +++ b/eeschema/tools/ee_selection_tool.h @@ -130,6 +130,9 @@ public: ///> Clear current selection event handler. int ClearSelection( const TOOL_EVENT& aEvent ); + ///> Select all visible items in sheet + int SelectAll( const TOOL_EVENT& aEvent ); + void ClearSelection(); /** diff --git a/eeschema/tools/lib_edit_tool.cpp b/eeschema/tools/lib_edit_tool.cpp index ceac0ab396..b5cc935d31 100644 --- a/eeschema/tools/lib_edit_tool.cpp +++ b/eeschema/tools/lib_edit_tool.cpp @@ -60,6 +60,12 @@ bool LIB_EDIT_TOOL::Init() wxASSERT_MSG( drawingTools, "eeschema.SymbolDrawing tool is not available" ); + auto havePartCondition = + [&]( const SELECTION& sel ) + { + return m_isLibEdit && static_cast( m_frame )->GetCurPart(); + }; + // Add edit actions to the move tool menu // if( moveTool ) @@ -79,6 +85,9 @@ bool LIB_EDIT_TOOL::Init() moveMenu.AddItem( ACTIONS::cut, EE_CONDITIONS::IdleSelection, 300 ); moveMenu.AddItem( ACTIONS::copy, EE_CONDITIONS::IdleSelection, 300 ); moveMenu.AddItem( ACTIONS::duplicate, EE_CONDITIONS::NotEmpty, 300 ); + + moveMenu.AddSeparator( 400 ); + moveMenu.AddItem( ACTIONS::selectAll, havePartCondition, 400 ); } // Add editing actions to the drawing tool menu @@ -111,6 +120,9 @@ bool LIB_EDIT_TOOL::Init() selToolMenu.AddItem( ACTIONS::paste, EE_CONDITIONS::Idle, 300 ); selToolMenu.AddItem( ACTIONS::duplicate, EE_CONDITIONS::NotEmpty, 300 ); + selToolMenu.AddSeparator( 400 ); + selToolMenu.AddItem( ACTIONS::selectAll, havePartCondition, 400 ); + return true; } diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 77a75fcb0b..cd170e367a 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -141,6 +141,12 @@ bool SCH_EDIT_TOOL::Init() wxASSERT_MSG( drawingTools, "eeshema.InteractiveDrawing tool is not available" ); + auto hasElements = + [ this ] ( const SELECTION& aSel ) + { + return !m_frame->GetScreen()->Items().empty(); + }; + auto sheetTool = [ this ] ( const SELECTION& aSel ) { @@ -301,6 +307,9 @@ bool SCH_EDIT_TOOL::Init() moveMenu.AddItem( ACTIONS::cut, E_C::IdleSelection ); moveMenu.AddItem( ACTIONS::copy, E_C::IdleSelection ); moveMenu.AddItem( ACTIONS::duplicate, duplicateCondition ); + + moveMenu.AddSeparator(); + moveMenu.AddItem( ACTIONS::selectAll, hasElements ); } // @@ -374,6 +383,10 @@ bool SCH_EDIT_TOOL::Init() selToolMenu.AddItem( ACTIONS::pasteSpecial, E_C::Idle, 300 ); selToolMenu.AddItem( ACTIONS::duplicate, duplicateCondition, 300 ); + selToolMenu.AddSeparator( 400 ); + selToolMenu.AddItem( ACTIONS::selectAll, hasElements, 400 ); + + return true; }