Allow multi-selecting from the search pane
Fix https://gitlab.com/kicad/code/kicad/-/issues/12476
This commit is contained in:
parent
dc9909f83f
commit
ec25463fed
|
@ -20,6 +20,7 @@
|
||||||
#include <widgets/search_pane_tab.h>
|
#include <widgets/search_pane_tab.h>
|
||||||
#include <widgets/search_pane.h>
|
#include <widgets/search_pane.h>
|
||||||
#include <kiway.h>
|
#include <kiway.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
SEARCH_PANE_LISTVIEW::SEARCH_PANE_LISTVIEW( SEARCH_HANDLER* handler, wxWindow* parent,
|
SEARCH_PANE_LISTVIEW::SEARCH_PANE_LISTVIEW( SEARCH_HANDLER* handler, wxWindow* parent,
|
||||||
wxWindowID winid, const wxPoint& pos,
|
wxWindowID winid, const wxPoint& pos,
|
||||||
|
@ -32,14 +33,36 @@ SEARCH_PANE_LISTVIEW::SEARCH_PANE_LISTVIEW( SEARCH_HANDLER* handler, wxWindow* p
|
||||||
RefreshColumnNames();
|
RefreshColumnNames();
|
||||||
|
|
||||||
Bind( wxEVT_LIST_ITEM_SELECTED, &SEARCH_PANE_LISTVIEW::OnItemSelected, this );
|
Bind( wxEVT_LIST_ITEM_SELECTED, &SEARCH_PANE_LISTVIEW::OnItemSelected, this );
|
||||||
|
Bind( wxEVT_LIST_ITEM_DESELECTED, &SEARCH_PANE_LISTVIEW::OnItemSelected, this );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<long> SEARCH_PANE_LISTVIEW::GetSelectRowsList()
|
||||||
|
{
|
||||||
|
std::vector<long> selectedIdxList;
|
||||||
|
long idx = GetFirstSelected();
|
||||||
|
selectedIdxList.emplace_back( idx );
|
||||||
|
|
||||||
|
idx = GetNextSelected( idx );
|
||||||
|
while( idx > 0 )
|
||||||
|
{
|
||||||
|
selectedIdxList.emplace_back( idx );
|
||||||
|
idx = GetNextSelected( idx );
|
||||||
|
}
|
||||||
|
|
||||||
|
return selectedIdxList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SEARCH_PANE_LISTVIEW::OnItemSelected( wxListEvent& aEvent )
|
void SEARCH_PANE_LISTVIEW::OnItemSelected( wxListEvent& aEvent )
|
||||||
{
|
{
|
||||||
long idx = aEvent.GetIndex();
|
m_handler->SelectItems( GetSelectRowsList() );
|
||||||
|
}
|
||||||
|
|
||||||
m_handler->SelectItem( idx );
|
|
||||||
|
void SEARCH_PANE_LISTVIEW::OnItemDeselected( wxListEvent& aEvent )
|
||||||
|
{
|
||||||
|
m_handler->SelectItems( GetSelectRowsList() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
virtual int Search( const wxString& string ) = 0;
|
virtual int Search( const wxString& string ) = 0;
|
||||||
virtual wxString GetResultCell( int row, int col ) = 0;
|
virtual wxString GetResultCell( int row, int col ) = 0;
|
||||||
|
|
||||||
virtual void SelectItem(int row) {}
|
virtual void SelectItems( std::vector<long>& aItemRows ) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxString m_name;
|
wxString m_name;
|
||||||
|
|
|
@ -40,6 +40,9 @@ public:
|
||||||
protected:
|
protected:
|
||||||
wxString OnGetItemText( long item, long column ) const override;
|
wxString OnGetItemText( long item, long column ) const override;
|
||||||
void OnItemSelected( wxListEvent& aEvent );
|
void OnItemSelected( wxListEvent& aEvent );
|
||||||
|
void OnItemDeselected( wxListEvent& aEvent );
|
||||||
|
|
||||||
|
std::vector<long> GetSelectRowsList();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SEARCH_HANDLER* m_handler;
|
SEARCH_HANDLER* m_handler;
|
||||||
|
|
|
@ -82,12 +82,20 @@ wxString FOOTPRINT_SEARCH_HANDLER::GetResultCell( int aRow, int aCol )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FOOTPRINT_SEARCH_HANDLER::SelectItem( int aRow )
|
void FOOTPRINT_SEARCH_HANDLER::SelectItems( std::vector<long>& aItemRows )
|
||||||
{
|
{
|
||||||
FOOTPRINT* fp = m_hitlist[aRow];
|
std::vector<EDA_ITEM*> selectedItems;
|
||||||
|
for( long row : aItemRows )
|
||||||
|
{
|
||||||
|
if( row < m_hitlist.size() )
|
||||||
|
{
|
||||||
|
FOOTPRINT* fp = m_hitlist[row];
|
||||||
|
selectedItems.push_back( fp );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
|
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
|
||||||
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItem, true, fp );
|
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItems, true, &selectedItems );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -157,12 +165,20 @@ wxString ZONE_SEARCH_HANDLER::GetResultCell( int aRow, int aCol )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ZONE_SEARCH_HANDLER::SelectItem( int aRow )
|
void ZONE_SEARCH_HANDLER::SelectItems( std::vector<long>& aItemRows )
|
||||||
{
|
{
|
||||||
ZONE* zone = m_hitlist[aRow];
|
std::vector<EDA_ITEM*> selectedItems;
|
||||||
|
for( long row : aItemRows )
|
||||||
|
{
|
||||||
|
if( row < m_hitlist.size() )
|
||||||
|
{
|
||||||
|
ZONE* zone = m_hitlist[row];
|
||||||
|
selectedItems.push_back( zone );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
|
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
|
||||||
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItem, true, zone );
|
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItems, true, &selectedItems );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -242,12 +258,20 @@ wxString TEXT_SEARCH_HANDLER::GetResultCell( int aRow, int aCol )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TEXT_SEARCH_HANDLER::SelectItem( int aRow )
|
void TEXT_SEARCH_HANDLER::SelectItems( std::vector<long>& aItemRows )
|
||||||
{
|
{
|
||||||
BOARD_ITEM* text = m_hitlist[aRow];
|
std::vector<EDA_ITEM*> selectedItems;
|
||||||
|
for( long row : aItemRows )
|
||||||
|
{
|
||||||
|
if( row < m_hitlist.size() )
|
||||||
|
{
|
||||||
|
BOARD_ITEM* text = m_hitlist[row];
|
||||||
|
selectedItems.push_back( text );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
|
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
|
||||||
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItem, true, text );
|
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItems, true, &selectedItems );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
|
|
||||||
int Search( const wxString& aQuery ) override;
|
int Search( const wxString& aQuery ) override;
|
||||||
wxString GetResultCell( int aRow, int aCol ) override;
|
wxString GetResultCell( int aRow, int aCol ) override;
|
||||||
void SelectItem( int aRow ) override;
|
void SelectItems( std::vector<long>& aItemRows ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PCB_EDIT_FRAME* m_frame;
|
PCB_EDIT_FRAME* m_frame;
|
||||||
|
@ -51,7 +51,7 @@ public:
|
||||||
|
|
||||||
int Search( const wxString& aQuery ) override;
|
int Search( const wxString& aQuery ) override;
|
||||||
wxString GetResultCell( int aRow, int aCol ) override;
|
wxString GetResultCell( int aRow, int aCol ) override;
|
||||||
void SelectItem( int aRow ) override;
|
void SelectItems( std::vector<long>& aItemRows ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PCB_EDIT_FRAME* m_frame;
|
PCB_EDIT_FRAME* m_frame;
|
||||||
|
@ -66,7 +66,7 @@ public:
|
||||||
|
|
||||||
int Search( const wxString& aQuery ) override;
|
int Search( const wxString& aQuery ) override;
|
||||||
wxString GetResultCell( int aRow, int aCol ) override;
|
wxString GetResultCell( int aRow, int aCol ) override;
|
||||||
void SelectItem( int aRow ) override;
|
void SelectItems( std::vector<long>& aItemRows ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PCB_EDIT_FRAME* m_frame;
|
PCB_EDIT_FRAME* m_frame;
|
||||||
|
|
Loading…
Reference in New Issue