From aee6d9d01c28912c5a0b3e5b9d0b88a66eee6d49 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Fri, 17 Feb 2023 13:32:11 -0300 Subject: [PATCH] Create the built-in colors in the constructor This is needed so Python scripts can get built-in colors using the SETTINGS_MANAGER.GetColorSettings() member. Otherwise calling it with a built-in name crashes. --- common/settings/settings_manager.cpp | 14 ++++++++++++-- include/settings/settings_manager.h | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/common/settings/settings_manager.cpp b/common/settings/settings_manager.cpp index 9b610ef4f1..958e9fc2f5 100644 --- a/common/settings/settings_manager.cpp +++ b/common/settings/settings_manager.cpp @@ -66,6 +66,10 @@ SETTINGS_MANAGER::SETTINGS_MANAGER( bool aHeadless ) : // create the common settings shared by all applications. Not loaded immediately m_common_settings = RegisterSettings( new COMMON_SETTINGS, false ); + + // Create the built-in color settings + // Here to allow the Python API to access the built-in colors + registerBuiltinColorSettings(); } SETTINGS_MANAGER::~SETTINGS_MANAGER() @@ -305,11 +309,17 @@ COLOR_SETTINGS* SETTINGS_MANAGER::GetMigratedColorSettings() } +void SETTINGS_MANAGER::registerBuiltinColorSettings() +{ + for( COLOR_SETTINGS* settings : COLOR_SETTINGS::CreateBuiltinColorSettings() ) + m_color_settings[settings->GetFilename()] = RegisterSettings( settings, false ); +} + + void SETTINGS_MANAGER::loadAllColorSettings() { // Create the built-in color settings - for( COLOR_SETTINGS* settings : COLOR_SETTINGS::CreateBuiltinColorSettings() ) - m_color_settings[settings->GetFilename()] = RegisterSettings( settings, false ); + registerBuiltinColorSettings(); wxFileName third_party_path; const ENV_VAR_MAP& env = Pgm().GetLocalEnvVariables(); diff --git a/include/settings/settings_manager.h b/include/settings/settings_manager.h index 69128e138e..c1d8779493 100644 --- a/include/settings/settings_manager.h +++ b/include/settings/settings_manager.h @@ -414,6 +414,9 @@ private: */ bool unloadProjectFile( PROJECT* aProject, bool aSave ); + // Helper to create built-in colors and register them + void registerBuiltinColorSettings(); + private: /// True if running outside a UI context