diff --git a/common/widgets/lib_tree.cpp b/common/widgets/lib_tree.cpp index 7b4081933d..8335ceb351 100644 --- a/common/widgets/lib_tree.cpp +++ b/common/widgets/lib_tree.cpp @@ -33,6 +33,7 @@ #include #include #include +#include LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, @@ -57,6 +58,8 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, m_query_ctrl->ShowCancelButton( true ); + m_debounceTimer = new wxTimer( this ); + // Additional visual cue for GTK, which hides the placeholder text on focus #ifdef __WXGTK__ auto bitmap = new wxStaticBitmap( this, wxID_ANY, wxArtProvider::GetBitmap( wxART_FIND, wxART_FRAME_ICON ) ); @@ -70,6 +73,8 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, m_query_ctrl->Bind( wxEVT_TEXT, &LIB_TREE::onQueryText, this ); m_query_ctrl->Bind( wxEVT_TEXT_ENTER, &LIB_TREE::onQueryEnter, this ); m_query_ctrl->Bind( wxEVT_CHAR_HOOK, &LIB_TREE::onQueryCharHook, this ); + + Bind( wxEVT_TIMER, &LIB_TREE::onDebounceTimer, this, m_debounceTimer->GetId() ); } // Tree control @@ -322,7 +327,7 @@ void LIB_TREE::setState( const STATE& aState ) void LIB_TREE::onQueryText( wxCommandEvent& aEvent ) { - Regenerate( false ); + m_debounceTimer->StartOnce( 200 ); // Required to avoid interaction with SetHint() // See documentation for wxTextEntry::SetHint @@ -337,6 +342,12 @@ void LIB_TREE::onQueryEnter( wxCommandEvent& aEvent ) } +void LIB_TREE::onDebounceTimer( wxTimerEvent& aEvent ) +{ + Regenerate( false ); +} + + void LIB_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke ) { auto const sel = m_tree_ctrl->GetSelection(); diff --git a/include/widgets/lib_tree.h b/include/widgets/lib_tree.h index 026e57b374..5911d43063 100644 --- a/include/widgets/lib_tree.h +++ b/include/widgets/lib_tree.h @@ -33,6 +33,8 @@ class wxTextCtrl; class wxHtmlWindow; class wxHtmlLinkEvent; class wxSearchCtrl; +class wxTimer; +class wxTimerEvent; class ACTION_MENU; class LIB_ID; class LIB_TABLE; @@ -167,6 +169,8 @@ protected: void onPreselect( wxCommandEvent& aEvent ); void onContextMenu( wxDataViewEvent& aEvent ); + void onDebounceTimer( wxTimerEvent& aEvent ); + protected: LIB_TABLE* m_lib_table; @@ -175,6 +179,7 @@ protected: wxSearchCtrl* m_query_ctrl; wxDataViewCtrl* m_tree_ctrl; wxHtmlWindow* m_details_ctrl; + wxTimer* m_debounceTimer; LIB_ID m_last_libid; };