diff --git a/common/confirm.cpp b/common/confirm.cpp index e3231515c8..22ddc7401f 100644 --- a/common/confirm.cpp +++ b/common/confirm.cpp @@ -292,73 +292,47 @@ int SelectSingleOption( wxWindow* aParent, const wxString& aTitle, const wxStrin } -class DIALOG_MULTI_OPTIONS : public wxDialog +class DIALOG_MULTI_OPTIONS : public wxMultiChoiceDialog { public: DIALOG_MULTI_OPTIONS( wxWindow* aParent, const wxString& aTitle, const wxString& aMessage, const wxArrayString& aOptions ) - : wxDialog( aParent, wxID_ANY, aTitle ) + : wxMultiChoiceDialog( aParent, aMessage, aTitle, aOptions ), + m_optionsCount( aOptions.GetCount() ) { - SetSizeHints( wxDefaultSize, wxDefaultSize ); - - wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL ); - - if( !aMessage.IsEmpty() ) - boxSizer->Add( new wxStaticText( this, wxID_ANY, aMessage ), 0, wxEXPAND | wxALL, 5 ); - - m_checklist = new wxCheckListBox( this, wxID_ANY ); - - for( const wxString& option : aOptions ) - m_checklist->Append( option ); - - boxSizer->Add( m_checklist, 1, wxEXPAND | wxALL, 5 ); - wxBoxSizer* btnSizer = new wxBoxSizer( wxHORIZONTAL ); wxButton* selectAll = new wxButton( this, wxID_ANY, _( "Select All" ) ); btnSizer->Add( selectAll, 1, wxEXPAND | wxALL, 5 ); wxButton* unselectAll = new wxButton( this, wxID_ANY, _( "Unselect All" ) ); btnSizer->Add( unselectAll, 1, wxEXPAND | wxALL, 5 ); - boxSizer->Add( btnSizer, 0, wxEXPAND | wxALL, 5 ); + auto sizer = GetSizer(); + sizer->Insert( sizer->GetItemCount() - 1, btnSizer, 0, wxEXPAND | wxALL, 0 ); - wxStdDialogButtonSizer* m_sdboxSizer = new wxStdDialogButtonSizer(); - wxButton* btnOk = new wxButton( this, wxID_OK ); - m_sdboxSizer->AddButton( btnOk ); - m_sdboxSizer->AddButton( new wxButton( this, wxID_CANCEL ) ); - m_sdboxSizer->Realize(); - btnOk->SetDefault(); - boxSizer->Add( m_sdboxSizer, 0, wxEXPAND | wxALL, 5 ); - - SetSizer( boxSizer ); Layout(); - boxSizer->Fit( this ); - boxSizer->SetSizeHints( this ); + sizer->Fit( this ); + sizer->SetSizeHints( this ); Centre( wxBOTH ); selectAll->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_MULTI_OPTIONS::selectAll, this ); unselectAll->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_MULTI_OPTIONS::unselectAll, this ); } - std::vector GetSelection() const - { - std::vector ret; - - for( unsigned int i = 0; i < m_checklist->GetCount(); ++i ) - { - if( m_checklist->IsChecked( i ) ) - ret.push_back( i ); - } - - return ret; - } - void SetCheckboxes( bool aValue ) { - for( unsigned int i = 0; i < m_checklist->GetCount(); ++i ) - m_checklist->Check( i, aValue ); + wxArrayInt selIdxs; + + if( aValue ) // select all indices + { + for( unsigned int i = 0; i < m_optionsCount; ++i ) + selIdxs.Add( i ); + } + + SetSelections( selIdxs ); } protected: - wxCheckListBox* m_checklist; + ///> Number of displayed options + int m_optionsCount; void selectAll( wxCommandEvent& aEvent ) { @@ -372,29 +346,24 @@ protected: }; -std::pair> SelectMultipleOptions( wxWindow* aParent, const wxString& aTitle, +std::pair SelectMultipleOptions( wxWindow* aParent, const wxString& aTitle, const wxString& aMessage, const wxArrayString& aOptions, bool aDefaultState ) { - std::vector ret; - bool clickedOk; DIALOG_MULTI_OPTIONS dlg( aParent, aTitle, aMessage, aOptions ); + dlg.Layout(); dlg.SetCheckboxes( aDefaultState ); - if( dlg.ShowModal() == wxID_OK ) - { - ret = dlg.GetSelection(); - clickedOk = true; - } - else - { - clickedOk = false; - } + wxArrayInt ret; + bool clickedOk = ( dlg.ShowModal() == wxID_OK ); + + if( clickedOk ) + ret = dlg.GetSelections(); return std::make_pair( clickedOk, ret ); } -std::pair> SelectMultipleOptions( wxWindow* aParent, const wxString& aTitle, +std::pair SelectMultipleOptions( wxWindow* aParent, const wxString& aTitle, const wxString& aMessage, const std::vector& aOptions, bool aDefaultState ) { wxArrayString array; diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index 39ae033afd..51630e861e 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -614,7 +614,7 @@ bool LIB_EDIT_FRAME::saveAllLibraries( bool aClosing ) if( unsavedLibraries.IsEmpty() ) break; - std::vector libIdxs; + wxArrayInt libIdxs; // Show a list of unsaved libraries when: // - library editor is closed diff --git a/include/confirm.h b/include/confirm.h index 595f891a11..79b0a41ee4 100644 --- a/include/confirm.h +++ b/include/confirm.h @@ -169,17 +169,19 @@ int SelectSingleOption( wxWindow* aParent, const wxString& aTitle, const wxStrin /** * Displays a dialog with checkboxes asking the user to select one or more options. + * * @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. * @param aOptions is a vector of possible options. * @param aDefaultState is the default state for the checkboxes. - * @return Vector containing indices of the selected option. + * @return Pair containing a boolean value equal to true when the selection has been confirmed and + * an integer array containing indices of the selected options. */ -std::pair> SelectMultipleOptions( wxWindow* aParent, const wxString& aTitle, +std::pair SelectMultipleOptions( wxWindow* aParent, const wxString& aTitle, const wxString& aMessage, const wxArrayString& aOptions, bool aDefaultState = false ); -std::pair> SelectMultipleOptions( wxWindow* aParent, const wxString& aTitle, +std::pair SelectMultipleOptions( wxWindow* aParent, const wxString& aTitle, const wxString& aMessage, const std::vector& aOptions, bool aDefaultState = false ); #endif /* __INCLUDE__CONFIRM_H__ */