Search Pane: add Activation (enter/double click) event support

(cherry picked from commit d915cb780e)
This commit is contained in:
Mike Williams 2023-01-25 11:09:23 -05:00 committed by Jeff Young
parent a3197578d6
commit 13fb23d59d
3 changed files with 24 additions and 3 deletions

View File

@ -33,6 +33,7 @@ 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_ACTIVATED, &SEARCH_PANE_LISTVIEW::OnItemActivated, this );
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 );
} }
@ -41,6 +42,7 @@ SEARCH_PANE_LISTVIEW::SEARCH_PANE_LISTVIEW( SEARCH_HANDLER* handler, wxWindow* p
SEARCH_PANE_LISTVIEW::~SEARCH_PANE_LISTVIEW() SEARCH_PANE_LISTVIEW::~SEARCH_PANE_LISTVIEW()
{ {
Unbind( wxEVT_LIST_ITEM_SELECTED, &SEARCH_PANE_LISTVIEW::OnItemSelected, this ); Unbind( wxEVT_LIST_ITEM_SELECTED, &SEARCH_PANE_LISTVIEW::OnItemSelected, 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 );
} }
@ -65,6 +67,23 @@ void SEARCH_PANE_LISTVIEW::GetSelectRowsList( std::vector<long>& aSelectedList )
} }
void SEARCH_PANE_LISTVIEW::OnItemActivated( wxListEvent& aEvent )
{
CallAfter(
[&]()
{
m_handler->ActivateItem( aEvent.GetIndex() );
// Reset our selection to match the selected list items
std::vector<long> list;
GetSelectRowsList( list );
m_handler->SelectItems( list );
} );
aEvent.Skip();
}
void SEARCH_PANE_LISTVIEW::OnItemSelected( wxListEvent& aEvent ) void SEARCH_PANE_LISTVIEW::OnItemSelected( wxListEvent& aEvent )
{ {
CallAfter( CallAfter(

View File

@ -40,6 +40,7 @@ public:
virtual wxString GetResultCell( int row, int col ) = 0; virtual wxString GetResultCell( int row, int col ) = 0;
virtual void SelectItems( std::vector<long>& aItemRows ) {} virtual void SelectItems( std::vector<long>& aItemRows ) {}
virtual void ActivateItem( long aItemRow ) {}
protected: protected:
wxString m_name; wxString m_name;

View File

@ -43,6 +43,7 @@ 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 OnItemActivated( wxListEvent& aEvent );
void OnItemDeselected( wxListEvent& aEvent ); void OnItemDeselected( wxListEvent& aEvent );
void GetSelectRowsList( std::vector<long>& aSelectedList ); void GetSelectRowsList( std::vector<long>& aSelectedList );