Handle two panels both referencing same colour theme.

Fixes https://gitlab.com/kicad/code/kicad/issues/5185
This commit is contained in:
Jeff Young 2020-09-21 00:11:44 +01:00
parent 4db4a0a46f
commit 865249c227
10 changed files with 51 additions and 30 deletions

View File

@ -79,6 +79,25 @@ void PANEL_COLOR_SETTINGS::ResetPanel()
} }
bool PANEL_COLOR_SETTINGS::Show( bool show )
{
if( show )
{
// In case changes have been made to the current theme in another panel:
wxString currentTheme = m_cbTheme->GetStringSelection();
COLOR_SETTINGS* settings = Pgm().GetSettingsManager().GetColorSettings( currentTheme );
if( settings )
*m_currentSettings = *settings;
onNewThemeSelected();
updateSwatches();
}
return PANEL_COLOR_SETTINGS_BASE::Show( show );
}
void PANEL_COLOR_SETTINGS::OnLeftDownTheme( wxMouseEvent& event ) void PANEL_COLOR_SETTINGS::OnLeftDownTheme( wxMouseEvent& event )
{ {
// Lazy rebuild of theme menu to catch any colour theme changes made in other panels // Lazy rebuild of theme menu to catch any colour theme changes made in other panels
@ -153,19 +172,24 @@ void PANEL_COLOR_SETTINGS::OnThemeChanged( wxCommandEvent& event )
*m_currentSettings = *selected; *m_currentSettings = *selected;
onNewThemeSelected(); onNewThemeSelected();
updateSwatches();
COLOR4D background = m_currentSettings->GetColor( m_backgroundLayer );
for( std::pair<int, COLOR_SWATCH*> pair : m_swatches )
{
pair.second->SetSwatchBackground( background );
pair.second->SetSwatchColor( m_currentSettings->GetColor( pair.first ), false );
}
} }
} }
} }
void PANEL_COLOR_SETTINGS::updateSwatches()
{
COLOR4D background = m_currentSettings->GetColor( m_backgroundLayer );
for( std::pair<int, COLOR_SWATCH*> pair : m_swatches )
{
pair.second->SetSwatchBackground( background );
pair.second->SetSwatchColor( m_currentSettings->GetColor( pair.first ), false );
}
}
void PANEL_COLOR_SETTINGS::createThemeList( const wxString& aCurrent ) void PANEL_COLOR_SETTINGS::createThemeList( const wxString& aCurrent )
{ {
int width = 0; int width = 0;
@ -292,6 +316,10 @@ void PANEL_COLOR_SETTINGS::updateColor( int aLayer, const KIGFX::COLOR4D& aColor
if( m_currentSettings ) if( m_currentSettings )
m_currentSettings->SetColor( aLayer, aColor ); m_currentSettings->SetColor( aLayer, aColor );
// Colors must be persisted when edited because multiple PANEL_COLOR_SETTINGS could be
// referring to the same theme.
saveCurrentTheme( false );
m_swatches[aLayer]->SetSwatchColor( aColor, false ); m_swatches[aLayer]->SetSwatchColor( aColor, false );
if( m_currentSettings && aLayer == m_backgroundLayer ) if( m_currentSettings && aLayer == m_backgroundLayer )

View File

@ -50,6 +50,8 @@ public:
return _( "Reset all colors in this theme to the KiCad defaults" ); return _( "Reset all colors in this theme to the KiCad defaults" );
} }
bool Show( bool show ) override;
protected: protected:
void OnBtnOpenThemeFolderClicked( wxCommandEvent& event ) override; void OnBtnOpenThemeFolderClicked( wxCommandEvent& event ) override;
@ -60,6 +62,8 @@ protected:
void OnColorChanged( wxCommandEvent& aEvent ); void OnColorChanged( wxCommandEvent& aEvent );
void updateSwatches();
void createThemeList( const wxString& aCurrent ); void createThemeList( const wxString& aCurrent );
void createSwatch( int aLayer, const wxString& aName ); void createSwatch( int aLayer, const wxString& aName );

View File

@ -20,9 +20,8 @@ PANEL_COLOR_SETTINGS_BASE::PANEL_COLOR_SETTINGS_BASE( wxWindow* parent, wxWindow
m_staticText9->Wrap( -1 ); m_staticText9->Wrap( -1 );
bControlSizer->Add( m_staticText9, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); bControlSizer->Add( m_staticText9, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
wxString m_cbThemeChoices[] = { _("User") }; wxArrayString m_cbThemeChoices;
int m_cbThemeNChoices = sizeof( m_cbThemeChoices ) / sizeof( wxString ); m_cbTheme = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_cbThemeChoices, 0 );
m_cbTheme = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_cbThemeNChoices, m_cbThemeChoices, 0 );
m_cbTheme->SetSelection( 0 ); m_cbTheme->SetSelection( 0 );
m_cbTheme->SetMinSize( wxSize( 150,-1 ) ); m_cbTheme->SetMinSize( wxSize( 150,-1 ) );

View File

@ -143,7 +143,7 @@
<property name="caption"></property> <property name="caption"></property>
<property name="caption_visible">1</property> <property name="caption_visible">1</property>
<property name="center_pane">0</property> <property name="center_pane">0</property>
<property name="choices">&quot;User&quot;</property> <property name="choices"></property>
<property name="close_button">1</property> <property name="close_button">1</property>
<property name="context_help"></property> <property name="context_help"></property>
<property name="context_menu">1</property> <property name="context_menu">1</property>

View File

@ -93,19 +93,10 @@ PANEL_MODEDIT_COLOR_SETTINGS::~PANEL_MODEDIT_COLOR_SETTINGS()
bool PANEL_MODEDIT_COLOR_SETTINGS::TransferDataFromWindow() bool PANEL_MODEDIT_COLOR_SETTINGS::TransferDataFromWindow()
{ {
m_currentSettings->SetOverrideSchItemColors( m_optOverrideColors->GetValue() );
if( !saveCurrentTheme( true ) )
return false;
m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings()->LoadColors( m_currentSettings );
SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager(); SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
FOOTPRINT_EDITOR_SETTINGS* settings = settingsMgr.GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>(); FOOTPRINT_EDITOR_SETTINGS* settings = settingsMgr.GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
settings->m_ColorTheme = m_currentSettings->GetFilename(); settings->m_ColorTheme = m_currentSettings->GetFilename();
m_frame->UpdateUserInterface();
return true; return true;
} }

View File

@ -432,17 +432,10 @@ PANEL_PCBNEW_COLOR_SETTINGS::~PANEL_PCBNEW_COLOR_SETTINGS()
bool PANEL_PCBNEW_COLOR_SETTINGS::TransferDataFromWindow() bool PANEL_PCBNEW_COLOR_SETTINGS::TransferDataFromWindow()
{ {
if( !saveCurrentTheme( true ) )
return false;
m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings()->LoadColors( m_currentSettings );
SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager(); SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
PCBNEW_SETTINGS* app_settings = settingsMgr.GetAppSettings<PCBNEW_SETTINGS>(); PCBNEW_SETTINGS* app_settings = settingsMgr.GetAppSettings<PCBNEW_SETTINGS>();
app_settings->m_ColorTheme = m_currentSettings->GetFilename(); app_settings->m_ColorTheme = m_currentSettings->GetFilename();
m_frame->GetAppearancePanel()->OnColorThemeChanged();
return true; return true;
} }

View File

@ -1039,6 +1039,11 @@ void FOOTPRINT_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTe
{ {
PCB_BASE_EDIT_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged ); PCB_BASE_EDIT_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
GetCanvas()->GetView()->UpdateAllLayersColor();
GetCanvas()->ForceRefresh();
UpdateUserInterface();
if( aEnvVarsChanged ) if( aEnvVarsChanged )
SyncLibraryTree( true ); SyncLibraryTree( true );

View File

@ -767,6 +767,8 @@ void PCB_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars
{ {
EDA_DRAW_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged ); EDA_DRAW_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
GetCanvas()->GetView()->GetPainter()->GetSettings()->LoadColors( GetColorSettings() );
RecreateToolbars(); RecreateToolbars();
// The 3D viewer isn't in the Kiway, so send its update manually // The 3D viewer isn't in the Kiway, so send its update manually

View File

@ -231,8 +231,6 @@ void PCB_DRAW_PANEL_GAL::UpdateColors()
wxCHECK_RET( cs, "null COLOR_SETTINGS" ); wxCHECK_RET( cs, "null COLOR_SETTINGS" );
Pgm().GetSettingsManager().SaveColorSettings( cs, "board" );
auto rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( m_view->GetPainter()->GetSettings() ); auto rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( m_view->GetPainter()->GetSettings() );
rs->LoadColors( cs ); rs->LoadColors( cs );

View File

@ -1584,6 +1584,7 @@ void PCB_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars
{ {
PCB_BASE_EDIT_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged ); PCB_BASE_EDIT_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
GetAppearancePanel()->OnColorThemeChanged();
ReCreateMicrowaveVToolbar(); ReCreateMicrowaveVToolbar();
if( aTextVarsChanged ) if( aTextVarsChanged )