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)
|
// Set up built-in environment variables (and override them from the system environment if set)
|
||||||
GetCommonSettings()->InitializeEnvironment();
|
GetCommonSettings()->InitializeEnvironment();
|
||||||
|
|
||||||
|
// Load color settings after env is initialized
|
||||||
|
m_settings_manager->ReloadColorSettings();
|
||||||
|
|
||||||
// Load common settings from disk after setting up env vars
|
// Load common settings from disk after setting up env vars
|
||||||
GetSettingsManager().Load( GetCommonSettings() );
|
GetSettingsManager().Load( GetCommonSettings() );
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <kiway.h>
|
#include <kiway.h>
|
||||||
#include <lockfile.h>
|
#include <lockfile.h>
|
||||||
#include <macros.h>
|
#include <macros.h>
|
||||||
|
#include <pgm_base.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <project.h>
|
#include <project.h>
|
||||||
#include <project/project_archiver.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
|
// create the common settings shared by all applications. Not loaded immediately
|
||||||
m_common_settings = RegisterSettings( new COMMON_SETTINGS, false );
|
m_common_settings = RegisterSettings( new COMMON_SETTINGS, false );
|
||||||
|
|
||||||
loadAllColorSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SETTINGS_MANAGER::~SETTINGS_MANAGER()
|
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:
|
private:
|
||||||
std::function<void( const wxString& )> m_action;
|
std::function<void( const wxFileName& )> m_action;
|
||||||
|
|
||||||
public:
|
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 ) )
|
: m_action( std::move( aAction ) )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -241,17 +240,15 @@ public:
|
||||||
{
|
{
|
||||||
wxFileName file( aFilePath );
|
wxFileName file( aFilePath );
|
||||||
|
|
||||||
if( file.GetExt() != "json" )
|
if( file.GetExt() == "json" )
|
||||||
return wxDIR_CONTINUE;
|
m_action( file );
|
||||||
|
|
||||||
m_action( file.GetName() );
|
|
||||||
|
|
||||||
return wxDIR_CONTINUE;
|
return wxDIR_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDirTraverseResult OnDir( const wxString& dirPath ) override
|
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() )
|
for( COLOR_SETTINGS* settings : COLOR_SETTINGS::CreateBuiltinColorSettings() )
|
||||||
m_color_settings[settings->GetFilename()] = RegisterSettings( settings, false );
|
m_color_settings[settings->GetFilename()] = RegisterSettings( settings, false );
|
||||||
|
|
||||||
// Search for and load any other settings
|
wxFileName third_party_path;
|
||||||
COLOR_SETTINGS_LOADER loader( [&]( const wxString& aFilename )
|
const ENV_VAR_MAP& env = Pgm().GetLocalEnvVariables();
|
||||||
|
auto it = env.find( "KICAD6_3RD_PARTY" );
|
||||||
|
|
||||||
|
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 )
|
||||||
{
|
{
|
||||||
registerColorSettings( aFilename );
|
wxFileName new_file( color_settings_path, aFilename.GetFullName() );
|
||||||
|
|
||||||
|
if( !new_file.Exists() )
|
||||||
|
wxCopyFile( aFilename.GetFullPath(), new_file.GetFullPath());
|
||||||
} );
|
} );
|
||||||
|
|
||||||
wxDir colors_dir( GetColorSettingsPath() );
|
// 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( colors_dir.IsOpened() )
|
||||||
|
{
|
||||||
|
if( third_party_colors_dir.IsOpened() )
|
||||||
|
third_party_colors_dir.Traverse( copier );
|
||||||
|
|
||||||
colors_dir.Traverse( loader );
|
colors_dir.Traverse( loader );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,8 @@
|
||||||
|
|
||||||
static std::vector<std::pair<PCM_PACKAGE_TYPE, wxString>> PACKAGE_TYPE_LIST = {
|
static std::vector<std::pair<PCM_PACKAGE_TYPE, wxString>> PACKAGE_TYPE_LIST = {
|
||||||
{ PT_PLUGIN, _( "Plugins (%d)" ) },
|
{ 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",
|
"models",
|
||||||
"symbols",
|
"symbols",
|
||||||
"resources",
|
"resources",
|
||||||
|
"colors",
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ enum PCM_PACKAGE_TYPE
|
||||||
PT_INVALID,
|
PT_INVALID,
|
||||||
PT_PLUGIN,
|
PT_PLUGIN,
|
||||||
PT_LIBRARY,
|
PT_LIBRARY,
|
||||||
|
PT_COLORTHEME,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -159,6 +160,7 @@ NLOHMANN_JSON_SERIALIZE_ENUM( PCM_PACKAGE_TYPE, {
|
||||||
{ PT_INVALID, "invalid" },
|
{ PT_INVALID, "invalid" },
|
||||||
{ PT_PLUGIN, "plugin" },
|
{ PT_PLUGIN, "plugin" },
|
||||||
{ PT_LIBRARY, "library" },
|
{ PT_LIBRARY, "library" },
|
||||||
|
{ PT_COLORTHEME, "colortheme" },
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,8 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
"plugin",
|
"plugin",
|
||||||
"library"
|
"library",
|
||||||
|
"colortheme"
|
||||||
],
|
],
|
||||||
"description": "Type of the package"
|
"description": "Type of the package"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue