Namespace the env_vars.h functions
This commit is contained in:
parent
0f27618125
commit
7802037495
|
@ -185,7 +185,7 @@ void DIALOG_CONFIGURE_PATHS::AppendEnvVar( const wxString& aName, const wxString
|
||||||
wxGridCellTextEditor* nameTextEditor = new GRID_CELL_TEXT_EDITOR();
|
wxGridCellTextEditor* nameTextEditor = new GRID_CELL_TEXT_EDITOR();
|
||||||
nameTextEditor->SetValidator( ENV_VAR_NAME_VALIDATOR() );
|
nameTextEditor->SetValidator( ENV_VAR_NAME_VALIDATOR() );
|
||||||
nameCellAttr->SetEditor( nameTextEditor );
|
nameCellAttr->SetEditor( nameTextEditor );
|
||||||
nameCellAttr->SetReadOnly( IsEnvVarImmutable( aName ) );
|
nameCellAttr->SetReadOnly( ENV_VAR::IsEnvVarImmutable( aName ) );
|
||||||
nameCellAttr->DecRef();
|
nameCellAttr->DecRef();
|
||||||
|
|
||||||
m_EnvVars->SetCellValue( i, TV_VALUE_COL, aPath );
|
m_EnvVars->SetCellValue( i, TV_VALUE_COL, aPath );
|
||||||
|
@ -405,7 +405,7 @@ void DIALOG_CONFIGURE_PATHS::OnRemoveEnvVar( wxCommandEvent& event )
|
||||||
|
|
||||||
if( curRow < 0 || m_EnvVars->GetNumberRows() <= curRow )
|
if( curRow < 0 || m_EnvVars->GetNumberRows() <= curRow )
|
||||||
return;
|
return;
|
||||||
else if( IsEnvVarImmutable( m_EnvVars->GetCellValue( curRow, TV_NAME_COL ) ) )
|
else if( ENV_VAR::IsEnvVarImmutable( m_EnvVars->GetCellValue( curRow, TV_NAME_COL ) ) )
|
||||||
{
|
{
|
||||||
wxBell();
|
wxBell();
|
||||||
return;
|
return;
|
||||||
|
@ -586,11 +586,11 @@ void DIALOG_CONFIGURE_PATHS::OnHelp( wxCommandEvent& event )
|
||||||
"will only accept upper case letters, digits, and the underscore characters." );
|
"will only accept upper case letters, digits, and the underscore characters." );
|
||||||
msg << "</b>";
|
msg << "</b>";
|
||||||
|
|
||||||
for( const auto& var: GetPredefinedEnvVars() )
|
for( const auto& var : ENV_VAR::GetPredefinedEnvVars() )
|
||||||
{
|
{
|
||||||
msg << "<br><br><b>" << var << "</b>";
|
msg << "<br><br><b>" << var << "</b>";
|
||||||
|
|
||||||
const auto desc = LookUpEnvVarHelp( var );
|
const auto desc = ENV_VAR::LookUpEnvVarHelp( var );
|
||||||
|
|
||||||
if( desc.size() > 0 )
|
if( desc.size() > 0 )
|
||||||
msg << ": " << desc;
|
msg << ": " << desc;
|
||||||
|
|
|
@ -33,7 +33,7 @@ using STRING_MAP = std::map<wxString, wxString>;
|
||||||
* extract them from elsewhere in the program
|
* extract them from elsewhere in the program
|
||||||
* (where they are originally defined)
|
* (where they are originally defined)
|
||||||
*/
|
*/
|
||||||
static const ENV_VAR_LIST predefined_env_vars = {
|
static const ENV_VAR::ENV_VAR_LIST predefinedEnvVars = {
|
||||||
"KIPRJMOD",
|
"KIPRJMOD",
|
||||||
"KICAD6_SYMBOL_DIR",
|
"KICAD6_SYMBOL_DIR",
|
||||||
"KICAD6_3DMODEL_DIR",
|
"KICAD6_3DMODEL_DIR",
|
||||||
|
@ -44,9 +44,9 @@ static const ENV_VAR_LIST predefined_env_vars = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
bool IsEnvVarImmutable( const wxString& aEnvVar )
|
bool ENV_VAR::IsEnvVarImmutable( const wxString& aEnvVar )
|
||||||
{
|
{
|
||||||
for( const auto& s: predefined_env_vars )
|
for( const auto& s : predefinedEnvVars )
|
||||||
{
|
{
|
||||||
if( s == aEnvVar )
|
if( s == aEnvVar )
|
||||||
return true;
|
return true;
|
||||||
|
@ -56,13 +56,13 @@ bool IsEnvVarImmutable( const wxString& aEnvVar )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const ENV_VAR_LIST& GetPredefinedEnvVars()
|
const ENV_VAR::ENV_VAR_LIST& ENV_VAR::GetPredefinedEnvVars()
|
||||||
{
|
{
|
||||||
return predefined_env_vars;
|
return predefinedEnvVars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void initialiseEnvVarHelp( STRING_MAP& aMap )
|
static void initialiseEnvVarHelp( STRING_MAP& aMap )
|
||||||
{
|
{
|
||||||
// Set up dynamically, as we want to be able to use _() translations,
|
// Set up dynamically, as we want to be able to use _() translations,
|
||||||
// which can't be done statically
|
// which can't be done statically
|
||||||
|
@ -101,21 +101,21 @@ void initialiseEnvVarHelp( STRING_MAP& aMap )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxString LookUpEnvVarHelp( const wxString& aEnvVar )
|
wxString ENV_VAR::LookUpEnvVarHelp( const wxString& aEnvVar )
|
||||||
{
|
{
|
||||||
static STRING_MAP env_var_help_text;
|
static STRING_MAP envVarHelpText;
|
||||||
|
|
||||||
if( env_var_help_text.size() == 0 )
|
if( envVarHelpText.size() == 0 )
|
||||||
initialiseEnvVarHelp( env_var_help_text );
|
initialiseEnvVarHelp( envVarHelpText );
|
||||||
|
|
||||||
return env_var_help_text[aEnvVar];
|
return envVarHelpText[ aEnvVar ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
OPT<double> GetEnvVar( const wxString& aEnvVarName )
|
OPT<double> ENV_VAR::GetEnvVar( const wxString& aEnvVarName )
|
||||||
{
|
{
|
||||||
OPT<double> opt_value;
|
OPT<double> optValue;
|
||||||
|
|
||||||
wxString env;
|
wxString env;
|
||||||
if( wxGetEnv( aEnvVarName, &env ) )
|
if( wxGetEnv( aEnvVarName, &env ) )
|
||||||
|
@ -123,23 +123,23 @@ OPT<double> GetEnvVar( const wxString& aEnvVarName )
|
||||||
double value;
|
double value;
|
||||||
if( env.ToDouble( &value ) )
|
if( env.ToDouble( &value ) )
|
||||||
{
|
{
|
||||||
opt_value = value;
|
optValue = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return opt_value;
|
return optValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
OPT<wxString> GetEnvVar( const wxString& aEnvVarName )
|
OPT<wxString> ENV_VAR::GetEnvVar( const wxString& aEnvVarName )
|
||||||
{
|
{
|
||||||
OPT<wxString> opt_value;
|
OPT<wxString> optValue;
|
||||||
|
|
||||||
wxString env;
|
wxString env;
|
||||||
if( wxGetEnv( aEnvVarName, &env ) )
|
if( wxGetEnv( aEnvVarName, &env ) )
|
||||||
{
|
{
|
||||||
opt_value = env;
|
optValue = env;
|
||||||
}
|
}
|
||||||
|
|
||||||
return opt_value;
|
return optValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ static OPT<double> getEnvironmentScale()
|
||||||
if( port_id == wxPORT_GTK )
|
if( port_id == wxPORT_GTK )
|
||||||
{
|
{
|
||||||
// Under GTK, the user can use GDK_SCALE to force the scaling
|
// Under GTK, the user can use GDK_SCALE to force the scaling
|
||||||
scale = GetEnvVar<double>( "GDK_SCALE" );
|
scale = ENV_VAR::GetEnvVar<double>( "GDK_SCALE" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( scale )
|
if( scale )
|
||||||
|
|
|
@ -68,15 +68,4 @@ wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars
|
||||||
wxString ResolveFile( const wxString& aFileName, const ENV_VAR_MAP* aEnvVars,
|
wxString ResolveFile( const wxString& aFileName, const ENV_VAR_MAP* aEnvVars,
|
||||||
const PROJECT* aProject );
|
const PROJECT* aProject );
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a given filename is within a given project directory (not whether it exists!)
|
|
||||||
*
|
|
||||||
* @param aFileName is the absolute path to check
|
|
||||||
* @param aProject is the project to test against
|
|
||||||
* @param aSubPath will be filled with the relative path to the file inside the project (if any)
|
|
||||||
* @return true if aFileName's path is inside aProject's path
|
|
||||||
*/
|
|
||||||
bool PathIsInsideProject( const wxString& aFileName, const PROJECT* aProject,
|
|
||||||
wxFileName* aSubPath = nullptr );
|
|
||||||
|
|
||||||
#endif /* ENV_PATHS_H */
|
#endif /* ENV_PATHS_H */
|
||||||
|
|
|
@ -26,66 +26,66 @@
|
||||||
#define ENV_VARS_H
|
#define ENV_VARS_H
|
||||||
|
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <core/optional.h>
|
#include <core/optional.h>
|
||||||
|
|
||||||
using ENV_VAR_LIST = std::vector<wxString>;
|
namespace ENV_VAR
|
||||||
|
{
|
||||||
|
using ENV_VAR_LIST = std::vector<wxString>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if an environment variable is "predefined", i.e. if the
|
* Determine if an environment variable is "predefined", i.e. if the
|
||||||
* name of the variable is special to KiCad, and isn't just a user-specified
|
* name of the variable is special to KiCad, and isn't just a user-specified
|
||||||
* substitution name.
|
* substitution name.
|
||||||
* @param aEnvVar the variable to check
|
* @param aEnvVar the variable to check
|
||||||
* @return true if predefined
|
* @return true if predefined
|
||||||
*/
|
*/
|
||||||
bool IsEnvVarImmutable( const wxString& aEnvVar );
|
bool IsEnvVarImmutable( const wxString& aEnvVar );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of pre-defined environment variables.
|
* Get the list of pre-defined environment variables.
|
||||||
*/
|
*/
|
||||||
const ENV_VAR_LIST& GetPredefinedEnvVars();
|
const ENV_VAR_LIST& GetPredefinedEnvVars();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look up long-form help text for a given environment variable.
|
* Look up long-form help text for a given environment variable.
|
||||||
*
|
*
|
||||||
* This is intended for use in more verbose help resources (as opposed to
|
* This is intended for use in more verbose help resources (as opposed to
|
||||||
* tooltip text)
|
* tooltip text)
|
||||||
*
|
*
|
||||||
* @param aEnvVar The variable to look up
|
* @param aEnvVar The variable to look up
|
||||||
* @return A string with help for that variable. Empty if
|
* @return A string with help for that variable. Empty if
|
||||||
* no help available for this variable.
|
* no help available for this variable.
|
||||||
*/
|
*/
|
||||||
wxString LookUpEnvVarHelp( const wxString& aEnvVar );
|
wxString LookUpEnvVarHelp( const wxString& aEnvVar );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an environment variable as a specific type, if set correctly
|
* Get an environment variable as a specific type, if set correctly
|
||||||
*
|
*
|
||||||
* @param aEnvVarName the name of the environment variable
|
* @param aEnvVarName the name of the environment variable
|
||||||
* @return an OPT containing the value, if set and parseable, otherwise empty.
|
* @return an OPT containing the value, if set and parseable, otherwise empty.
|
||||||
*/
|
*/
|
||||||
template <typename VAL_TYPE>
|
template <typename VAL_TYPE>
|
||||||
OPT<VAL_TYPE> GetEnvVar( const wxString& aEnvVarName );
|
OPT<VAL_TYPE> GetEnvVar( const wxString& aEnvVarName );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a string environment variable, if it is set.
|
* Get a string environment variable, if it is set.
|
||||||
*
|
*
|
||||||
* @param aEnvVarName the name of the environment variable
|
* @param aEnvVarName the name of the environment variable
|
||||||
* @return an OPT containing the value, if set, otherwise empty.
|
* @return an OPT containing the value, if set, otherwise empty.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
OPT<wxString> GetEnvVar( const wxString& aEnvVarName );
|
OPT<wxString> GetEnvVar( const wxString& aEnvVarName );
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a double from an environment variable, if set
|
|
||||||
*
|
|
||||||
* @param aEnvVarName the name of the environment variable
|
|
||||||
* @return an OPT containing the value, if set and parseable as a double,
|
|
||||||
* otherwise empty.
|
|
||||||
*/
|
|
||||||
template <>
|
|
||||||
OPT<double> GetEnvVar( const wxString& aEnvVarName );
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a double from an environment variable, if set
|
||||||
|
*
|
||||||
|
* @param aEnvVarName the name of the environment variable
|
||||||
|
* @return an OPT containing the value, if set and parseable as a double,
|
||||||
|
* otherwise empty.
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
OPT<double> GetEnvVar( const wxString& aEnvVarName );
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* ENV_VARS_H */
|
#endif /* ENV_VARS_H */
|
||||||
|
|
Loading…
Reference in New Issue