Prevent crash in color settings due to dropdown weirdness

Fixes sentry reported crash KICAD-R6


(cherry picked from commit c65e33ac13)
This commit is contained in:
Marek Roszko 2023-03-23 19:45:29 -04:00 committed by Mark Roszko
parent 2ada171806
commit 3f90c895b9
2 changed files with 20 additions and 6 deletions

View File

@ -117,8 +117,7 @@ void PANEL_COLOR_SETTINGS::OnThemeChanged( wxCommandEvent& event )
if( idx == static_cast<int>( m_cbTheme->GetCount() ) - 2 ) if( idx == static_cast<int>( m_cbTheme->GetCount() ) - 2 )
{ {
// separator; re-select active theme m_cbTheme->SetStringSelection( GetSettingsDropdownName( m_currentSettings ) );
m_cbTheme->SetStringSelection( m_currentSettings->GetName() );
return; return;
} }
@ -217,10 +216,7 @@ void PANEL_COLOR_SETTINGS::createThemeList( const wxString& aCurrent )
for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() ) for( COLOR_SETTINGS* settings : Pgm().GetSettingsManager().GetColorSettingsList() )
{ {
wxString name = settings->GetName(); wxString name = GetSettingsDropdownName( settings );
if( settings->IsReadOnly() )
name += wxS( " " ) + _( "(read-only)" );
int pos = m_cbTheme->Append( name, static_cast<void*>( settings ) ); int pos = m_cbTheme->Append( name, static_cast<void*>( settings ) );
@ -286,6 +282,8 @@ void PANEL_COLOR_SETTINGS::ShowColorContextMenu( wxMouseEvent& aEvent, int aLaye
auto selected = auto selected =
static_cast<COLOR_SETTINGS*>( m_cbTheme->GetClientData( m_cbTheme->GetSelection() ) ); static_cast<COLOR_SETTINGS*>( m_cbTheme->GetClientData( m_cbTheme->GetSelection() ) );
wxCHECK_RET( selected, wxT( "Invalid color theme selected" ) );
COLOR4D current = m_currentSettings->GetColor( aLayer ); COLOR4D current = m_currentSettings->GetColor( aLayer );
COLOR4D saved = selected->GetColor( aLayer ); COLOR4D saved = selected->GetColor( aLayer );
bool readOnly = m_currentSettings->IsReadOnly(); bool readOnly = m_currentSettings->IsReadOnly();
@ -379,3 +377,14 @@ bool PANEL_COLOR_SETTINGS::saveCurrentTheme( bool aValidate )
return true; return true;
} }
wxString PANEL_COLOR_SETTINGS::GetSettingsDropdownName(COLOR_SETTINGS* aSettings)
{
wxString name = aSettings->GetName();
if( aSettings->IsReadOnly() )
name += wxS( " " ) + _( "(read-only)" );
return name;
}

View File

@ -97,6 +97,11 @@ protected:
*/ */
virtual void onColorChanged() {} virtual void onColorChanged() {}
/**
* Retrieves the drop down name to be displayed for a color setting
*/
wxString GetSettingsDropdownName( COLOR_SETTINGS* aSettings );
COLOR_SETTINGS* m_currentSettings; COLOR_SETTINGS* m_currentSettings;
std::map<int, wxStaticText*> m_labels; std::map<int, wxStaticText*> m_labels;