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();
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_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()
{
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_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 )
{
CallAfter(
@ -153,4 +172,4 @@ void SEARCH_PANE_TAB::Clear()
void SEARCH_PANE_TAB::RefreshColumnNames()
{
m_listView->RefreshColumnNames();
}
}

View File

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

View File

@ -43,6 +43,7 @@ public:
protected:
wxString OnGetItemText( long item, long column ) const override;
void OnItemSelected( wxListEvent& aEvent );
void OnItemActivated( wxListEvent& aEvent );
void OnItemDeselected( wxListEvent& aEvent );
void GetSelectRowsList( std::vector<long>& aSelectedList );
@ -70,4 +71,4 @@ private:
SEARCH_HANDLER* m_handler;
};
#endif
#endif