80 wxGridCellAttr* attr =
new wxGridCellAttr;
85 [
this]( wxCommandEvent& aEvent )
90 m_EnvVars->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
96 m_EnvVars->Connect( wxEVT_GRID_CELL_CHANGING,
102 GetSizer()->SetSizeHints(
this );
112 m_EnvVars->Disconnect( wxEVT_GRID_CELL_CHANGING,
120 if( !wxDialog::TransferDataToWindow() )
125 for(
auto it = envVars.begin(); it != envVars.end(); ++it )
127 const wxString&
path = it->second.GetValue();
130 if(
m_curdir.IsEmpty() && !
path.StartsWith(
"${" ) && !
path.StartsWith(
"$(" ) )
137 wxRegEx envVarRegex( wxS(
".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?" ), wxRE_ADVANCED );
138 std::set<wxString> foundEnvVars;
149 std::vector<LIBRARY_TABLE_ROW*> rows = libMgr.
Rows( tableType, scope,
true );
153 wxString uri = row->URI();
155 while( envVarRegex.Matches( uri ) )
157 wxString envvar = envVarRegex.GetMatch( uri, 2 );
159 if( envvar.IsEmpty() )
160 envvar = envVarRegex.GetMatch( uri, 4 );
162 if( !envvar.IsEmpty() )
163 foundEnvVars.insert( envvar );
165 uri.Replace( envVarRegex.GetMatch( uri, 0 ), wxEmptyString );
171 for(
const wxString& envvar : foundEnvVars )
176 bool isExternal = wxGetEnv( envvar, &value );
180 if( value.IsEmpty() && !isExternal )
182 wxString token = wxString::Format( wxS(
"${%s}" ), envvar );
185 if( resolved != token )
209 nameCellAttr->SetEditor( nameTextEditor );
211 nameCellAttr->DecRef();
216 wxSystemColour c = isExternal ? wxSYS_COLOUR_MENU : wxSYS_COLOUR_LISTBOX;
217 pathCellAttr->SetBackgroundColour( wxSystemSettings::GetColour( c ) );
218 pathCellAttr->DecRef();
229 if( !wxDialog::TransferDataFromWindow() )
235 for(
int row = 0; row <
m_EnvVars->GetNumberRows(); ++row )
245 else if(
name.empty() &&
path.empty() )
250 else if(
name.IsEmpty() )
255 m_errorMsg =
_(
"Environment variable name cannot be empty." );
258 else if(
path.IsEmpty() )
263 m_errorMsg =
_(
"Environment variable path cannot be empty." );
267 if( envVarMap.count(
name ) )
268 envVarMap.at(
name ).SetValue(
path );
274 for(
auto it = envVarMap.begin(); it != envVarMap.end(); )
278 for(
int row = 0; row <
m_EnvVars->GetNumberRows(); ++row )
282 if( it->first ==
name )
292 it = envVarMap.erase( it );
303 wxGrid*
grid =
dynamic_cast<wxGrid*
>(
event.GetEventObject() );
307 if(
grid &&
grid->IsCellEditControlEnabled() )
310 int row =
event.GetRow();
311 int col =
event.GetCol();
312 wxString
text =
event.GetString();
314 text.Trim(
true ).Trim(
false );
315 grid->SetCellValue( row, col,
text );
322 m_errorMsg =
_(
"Environment variable name cannot be empty." );
324 m_errorMsg =
_(
"Environment variable path cannot be empty." );
329 m_errorMsg =
_(
"3D search path alias cannot be empty." );
331 m_errorMsg =
_(
"3D search path cannot be empty." );
334 m_errorGrid =
dynamic_cast<wxGrid*
>(
event.GetEventObject() );
344 && !
Pgm().GetCommonSettings()->m_DoNotShowAgain.env_var_overwrite_warning )
346 wxString msg1 =
_(
"This path was defined externally to the running process and\n"
347 "will only be temporarily overwritten." );
348 wxString msg2 =
_(
"The next time KiCad is launched, any paths that have already\n"
349 "been defined are honored and any settings defined in the path\n"
350 "configuration dialog are ignored. If you did not intend for\n"
351 "this behavior, either rename any conflicting entries or remove\n"
352 "the external environment variable(s) from your system." );
354 dlg.ShowDetailedText( msg2 );
366 wxMessageBox( wxString::Format(
_(
"The name %s is reserved, and cannot be used." ),
382 [&]() -> std::pair<int, int>
427 grid->EnableCellEditControl(
true );
428 grid->ShowCellEditControl();
435 wxSizer* sizerMain = GetSizer();
440 wxHW_SCROLLBAR_AUTO );
442 wxString msg =
_(
"Enter the name and value for each environment variable. Grey entries "
443 "are names that have been defined externally at the system or user "
444 "level. Environment variables defined at the system or user level "
445 "take precedence over the ones defined in this table. This means the "
446 "values in this table are ignored." );
447 msg <<
"<br><br><b>";
448 msg <<
_(
"To ensure environment variable names are valid on all platforms, the name field "
449 "will only accept upper case letters, digits, and the underscore characters." );
454 msg <<
"<br><br><b>" << var <<
"</b>";
458 if( desc.size() > 0 )
466 sizerMain->Insert( sizerMain->GetItemCount() - 1,
m_helpBox, 1, wxALL|wxEXPAND, 10 );
479 int minHelpBoxHeight = GetTextExtent( wxT(
"T" ) ).y * 20;
481 if( GetClientSize().y < minHelpBoxHeight * 2 )
482 SetClientSize( wxSize( GetClientSize().x, GetClientSize().y + minHelpBoxHeight ) );
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
DO_NOT_SHOW_AGAIN m_DoNotShowAgain
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
KiCad uses environment variables internally for determining the base paths for libraries,...
Provide a custom wxValidator object for limiting the allowable characters when defining an environmen...
Editor for wxGrid cells that adds a file/folder browser to the grid input field.
This class works around a bug in wxGrid where the first keystroke doesn't get sent through the valida...
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Add dark theme support to wxHtmlWindow.
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
bool DoNotShowAgain() const
Checks the 'do not show again' setting for the dialog.
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
std::vector< LIBRARY_TABLE_ROW * > Rows(LIBRARY_TABLE_TYPE aType, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH, bool aIncludeInvalid=false) const
Returns a flattened list of libraries of the given type.
virtual COMMON_SETTINGS * GetCommonSettings() const
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
virtual void SetLocalEnvVariables()
Update the local environment with the contents of the current ENV_VAR_MAP stored in the COMMON_SETTIN...
virtual LIBRARY_MANAGER & GetLibraryManager() const
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
Functions related to environment variables, including help functions.
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
KICOMMON_API wxString LookUpEnvVarHelp(const wxString &aEnvVar)
Look up long-form help text for a given environment variable.
KICOMMON_API const std::vector< wxString > & GetPredefinedEnvVars()
Get the list of pre-defined environment variables.
KICOMMON_API bool IsEnvVarImmutable(const wxString &aEnvVar)
Determine if an environment variable is "predefined", i.e.
PGM_BASE & Pgm()
The global program "get" accessor.
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
bool env_var_overwrite_warning
Custom text control validator definitions.