Add colortheme package type
This commit is contained in:
parent
0f7c0e3872
commit
a1521d338e
|
@ -257,6 +257,9 @@ bool PGM_BASE::InitPgm( bool aHeadless, bool aSkipPyInit )
|
|||
// Set up built-in environment variables (and override them from the system environment if set)
|
||||
GetCommonSettings()->InitializeEnvironment();
|
||||
|
||||
// Load color settings after env is initialized
|
||||
m_settings_manager->ReloadColorSettings();
|
||||
|
||||
// Load common settings from disk after setting up env vars
|
||||
GetSettingsManager().Load( GetCommonSettings() );
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <kiway.h>
|
||||
#include <lockfile.h>
|
||||
#include <macros.h>
|
||||
#include <pgm_base.h>
|
||||
#include <paths.h>
|
||||
#include <project.h>
|
||||
#include <project/project_archiver.h>
|
||||
|
@ -70,8 +71,6 @@ 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 );
|
||||
|
||||
loadAllColorSettings();
|
||||
}
|
||||
|
||||
SETTINGS_MANAGER::~SETTINGS_MANAGER()
|
||||
|
@ -226,13 +225,13 @@ COLOR_SETTINGS* SETTINGS_MANAGER::loadColorSettingsByName( const wxString& aName
|
|||
}
|
||||
|
||||
|
||||
class COLOR_SETTINGS_LOADER : public wxDirTraverser
|
||||
class JSON_DIR_TRAVERSER : public wxDirTraverser
|
||||
{
|
||||
private:
|
||||
std::function<void( const wxString& )> m_action;
|
||||
std::function<void( const wxFileName& )> m_action;
|
||||
|
||||
public:
|
||||
explicit COLOR_SETTINGS_LOADER( std::function<void( const wxString& )> aAction )
|
||||
explicit JSON_DIR_TRAVERSER( std::function<void( const wxFileName& )> aAction )
|
||||
: m_action( std::move( aAction ) )
|
||||
{
|
||||
}
|
||||
|
@ -241,17 +240,15 @@ public:
|
|||
{
|
||||
wxFileName file( aFilePath );
|
||||
|
||||
if( file.GetExt() != "json" )
|
||||
return wxDIR_CONTINUE;
|
||||
|
||||
m_action( file.GetName() );
|
||||
if( file.GetExt() == "json" )
|
||||
m_action( file );
|
||||
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
|
||||
wxDirTraverseResult OnDir( const wxString& dirPath ) override
|
||||
{
|
||||
return wxDIR_IGNORE;
|
||||
return wxDIR_CONTINUE;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -296,16 +293,44 @@ void SETTINGS_MANAGER::loadAllColorSettings()
|
|||
for( COLOR_SETTINGS* settings : COLOR_SETTINGS::CreateBuiltinColorSettings() )
|
||||
m_color_settings[settings->GetFilename()] = RegisterSettings( settings, false );
|
||||
|
||||
// Search for and load any other settings
|
||||
COLOR_SETTINGS_LOADER loader( [&]( const wxString& aFilename )
|
||||
{
|
||||
registerColorSettings( aFilename );
|
||||
} );
|
||||
wxFileName third_party_path;
|
||||
const ENV_VAR_MAP& env = Pgm().GetLocalEnvVariables();
|
||||
auto it = env.find( "KICAD6_3RD_PARTY" );
|
||||
|
||||
wxDir colors_dir( GetColorSettingsPath() );
|
||||
if( it != env.end() && !it->second.GetValue().IsEmpty() )
|
||||
third_party_path.SetPath( it->second.GetValue() );
|
||||
else
|
||||
third_party_path.SetPath( PATHS::GetDefault3rdPartyPath() );
|
||||
|
||||
third_party_path.AppendDir( "colors" );
|
||||
|
||||
wxDir third_party_colors_dir( third_party_path.GetFullPath() );
|
||||
wxString color_settings_path = GetColorSettingsPath();
|
||||
|
||||
JSON_DIR_TRAVERSER copier(
|
||||
[&]( const wxFileName& aFilename )
|
||||
{
|
||||
wxFileName new_file( color_settings_path, aFilename.GetFullName() );
|
||||
|
||||
if( !new_file.Exists() )
|
||||
wxCopyFile( aFilename.GetFullPath(), new_file.GetFullPath());
|
||||
} );
|
||||
|
||||
// Search for and load any other settings
|
||||
JSON_DIR_TRAVERSER loader( [&]( const wxFileName& aFilename )
|
||||
{
|
||||
registerColorSettings( aFilename.GetName() );
|
||||
} );
|
||||
|
||||
wxDir colors_dir( color_settings_path );
|
||||
|
||||
if( colors_dir.IsOpened() )
|
||||
{
|
||||
if( third_party_colors_dir.IsOpened() )
|
||||
third_party_colors_dir.Traverse( copier );
|
||||
|
||||
colors_dir.Traverse( loader );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -44,7 +44,8 @@
|
|||
|
||||
static std::vector<std::pair<PCM_PACKAGE_TYPE, wxString>> PACKAGE_TYPE_LIST = {
|
||||
{ PT_PLUGIN, _( "Plugins (%d)" ) },
|
||||
{ PT_LIBRARY, _( "Libraries (%d)" ) }
|
||||
{ PT_LIBRARY, _( "Libraries (%d)" ) },
|
||||
{ PT_COLORTHEME, _( "Color themes (%d)" ) },
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ const std::unordered_set<wxString> PCM_PACKAGE_DIRECTORIES( {
|
|||
"models",
|
||||
"symbols",
|
||||
"resources",
|
||||
"colors",
|
||||
} );
|
||||
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ enum PCM_PACKAGE_TYPE
|
|||
PT_INVALID,
|
||||
PT_PLUGIN,
|
||||
PT_LIBRARY,
|
||||
PT_COLORTHEME,
|
||||
};
|
||||
|
||||
|
||||
|
@ -159,6 +160,7 @@ NLOHMANN_JSON_SERIALIZE_ENUM( PCM_PACKAGE_TYPE, {
|
|||
{ PT_INVALID, "invalid" },
|
||||
{ PT_PLUGIN, "plugin" },
|
||||
{ PT_LIBRARY, "library" },
|
||||
{ PT_COLORTHEME, "colortheme" },
|
||||
} )
|
||||
|
||||
|
||||
|
|
|
@ -32,7 +32,8 @@
|
|||
"type": "string",
|
||||
"enum": [
|
||||
"plugin",
|
||||
"library"
|
||||
"library",
|
||||
"colortheme"
|
||||
],
|
||||
"description": "Type of the package"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue