De-bounce search pane selection events.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15605
This commit is contained in:
Jeff Young 2023-11-09 14:30:23 +00:00
parent fe46fafa98
commit 77e408a93d
2 changed files with 22 additions and 22 deletions

View File

@ -29,7 +29,8 @@ SEARCH_PANE_LISTVIEW::SEARCH_PANE_LISTVIEW( SEARCH_HANDLER* handler, wxWindow* p
wxListView( parent, winid, pos, size, wxLC_REPORT | wxLC_VIRTUAL ), wxListView( parent, winid, pos, size, wxLC_REPORT | wxLC_VIRTUAL ),
m_handler( handler ), m_handler( handler ),
m_sortCol( -1 ), m_sortCol( -1 ),
m_sortAscending( true ) m_sortAscending( true ),
m_selectionDirty( false )
{ {
SetItemCount( 0 ); SetItemCount( 0 );
@ -40,6 +41,7 @@ SEARCH_PANE_LISTVIEW::SEARCH_PANE_LISTVIEW( SEARCH_HANDLER* handler, wxWindow* p
Bind( wxEVT_LIST_ITEM_FOCUSED, &SEARCH_PANE_LISTVIEW::OnItemSelected, this ); Bind( wxEVT_LIST_ITEM_FOCUSED, &SEARCH_PANE_LISTVIEW::OnItemSelected, this );
Bind( wxEVT_LIST_ITEM_DESELECTED, &SEARCH_PANE_LISTVIEW::OnItemDeselected, this ); Bind( wxEVT_LIST_ITEM_DESELECTED, &SEARCH_PANE_LISTVIEW::OnItemDeselected, this );
Bind( wxEVT_LIST_COL_CLICK, &SEARCH_PANE_LISTVIEW::OnColClicked, this ); Bind( wxEVT_LIST_COL_CLICK, &SEARCH_PANE_LISTVIEW::OnColClicked, this );
Bind( wxEVT_UPDATE_UI, &SEARCH_PANE_LISTVIEW::OnUpdateUI, this );
} }
@ -49,6 +51,7 @@ SEARCH_PANE_LISTVIEW::~SEARCH_PANE_LISTVIEW()
Unbind( wxEVT_LIST_ITEM_ACTIVATED, &SEARCH_PANE_LISTVIEW::OnItemActivated, this ); Unbind( wxEVT_LIST_ITEM_ACTIVATED, &SEARCH_PANE_LISTVIEW::OnItemActivated, this );
Unbind( wxEVT_LIST_ITEM_FOCUSED, &SEARCH_PANE_LISTVIEW::OnItemSelected, this ); Unbind( wxEVT_LIST_ITEM_FOCUSED, &SEARCH_PANE_LISTVIEW::OnItemSelected, this );
Unbind( wxEVT_LIST_ITEM_DESELECTED, &SEARCH_PANE_LISTVIEW::OnItemDeselected, this ); Unbind( wxEVT_LIST_ITEM_DESELECTED, &SEARCH_PANE_LISTVIEW::OnItemDeselected, this );
Unbind( wxEVT_UPDATE_UI, &SEARCH_PANE_LISTVIEW::OnUpdateUI, this );
} }
@ -77,45 +80,40 @@ void SEARCH_PANE_LISTVIEW::OnItemActivated( wxListEvent& aEvent )
[=]() [=]()
{ {
m_handler->ActivateItem( aEvent.GetIndex() ); m_handler->ActivateItem( aEvent.GetIndex() );
// Reset our selection to match the selected list items
std::vector<long> list;
GetSelectRowsList( list );
m_handler->SelectItems( list );
} ); } );
m_selectionDirty = true;
aEvent.Skip(); aEvent.Skip();
} }
void SEARCH_PANE_LISTVIEW::OnItemSelected( wxListEvent& aEvent ) void SEARCH_PANE_LISTVIEW::OnItemSelected( wxListEvent& aEvent )
{ {
CallAfter( m_selectionDirty = true;
[=]()
{
std::vector<long> list;
GetSelectRowsList( list );
m_handler->SelectItems( list );
} );
aEvent.Skip(); aEvent.Skip();
} }
void SEARCH_PANE_LISTVIEW::OnItemDeselected( wxListEvent& aEvent ) void SEARCH_PANE_LISTVIEW::OnItemDeselected( wxListEvent& aEvent )
{ {
CallAfter( m_selectionDirty = true;
[=]()
{
std::vector<long> list;
GetSelectRowsList( list );
m_handler->SelectItems( list );
} );
aEvent.Skip(); aEvent.Skip();
} }
void SEARCH_PANE_LISTVIEW::OnUpdateUI( wxUpdateUIEvent& aEvent )
{
if( m_selectionDirty )
{
m_selectionDirty = false;
std::vector<long> list;
GetSelectRowsList( list );
m_handler->SelectItems( list );
}
}
void SEARCH_PANE_LISTVIEW::OnColClicked( wxListEvent& aEvent ) void SEARCH_PANE_LISTVIEW::OnColClicked( wxListEvent& aEvent )
{ {
if( aEvent.GetColumn() == m_sortCol ) if( aEvent.GetColumn() == m_sortCol )

View File

@ -48,6 +48,7 @@ protected:
void OnItemActivated( wxListEvent& aEvent ); void OnItemActivated( wxListEvent& aEvent );
void OnItemDeselected( wxListEvent& aEvent ); void OnItemDeselected( wxListEvent& aEvent );
void OnColClicked( wxListEvent& aEvent ); void OnColClicked( wxListEvent& aEvent );
void OnUpdateUI( wxUpdateUIEvent& aEvent );
void GetSelectRowsList( std::vector<long>& aSelectedList ); void GetSelectRowsList( std::vector<long>& aSelectedList );
@ -55,6 +56,7 @@ private:
SEARCH_HANDLER* m_handler; SEARCH_HANDLER* m_handler;
int m_sortCol; int m_sortCol;
bool m_sortAscending; bool m_sortAscending;
bool m_selectionDirty;
}; };