Refactored SelectSingleOption() to take advantage of wxSingleChoiceDialog.

This commit is contained in:
Maciej Suminski 2018-03-02 17:30:10 +01:00
parent 18167f829a
commit be13bb0013
2 changed files with 5 additions and 48 deletions

View File

@ -283,56 +283,12 @@ int YesNoCancelDialog( wxWindow* aParent,
int SelectSingleOption( wxWindow* aParent, const wxString& aTitle, const wxString& aMessage, const wxArrayString& aOptions )
{
int ret = -1;
wxDialog* dlg = new wxDialog( aParent, wxID_ANY, aTitle );
wxSingleChoiceDialog dlg( aParent, aMessage, aTitle, aOptions );
wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
if( dlg.ShowModal() != wxID_OK )
return -1;
if( !aMessage.IsEmpty() )
boxSizer->Add( new wxStaticText( dlg, wxID_ANY, aMessage ), 0, wxEXPAND | wxALL, 5 );
std::vector<wxRadioButton*> radioButtons;
radioButtons.reserve( aOptions.Count() );
for( const wxString& option : aOptions )
{
radioButtons.emplace_back( new wxRadioButton( dlg, wxID_ANY, _( option ) ) );
boxSizer->Add( radioButtons.back(), 0, wxEXPAND | wxALL, 5 );
}
wxStdDialogButtonSizer* m_sdboxSizer = new wxStdDialogButtonSizer();
wxButton* btnOk = new wxButton( dlg, wxID_OK );
m_sdboxSizer->AddButton( btnOk );
m_sdboxSizer->AddButton( new wxButton( dlg, wxID_CANCEL ) );
m_sdboxSizer->Realize();
btnOk->SetDefault();
boxSizer->Add( m_sdboxSizer, 1, wxEXPAND | wxALL, 5 );
dlg->SetSizer( boxSizer );
dlg->Layout();
boxSizer->Fit( dlg );
boxSizer->SetSizeHints( dlg );
dlg->Centre( wxBOTH );
if( dlg->ShowModal() == wxID_OK )
{
for( unsigned int i = 0; i < radioButtons.size(); ++i )
{
if( radioButtons[i]->GetValue() )
{
ret = i;
break;
}
}
}
else
{
ret = -1;
}
dlg->Destroy();
return ret;
return dlg.GetSelection();
}

View File

@ -157,6 +157,7 @@ int YesNoCancelDialog( wxWindow* aParent,
/**
* Displays a dialog with radioboxes asking the user to select an option.
*
* @param aParent is the parent window.
* @param aTitle is the dialog title.
* @param aMessage is a text label displayed in the first row of the dialog.