Refactored SelectSingleOption() to take advantage of wxSingleChoiceDialog.
This commit is contained in:
parent
18167f829a
commit
be13bb0013
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue