Add precondition checks to operations in the listctrl sample

Avoid showing assert failures in debug builds if a menu item not
applicable in the current state is selected and just show an error
instead.

Closes #18572.

Closes https://github.com/wxWidgets/wxWidgets/pull/1694
This commit is contained in:
Kvaz1r 2020-01-05 13:42:16 +02:00 committed by Vadim Zeitlin
parent 89be9ac316
commit a23b3783b6

View File

@ -402,6 +402,12 @@ void MyFrame::OnToggleMacUseGeneric(wxCommandEvent& event)
void MyFrame::OnGoTo(wxCommandEvent& WXUNUSED(event))
{
if ( m_listCtrl->IsEmpty() )
{
wxLogMessage("Attempt go to item #3 when list is empty");
return;
}
long index = 3;
m_listCtrl->SetItemState(index, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
@ -426,7 +432,14 @@ void MyFrame::OnFocusLast(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnToggleFirstSel(wxCommandEvent& WXUNUSED(event))
{
m_listCtrl->SetItemState(0, (~m_listCtrl->GetItemState(0, wxLIST_STATE_SELECTED) ) & wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
if ( !m_listCtrl->IsEmpty() )
{
m_listCtrl->SetItemState(0, (~m_listCtrl->GetItemState(0, wxLIST_STATE_SELECTED) ) & wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
}
else
{
wxLogMessage("Attempt toggle first item when list is empty");
}
}
void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event))