2015-03-29 21:22:53 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
2017-12-22 22:34:03 +00:00
|
|
|
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
|
2017-06-13 23:47:05 +00:00
|
|
|
* Copyright (C) 2015-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-03-29 21:22:53 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-06-13 23:47:05 +00:00
|
|
|
* @file dialog_env_var_config.cpp
|
2015-03-29 21:22:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dialog_env_var_config.h>
|
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
#include <confirm.h>
|
|
|
|
|
2015-03-29 21:22:53 +00:00
|
|
|
#include <validators.h>
|
2015-07-24 10:23:34 +00:00
|
|
|
#include <html_messagebox.h>
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2015-08-17 00:30:29 +00:00
|
|
|
#include <wx/regex.h>
|
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
/** A helper dialog to edit a env var name and/or its value (often a path)
|
|
|
|
*/
|
|
|
|
class DIALOG_ENV_VAR_SINGLE : public DIALOG_ENV_VAR_SINGLE_BASE
|
2015-03-29 21:22:53 +00:00
|
|
|
{
|
2017-10-26 09:47:57 +00:00
|
|
|
public:
|
|
|
|
DIALOG_ENV_VAR_SINGLE( wxWindow* parent, const wxString& aEnvVarName,
|
|
|
|
const wxString& aEnvVarPath );
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
/// @return the new environment variable name
|
|
|
|
wxString GetEnvVarName() const
|
|
|
|
{
|
|
|
|
return m_envVarName->GetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @return the new environment variable value
|
|
|
|
wxString GetEnvVarValue() const
|
|
|
|
{
|
|
|
|
return m_envVarPath->GetValue();
|
|
|
|
}
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
/// disable the environment variable name (must be called
|
|
|
|
/// for predefined environment variable names, not editable
|
|
|
|
void SetEnvVarProtected()
|
2015-03-29 21:22:53 +00:00
|
|
|
{
|
2017-10-26 09:47:57 +00:00
|
|
|
m_envVarName->Enable( false );
|
2015-03-29 21:22:53 +00:00
|
|
|
}
|
2017-10-26 09:47:57 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void OnSelectPath( wxCommandEvent& event ) override;
|
|
|
|
void onHelpClick( wxCommandEvent& event ) override;
|
2018-04-10 18:17:21 +00:00
|
|
|
|
|
|
|
// Currently, only upper case variable names are acepted. onVarNameChange
|
|
|
|
// changes on the fly any lower case char by the corresponding upper case
|
|
|
|
void onVarNameChange( wxCommandEvent& event ) override;
|
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
bool TransferDataFromWindow() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_ENV_VAR_CONFIG::DIALOG_ENV_VAR_CONFIG( wxWindow* aParent, const ENV_VAR_MAP& aEnvVarMap ) :
|
|
|
|
DIALOG_ENV_VAR_CONFIG_BASE( aParent )
|
|
|
|
{
|
|
|
|
// Copy environment variables across
|
|
|
|
m_envVarMap = aEnvVarMap;
|
2015-03-29 21:22:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_ENV_VAR_CONFIG::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
wxLogDebug( wxT( "In DIALOG_ENV_VAR_CONFIG::TransferDataToWindow()." ) );
|
|
|
|
|
|
|
|
if( !wxDialog::TransferDataToWindow() )
|
|
|
|
return false;
|
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
//TODO
|
|
|
|
/*
|
|
|
|
// Grab the project path var (not editable)
|
|
|
|
wxString prjPath;
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
wxGetEnv( PROJECT_VAR_NAME, &prjPath );
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
m_kiprjmod->SetLabel( prjPath );
|
|
|
|
*/
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
//TODO - Call SetAlternateRowColour first to prevent assertion error
|
|
|
|
//m_pathList->EnableAlternateRowColours( true );
|
|
|
|
|
|
|
|
PopulatePathList();
|
|
|
|
|
|
|
|
// Select the first item in the list
|
|
|
|
SelectListIndex( 0 );
|
2015-03-29 21:22:53 +00:00
|
|
|
|
|
|
|
GetSizer()->Layout();
|
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_ENV_VAR_CONFIG::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
2017-10-26 09:47:57 +00:00
|
|
|
{
|
2015-03-29 21:22:53 +00:00
|
|
|
return false;
|
2017-10-26 09:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Pgm().SetLocalEnvVariables( m_envVarMap );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_ENV_VAR_CONFIG::PopulatePathList()
|
|
|
|
{
|
|
|
|
m_pathList->Freeze();
|
|
|
|
|
|
|
|
m_pathList->ClearAll();
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-12-22 22:34:03 +00:00
|
|
|
m_pathList->AppendColumn( _( "Name:" ) );
|
|
|
|
m_pathList->AppendColumn( _( "Path:" ) );
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
int row = 0;
|
|
|
|
|
|
|
|
for( auto it = m_envVarMap.begin(); it != m_envVarMap.end(); ++it )
|
2015-03-29 21:22:53 +00:00
|
|
|
{
|
2017-10-26 09:47:57 +00:00
|
|
|
long index = m_pathList->InsertItem( row, it->first );
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
m_pathList->SetItem( index, 1, it->second.GetValue() );
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-12-22 22:34:03 +00:00
|
|
|
if( it->second.GetDefinedExternally() )
|
|
|
|
{
|
|
|
|
wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
|
|
|
|
|
|
|
|
m_pathList->SetItemBackgroundColour( index, color );
|
|
|
|
}
|
2015-08-17 00:30:29 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
row++;
|
|
|
|
}
|
2015-08-17 00:30:29 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
m_pathList->SetColumnWidth( 0, wxLIST_AUTOSIZE );
|
|
|
|
m_pathList->SetColumnWidth( 1, wxLIST_AUTOSIZE );
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
m_pathList->Update();
|
|
|
|
|
|
|
|
m_pathList->Thaw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-22 22:34:03 +00:00
|
|
|
bool DIALOG_ENV_VAR_CONFIG::GetPathAtIndex( unsigned int aIndex, wxString& aEnvVar,
|
|
|
|
wxString& aEnvPath )
|
2017-10-26 09:47:57 +00:00
|
|
|
{
|
2017-10-28 22:54:08 +00:00
|
|
|
if( aIndex > m_envVarMap.size() )
|
2017-10-26 09:47:57 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int idx = 0;
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
for( auto it = m_envVarMap.begin(); it != m_envVarMap.end(); ++it )
|
|
|
|
{
|
|
|
|
if( idx == aIndex )
|
2015-03-29 21:22:53 +00:00
|
|
|
{
|
2017-10-26 09:47:57 +00:00
|
|
|
aEnvVar = it->first;
|
|
|
|
aEnvPath = it->second.GetValue();
|
|
|
|
|
|
|
|
return true;
|
2015-03-29 21:22:53 +00:00
|
|
|
}
|
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
idx++;
|
2015-03-29 21:22:53 +00:00
|
|
|
}
|
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_ENV_VAR_CONFIG::OnAddButton( wxCommandEvent& event )
|
|
|
|
{
|
2018-01-23 19:48:29 +00:00
|
|
|
DIALOG_ENV_VAR_SINGLE dlg( nullptr, wxEmptyString, wxEmptyString );
|
2017-10-26 09:47:57 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
2015-03-29 21:22:53 +00:00
|
|
|
{
|
2017-10-26 09:47:57 +00:00
|
|
|
wxString newName = dlg.GetEnvVarName();
|
|
|
|
wxString newPath = dlg.GetEnvVarValue();
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
// Check that the name does not already exist
|
|
|
|
if( m_envVarMap.count( newName ) > 0 )
|
2015-03-29 21:22:53 +00:00
|
|
|
{
|
2017-10-26 09:47:57 +00:00
|
|
|
//TODO - Improve this message, use DisplayErrorMessage instead
|
2017-12-22 22:34:03 +00:00
|
|
|
DisplayError( this, _( "Path already exists." ) );
|
2015-03-29 21:22:53 +00:00
|
|
|
}
|
2017-10-26 09:47:57 +00:00
|
|
|
else
|
2015-03-29 21:22:53 +00:00
|
|
|
{
|
2017-10-26 09:47:57 +00:00
|
|
|
m_envVarMap[newName] = ENV_VAR_ITEM( newPath );
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
// Update path list
|
|
|
|
PopulatePathList();
|
2015-03-29 21:22:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-26 09:47:57 +00:00
|
|
|
}
|
|
|
|
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
void DIALOG_ENV_VAR_CONFIG::OnEditButton( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
EditSelectedEntry();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_ENV_VAR_CONFIG::EditSelectedEntry()
|
|
|
|
{
|
|
|
|
wxString envName;
|
|
|
|
wxString envPath;
|
2015-03-31 15:46:31 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
if( GetPathAtIndex( m_pathIndex, envName, envPath ) )
|
2015-03-29 21:22:53 +00:00
|
|
|
{
|
2017-10-26 09:47:57 +00:00
|
|
|
auto dlg = new DIALOG_ENV_VAR_SINGLE( nullptr, envName, envPath );
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
if( IsEnvVarImmutable( envName ) )
|
2015-03-29 21:22:53 +00:00
|
|
|
{
|
2017-10-26 09:47:57 +00:00
|
|
|
dlg->SetEnvVarProtected();
|
2015-03-29 21:22:53 +00:00
|
|
|
}
|
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
if( dlg->ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
wxString newName = dlg->GetEnvVarName();
|
|
|
|
wxString newPath = dlg->GetEnvVarValue();
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
// If the path name has not been changed
|
|
|
|
if( envName.Cmp( newName ) == 0 )
|
|
|
|
{
|
|
|
|
m_envVarMap[envName].SetValue( newPath );
|
2015-03-31 15:46:31 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
if( m_envVarMap[envName].GetDefinedExternally() )
|
|
|
|
{
|
|
|
|
m_extDefsChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Path-name needs to be updated
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( IsEnvVarImmutable( envName ) )
|
|
|
|
{
|
|
|
|
DisplayErrorMessage( this,
|
2017-12-22 22:34:03 +00:00
|
|
|
wxString::Format( _( "Environment variable \"%s\" cannot "
|
|
|
|
"be renamed." ),
|
|
|
|
envName.ToStdString() ),
|
2017-10-26 09:47:57 +00:00
|
|
|
_( "The selected environment variable name "
|
|
|
|
"is required for KiCad functionality and "
|
|
|
|
"can not be renamed." ) );
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
auto envVar = m_envVarMap[envName];
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
m_envVarMap.erase( envName );
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
envVar.SetValue( newPath );
|
|
|
|
envVar.SetDefinedExternally( false );
|
|
|
|
m_envVarMap[newName] = envVar;
|
|
|
|
}
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
// Update the path list
|
|
|
|
PopulatePathList();
|
|
|
|
}
|
2015-03-29 21:22:53 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
dlg->Destroy();
|
2015-03-29 21:22:53 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-24 10:23:34 +00:00
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
void DIALOG_ENV_VAR_CONFIG::OnHelpButton( wxCommandEvent& event )
|
2015-07-24 10:23:34 +00:00
|
|
|
{
|
2017-12-22 22:34:03 +00:00
|
|
|
wxString msg = _( "Enter the name and value for each environment variable. Grey entries "
|
2015-08-17 00:30:29 +00:00
|
|
|
"are names that have been defined externally at the system or user "
|
|
|
|
"level. Environment variables defined at the system or user level "
|
|
|
|
"take precedence over the ones defined in this table. This means the "
|
|
|
|
"values in this table are ignored." );
|
2015-07-24 10:23:34 +00:00
|
|
|
msg << wxT( "<br><br><b>" );
|
2015-08-17 00:30:29 +00:00
|
|
|
msg << _( "To ensure environment variable names are valid on all platforms, the name field "
|
|
|
|
"will only accept upper case letters, digits, and the underscore characters." );
|
2015-07-24 10:23:34 +00:00
|
|
|
msg << wxT( "</b><br><br>" );
|
2017-10-26 09:47:57 +00:00
|
|
|
msg << _( "<b>KICAD_SYMBOL_DIR</b> is the base path of the locally installed symbol libraries." );
|
|
|
|
msg << wxT( "<br><br>" );
|
2015-08-17 00:30:29 +00:00
|
|
|
msg << _( "<b>KIGITHUB</b> is used by KiCad to define the URL of the repository "
|
2017-12-22 22:34:03 +00:00
|
|
|
"of the official KiCad footprint libraries." );
|
2015-08-17 00:30:29 +00:00
|
|
|
msg << wxT( "<br><br>" );
|
|
|
|
msg << _( "<b>KISYS3DMOD</b> is the base path of system footprint 3D "
|
|
|
|
"shapes (.3Dshapes folders)." );
|
2015-07-24 10:23:34 +00:00
|
|
|
msg << wxT( "<br><br>" );
|
2015-08-17 00:30:29 +00:00
|
|
|
msg << _( "<b>KISYSMOD</b> is the base path of locally installed system "
|
|
|
|
"footprint libraries (.pretty folders)." );
|
2015-07-24 10:23:34 +00:00
|
|
|
msg << wxT( "<br><br>" );
|
2015-08-17 00:30:29 +00:00
|
|
|
msg << _( "<b>KIPRJMOD</b> is internally defined by KiCad (cannot be edited) and is set "
|
|
|
|
"to the absolute path of the currently loaded project file. This environment "
|
|
|
|
"variable can be used to define files and paths relative to the currently loaded "
|
|
|
|
"project. For instance, ${KIPRJMOD}/libs/footprints.pretty can be defined as a "
|
|
|
|
"folder containing a project specific footprint library named footprints.pretty." );
|
|
|
|
msg << wxT( "<br><br>" );
|
|
|
|
msg << _( "<b>KICAD_PTEMPLATES</b> is optional and can be defined if you want to "
|
|
|
|
"create your own project templates folder." );
|
|
|
|
|
2018-01-11 08:08:55 +00:00
|
|
|
HTML_MESSAGE_BOX dlg( GetParent(), _( "Environment Variable Help" ) );
|
|
|
|
dlg.SetDialogSizeInDU( 400, 350 );
|
|
|
|
|
|
|
|
dlg.AddHTML_Text( msg );
|
|
|
|
dlg.ShowModal();
|
2017-10-26 09:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_ENV_VAR_CONFIG::IsEnvVarImmutable( const wxString aEnvVar )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* TODO - Instead of defining these values here,
|
|
|
|
* extract them from elsewhere in the program
|
|
|
|
* (where they are originally defined)
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const wxString immutable[] = {
|
|
|
|
"KIGITHUB",
|
|
|
|
"KISYS3DMOD",
|
|
|
|
"KISYSMOD",
|
|
|
|
"KIPRJMOD",
|
|
|
|
"KICAD_PTEMPLATES",
|
|
|
|
"KICAD_SYMBOL_DIR"
|
|
|
|
};
|
|
|
|
|
|
|
|
for( unsigned int ii=0; ii<6; ii++ )
|
|
|
|
{
|
|
|
|
if( aEnvVar.Cmp( immutable[ii] ) == 0 )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_ENV_VAR_CONFIG::OnRemoveButton( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxString envName;
|
|
|
|
wxString envPath;
|
|
|
|
|
|
|
|
if( GetPathAtIndex( m_pathIndex, envName, envPath ) )
|
|
|
|
{
|
|
|
|
if( IsEnvVarImmutable( envName ) )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_envVarMap.erase( envName );
|
|
|
|
|
|
|
|
PopulatePathList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_ENV_VAR_CONFIG::SelectListIndex( unsigned int aIndex )
|
|
|
|
{
|
|
|
|
if( aIndex >= m_envVarMap.size() )
|
|
|
|
{
|
|
|
|
aIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pathIndex = aIndex;
|
|
|
|
|
|
|
|
wxString envName;
|
|
|
|
wxString envPath;
|
|
|
|
|
|
|
|
if( GetPathAtIndex( m_pathIndex, envName, envPath ) )
|
|
|
|
{
|
|
|
|
// Disable the 'delete' button if the path cannot be deleted
|
|
|
|
m_deletePathButton->Enable( !IsEnvVarImmutable( envName ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DIALOG_ENV_VAR_CONFIG::OnPathSelected( wxListEvent& event )
|
|
|
|
{
|
|
|
|
SelectListIndex( event.GetIndex() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_ENV_VAR_CONFIG::OnPathActivated( wxListEvent& event )
|
|
|
|
{
|
|
|
|
SelectListIndex( event.GetIndex() );
|
|
|
|
|
|
|
|
EditSelectedEntry();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////
|
|
|
|
// DIALOG_ENV_VAR_SINGLE //
|
|
|
|
///////////////////////////
|
|
|
|
|
|
|
|
DIALOG_ENV_VAR_SINGLE::DIALOG_ENV_VAR_SINGLE( wxWindow* parent,
|
|
|
|
const wxString& aEnvVarName,
|
|
|
|
const wxString& aEnvVarPath ) :
|
|
|
|
DIALOG_ENV_VAR_SINGLE_BASE( parent )
|
|
|
|
{
|
|
|
|
m_envVarName->SetValue( aEnvVarName );
|
|
|
|
m_envVarPath->SetValue( aEnvVarPath );
|
|
|
|
m_envVarName->SetValidator( ENVIRONMENT_VARIABLE_CHAR_VALIDATOR() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_ENV_VAR_SINGLE::OnSelectPath( wxCommandEvent& event )
|
|
|
|
{
|
2017-12-22 22:34:03 +00:00
|
|
|
wxString title = _( "Select Path for Environment Variable" );
|
2017-10-26 09:47:57 +00:00
|
|
|
wxString path; // Currently the first opened path is not initialized
|
|
|
|
|
|
|
|
wxDirDialog dlg( nullptr, title, path, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
m_envVarPath->SetValue( dlg.GetPath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-10 18:17:21 +00:00
|
|
|
void DIALOG_ENV_VAR_SINGLE::onVarNameChange( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxString upper_var = m_envVarName->GetValue().Upper();
|
|
|
|
|
|
|
|
if( upper_var != m_envVarName->GetValue() )
|
|
|
|
{
|
|
|
|
int pos = m_envVarName->GetInsertionPoint();
|
|
|
|
m_envVarName->ChangeValue( upper_var );
|
|
|
|
m_envVarName->SetInsertionPoint( pos );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-26 09:47:57 +00:00
|
|
|
bool DIALOG_ENV_VAR_SINGLE::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
// The user pressed the OK button, test data validity
|
|
|
|
wxString name = m_envVarName->GetValue();
|
|
|
|
wxString path = m_envVarPath->GetValue();
|
|
|
|
|
|
|
|
// Neither name nor path can be empty
|
|
|
|
if( name.IsEmpty() )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "Environment variable name cannot be empty." ) );
|
|
|
|
// Veto:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( path.IsEmpty() )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "Environment variable value cannot be empty." ) );
|
|
|
|
// Veto:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name cannot start with a number
|
|
|
|
if( name.Left( 1 ).IsNumber() )
|
|
|
|
{
|
2017-12-22 22:34:03 +00:00
|
|
|
DisplayError( this, _( "Environment variable names cannot start with a digit (0-9)." ) );
|
2017-10-26 09:47:57 +00:00
|
|
|
// Veto:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No errors detected
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_ENV_VAR_SINGLE::onHelpClick( wxCommandEvent& event )
|
|
|
|
{
|
2017-12-22 22:34:03 +00:00
|
|
|
wxString msg = _( "An environment variable is used for string substitutions.<br>"
|
|
|
|
"Environment variables are primarily used for paths to make KiCad portable "
|
|
|
|
"between platforms.<br><br>"
|
|
|
|
"If an environment variable is defined as <b>MYLIBPATH</b> with a "
|
|
|
|
"value <b>e:/kicad_libs</b>, then a library name "
|
|
|
|
"<b>${MYLIBPATH}/mylib.lib</b> gets expanded to "
|
|
|
|
"<b>e:/kicad_libs/mylib.lib</b>"
|
2017-10-26 09:47:57 +00:00
|
|
|
"<br><br>"
|
|
|
|
"<b>Note:</b><br>"
|
2017-12-22 22:34:03 +00:00
|
|
|
"Only characters <b>ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_</b> are "
|
|
|
|
"allowed in environment variable names and the environment variable name "
|
|
|
|
"cannot start with a digit (0-9)."
|
2017-10-26 09:47:57 +00:00
|
|
|
);
|
|
|
|
|
2018-01-11 08:08:55 +00:00
|
|
|
HTML_MESSAGE_BOX dlg( GetParent(), _( "Environment Variable Help" ) );
|
|
|
|
dlg.SetDialogSizeInDU( 400, 350 );
|
|
|
|
|
|
|
|
dlg.AddHTML_Text( msg );
|
|
|
|
dlg.ShowModal();
|
2015-07-24 10:23:34 +00:00
|
|
|
}
|