From 780203749526352e345c5c71023b16c7da03cacc Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Mon, 21 Jun 2021 20:35:11 -0400 Subject: [PATCH] Namespace the env_vars.h functions --- common/dialogs/dialog_configure_paths.cpp | 8 +- common/env_vars.cpp | 38 ++++---- common/gal/dpi_scaling.cpp | 2 +- include/env_paths.h | 11 --- include/env_vars.h | 104 +++++++++++----------- 5 files changed, 76 insertions(+), 87 deletions(-) diff --git a/common/dialogs/dialog_configure_paths.cpp b/common/dialogs/dialog_configure_paths.cpp index 9058140bfd..78e3efe76a 100644 --- a/common/dialogs/dialog_configure_paths.cpp +++ b/common/dialogs/dialog_configure_paths.cpp @@ -185,7 +185,7 @@ void DIALOG_CONFIGURE_PATHS::AppendEnvVar( const wxString& aName, const wxString wxGridCellTextEditor* nameTextEditor = new GRID_CELL_TEXT_EDITOR(); nameTextEditor->SetValidator( ENV_VAR_NAME_VALIDATOR() ); nameCellAttr->SetEditor( nameTextEditor ); - nameCellAttr->SetReadOnly( IsEnvVarImmutable( aName ) ); + nameCellAttr->SetReadOnly( ENV_VAR::IsEnvVarImmutable( aName ) ); nameCellAttr->DecRef(); 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 ) return; - else if( IsEnvVarImmutable( m_EnvVars->GetCellValue( curRow, TV_NAME_COL ) ) ) + else if( ENV_VAR::IsEnvVarImmutable( m_EnvVars->GetCellValue( curRow, TV_NAME_COL ) ) ) { wxBell(); return; @@ -586,11 +586,11 @@ void DIALOG_CONFIGURE_PATHS::OnHelp( wxCommandEvent& event ) "will only accept upper case letters, digits, and the underscore characters." ); msg << ""; - for( const auto& var: GetPredefinedEnvVars() ) + for( const auto& var : ENV_VAR::GetPredefinedEnvVars() ) { msg << "

" << var << ""; - const auto desc = LookUpEnvVarHelp( var ); + const auto desc = ENV_VAR::LookUpEnvVarHelp( var ); if( desc.size() > 0 ) msg << ": " << desc; diff --git a/common/env_vars.cpp b/common/env_vars.cpp index 2f6c15e6ad..267942c17c 100644 --- a/common/env_vars.cpp +++ b/common/env_vars.cpp @@ -33,7 +33,7 @@ using STRING_MAP = std::map; * extract them from elsewhere in the program * (where they are originally defined) */ -static const ENV_VAR_LIST predefined_env_vars = { +static const ENV_VAR::ENV_VAR_LIST predefinedEnvVars = { "KIPRJMOD", "KICAD6_SYMBOL_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 ) 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, // 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 ) - initialiseEnvVarHelp( env_var_help_text ); + if( envVarHelpText.size() == 0 ) + initialiseEnvVarHelp( envVarHelpText ); - return env_var_help_text[aEnvVar]; + return envVarHelpText[ aEnvVar ]; } template<> -OPT GetEnvVar( const wxString& aEnvVarName ) +OPT ENV_VAR::GetEnvVar( const wxString& aEnvVarName ) { - OPT opt_value; + OPT optValue; wxString env; if( wxGetEnv( aEnvVarName, &env ) ) @@ -123,23 +123,23 @@ OPT GetEnvVar( const wxString& aEnvVarName ) double value; if( env.ToDouble( &value ) ) { - opt_value = value; + optValue = value; } } - return opt_value; + return optValue; } template<> -OPT GetEnvVar( const wxString& aEnvVarName ) +OPT ENV_VAR::GetEnvVar( const wxString& aEnvVarName ) { - OPT opt_value; + OPT optValue; wxString env; if( wxGetEnv( aEnvVarName, &env ) ) { - opt_value = env; + optValue = env; } - return opt_value; + return optValue; } diff --git a/common/gal/dpi_scaling.cpp b/common/gal/dpi_scaling.cpp index 862d8d1523..9931f3e8e9 100644 --- a/common/gal/dpi_scaling.cpp +++ b/common/gal/dpi_scaling.cpp @@ -80,7 +80,7 @@ static OPT getEnvironmentScale() if( port_id == wxPORT_GTK ) { // Under GTK, the user can use GDK_SCALE to force the scaling - scale = GetEnvVar( "GDK_SCALE" ); + scale = ENV_VAR::GetEnvVar( "GDK_SCALE" ); } if( scale ) diff --git a/include/env_paths.h b/include/env_paths.h index 88011632f2..2fab984285 100644 --- a/include/env_paths.h +++ b/include/env_paths.h @@ -68,15 +68,4 @@ wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars wxString ResolveFile( const wxString& aFileName, const ENV_VAR_MAP* aEnvVars, 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 */ diff --git a/include/env_vars.h b/include/env_vars.h index d2200a4c2a..78c278d97f 100644 --- a/include/env_vars.h +++ b/include/env_vars.h @@ -26,66 +26,66 @@ #define ENV_VARS_H #include - #include - #include -using ENV_VAR_LIST = std::vector; +namespace ENV_VAR +{ + using ENV_VAR_LIST = std::vector; -/** - * 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 - * substitution name. - * @param aEnvVar the variable to check - * @return true if predefined - */ -bool IsEnvVarImmutable( const wxString& aEnvVar ); + /** + * 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 + * substitution name. + * @param aEnvVar the variable to check + * @return true if predefined + */ + bool IsEnvVarImmutable( const wxString& aEnvVar ); -/** - * Get the list of pre-defined environment variables. - */ -const ENV_VAR_LIST& GetPredefinedEnvVars(); + /** + * Get the list of pre-defined environment variables. + */ + const ENV_VAR_LIST& GetPredefinedEnvVars(); -/** - * Look up long-form help text for a given environment variable. - * - * This is intended for use in more verbose help resources (as opposed to - * tooltip text) - * - * @param aEnvVar The variable to look up - * @return A string with help for that variable. Empty if - * no help available for this variable. - */ -wxString LookUpEnvVarHelp( const wxString& aEnvVar ); + /** + * Look up long-form help text for a given environment variable. + * + * This is intended for use in more verbose help resources (as opposed to + * tooltip text) + * + * @param aEnvVar The variable to look up + * @return A string with help for that variable. Empty if + * no help available for this variable. + */ + wxString LookUpEnvVarHelp( const wxString& aEnvVar ); -/** - * Get an environment variable as a specific type, if set correctly - * - * @param aEnvVarName the name of the environment variable - * @return an OPT containing the value, if set and parseable, otherwise empty. - */ -template -OPT GetEnvVar( const wxString& aEnvVarName ); + /** + * Get an environment variable as a specific type, if set correctly + * + * @param aEnvVarName the name of the environment variable + * @return an OPT containing the value, if set and parseable, otherwise empty. + */ + template + OPT GetEnvVar( const wxString& aEnvVarName ); -/** - * Get a string environment variable, if it is set. - * - * @param aEnvVarName the name of the environment variable - * @return an OPT containing the value, if set, otherwise empty. - */ -template<> -OPT 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 GetEnvVar( const wxString& aEnvVarName ); + /** + * Get a string environment variable, if it is set. + * + * @param aEnvVarName the name of the environment variable + * @return an OPT containing the value, if set, otherwise empty. + */ + template<> + OPT 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 GetEnvVar( const wxString& aEnvVarName ); +}; #endif /* ENV_VARS_H */