2018-03-07 13:05:12 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
|
2021-07-15 19:26:35 +00:00
|
|
|
* Copyright (C) 2015-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-03-07 13:05:12 +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
|
|
|
|
*/
|
|
|
|
|
2020-10-25 13:36:19 +00:00
|
|
|
#include <dialogs/dialog_configure_paths.h>
|
2018-03-07 13:05:12 +00:00
|
|
|
|
2021-03-07 20:31:19 +00:00
|
|
|
#include <bitmaps.h>
|
2018-03-07 13:05:12 +00:00
|
|
|
#include <confirm.h>
|
|
|
|
#include <menus_helpers.h>
|
|
|
|
#include <validators.h>
|
2021-09-14 18:26:03 +00:00
|
|
|
#include <dialogs/html_message_box.h>
|
2018-03-07 13:05:12 +00:00
|
|
|
#include <filename_resolver.h>
|
2018-09-28 21:08:31 +00:00
|
|
|
#include <env_vars.h>
|
2019-03-04 11:02:12 +00:00
|
|
|
#include <grid_tricks.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <pgm_base.h>
|
2018-08-19 16:10:14 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
2018-08-24 18:28:11 +00:00
|
|
|
#include <widgets/grid_text_button_helpers.h>
|
2018-03-07 13:05:12 +00:00
|
|
|
|
2020-07-11 09:37:22 +00:00
|
|
|
#include <algorithm>
|
2020-10-18 11:31:07 +00:00
|
|
|
#include <wx/dirdlg.h>
|
2020-07-11 09:37:22 +00:00
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
enum TEXT_VAR_GRID_COLUMNS
|
2018-03-07 13:05:12 +00:00
|
|
|
{
|
2020-03-26 11:02:59 +00:00
|
|
|
TV_NAME_COL = 0,
|
|
|
|
TV_VALUE_COL,
|
|
|
|
TV_FLAG_COL
|
2018-03-07 13:05:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum SEARCH_PATH_GRID_COLUMNS
|
|
|
|
{
|
|
|
|
SP_ALIAS_COL = 0,
|
|
|
|
SP_PATH_COL,
|
|
|
|
SP_DESC_COL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS( wxWindow* aParent, FILENAME_RESOLVER* aResolver ) :
|
|
|
|
DIALOG_CONFIGURE_PATHS_BASE( aParent ),
|
2020-09-05 16:00:29 +00:00
|
|
|
m_errorGrid( nullptr ),
|
|
|
|
m_errorRow( -1 ),
|
|
|
|
m_errorCol( -1 ),
|
2018-07-20 17:46:56 +00:00
|
|
|
m_resolver( aResolver ),
|
2020-10-30 17:40:13 +00:00
|
|
|
m_gridWidth( 0 ),
|
2020-09-05 16:00:29 +00:00
|
|
|
m_gridWidthsDirty( true ),
|
2022-08-07 10:26:42 +00:00
|
|
|
m_helpBox( nullptr ),
|
|
|
|
m_heightBeforeHelp( 400 )
|
2018-03-07 13:05:12 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
m_btnAddEnvVar->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
|
|
|
|
m_btnDeleteEnvVar->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
|
|
|
|
m_btnAddSearchPath->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
|
|
|
|
m_btnDeleteSearchPath->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
|
|
|
|
m_btnMoveUp->SetBitmap( KiBitmap( BITMAPS::small_up ) );
|
|
|
|
m_btnMoveDown->SetBitmap( KiBitmap( BITMAPS::small_down ) );
|
2018-03-07 13:05:12 +00:00
|
|
|
|
2021-08-10 11:59:53 +00:00
|
|
|
m_EnvVars->ClearRows();
|
2018-03-07 13:05:12 +00:00
|
|
|
m_EnvVars->AppendCols( 1 ); // for the isExternal flags
|
2020-03-26 11:02:59 +00:00
|
|
|
m_EnvVars->HideCol( TV_FLAG_COL );
|
2018-03-07 13:05:12 +00:00
|
|
|
m_EnvVars->UseNativeColHeader( true );
|
|
|
|
|
2018-08-24 18:28:11 +00:00
|
|
|
wxGridCellAttr* attr = new wxGridCellAttr;
|
2021-02-17 14:06:19 +00:00
|
|
|
attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, m_EnvVars, &m_curdir, wxEmptyString ) );
|
2020-03-26 11:02:59 +00:00
|
|
|
m_EnvVars->SetColAttr( TV_VALUE_COL, attr );
|
2018-08-24 18:28:11 +00:00
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
2021-02-17 14:06:19 +00:00
|
|
|
attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, m_SearchPaths, &m_curdir, wxEmptyString ) );
|
2020-03-26 11:02:59 +00:00
|
|
|
m_SearchPaths->SetColAttr( TV_VALUE_COL, attr );
|
2018-08-24 18:28:11 +00:00
|
|
|
|
|
|
|
// Give a bit more room for combobox editors
|
|
|
|
m_EnvVars->SetDefaultRowSize( m_EnvVars->GetDefaultRowSize() + 4 );
|
|
|
|
m_SearchPaths->SetDefaultRowSize( m_SearchPaths->GetDefaultRowSize() + 4 );
|
|
|
|
|
|
|
|
m_EnvVars->PushEventHandler( new GRID_TRICKS( m_EnvVars ) );
|
|
|
|
m_SearchPaths->PushEventHandler( new GRID_TRICKS( m_SearchPaths ) );
|
|
|
|
|
|
|
|
m_EnvVars->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
|
|
|
|
m_SearchPaths->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
|
|
|
|
|
2018-03-07 13:05:12 +00:00
|
|
|
if( m_resolver )
|
|
|
|
{
|
2021-08-10 11:59:53 +00:00
|
|
|
m_SearchPaths->ClearRows();
|
2018-03-07 13:05:12 +00:00
|
|
|
m_SearchPaths->UseNativeColHeader( true );
|
|
|
|
|
|
|
|
// prohibit these characters in the alias names: []{}()%~<>"='`;:.,&?/\|$
|
|
|
|
m_aliasValidator.SetStyle( wxFILTER_EXCLUDE_CHAR_LIST );
|
|
|
|
m_aliasValidator.SetCharExcludes( wxT( "{}[]()%~<>\"='`;:.,&?/\\|$" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_sb3DSearchPaths->Show( false );
|
|
|
|
|
|
|
|
SetInitialFocus( m_EnvVars );
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
2018-03-07 13:05:12 +00:00
|
|
|
|
|
|
|
// wxFormBuilder doesn't include this event...
|
2021-07-15 19:26:35 +00:00
|
|
|
m_EnvVars->Connect( wxEVT_GRID_CELL_CHANGING,
|
|
|
|
wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ),
|
|
|
|
nullptr, this );
|
|
|
|
m_SearchPaths->Connect( wxEVT_GRID_CELL_CHANGING,
|
|
|
|
wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ),
|
|
|
|
nullptr, this );
|
2018-03-07 13:05:12 +00:00
|
|
|
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
Centre();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_CONFIGURE_PATHS::~DIALOG_CONFIGURE_PATHS()
|
|
|
|
{
|
2018-08-24 18:28:11 +00:00
|
|
|
// Delete the GRID_TRICKS.
|
|
|
|
m_SearchPaths->PopEventHandler( true );
|
|
|
|
m_EnvVars->PopEventHandler( true );
|
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
m_EnvVars->Disconnect( wxEVT_GRID_CELL_CHANGING,
|
|
|
|
wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ),
|
|
|
|
nullptr, this );
|
|
|
|
m_SearchPaths->Disconnect( wxEVT_GRID_CELL_CHANGING,
|
|
|
|
wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ),
|
|
|
|
nullptr, this );
|
2018-03-07 13:05:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_CONFIGURE_PATHS::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataToWindow() )
|
|
|
|
return false;
|
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
// Do 3D search paths first so they get first crack at setting m_curdir
|
2018-03-07 13:05:12 +00:00
|
|
|
|
|
|
|
if( m_resolver )
|
|
|
|
{
|
|
|
|
const std::list<SEARCH_PATH>* paths = m_resolver->GetPaths();
|
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
for( auto it = paths->begin(); it != paths->end(); ++it )
|
|
|
|
{
|
2020-11-16 11:16:44 +00:00
|
|
|
if ( !( *it ).m_Alias.StartsWith( "${" ) && !( *it ).m_Alias.StartsWith( "$(" ) )
|
2018-03-28 17:14:04 +00:00
|
|
|
{
|
2020-11-16 11:16:44 +00:00
|
|
|
AppendSearchPath( it->m_Alias, it->m_Pathvar, it->m_Description );
|
2018-03-07 13:05:12 +00:00
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
if( m_curdir.IsEmpty() )
|
2020-11-16 11:16:44 +00:00
|
|
|
m_curdir = it->m_Pathexp;
|
2018-03-28 17:14:04 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-07 13:05:12 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:14:04 +00:00
|
|
|
// Environment variables
|
|
|
|
|
|
|
|
const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
|
|
|
|
|
|
|
|
for( auto it = envVars.begin(); it != envVars.end(); ++it )
|
|
|
|
{
|
|
|
|
const wxString& path = it->second.GetValue();
|
|
|
|
AppendEnvVar( it->first, path, it->second.GetDefinedExternally() );
|
|
|
|
|
|
|
|
if( m_curdir.IsEmpty() && !path.StartsWith( "${" ) && !path.StartsWith( "$(" ) )
|
|
|
|
m_curdir = path;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-03-07 13:05:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIGURE_PATHS::AppendEnvVar( const wxString& aName, const wxString& aPath,
|
|
|
|
bool isExternal )
|
|
|
|
{
|
|
|
|
int i = m_EnvVars->GetNumberRows();
|
|
|
|
|
|
|
|
m_EnvVars->AppendRows( 1 );
|
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
m_EnvVars->SetCellValue( i, TV_NAME_COL, aName );
|
2018-03-07 13:05:12 +00:00
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
wxGridCellAttr* nameCellAttr = m_EnvVars->GetOrCreateCellAttr( i, TV_NAME_COL );
|
2018-03-07 13:05:12 +00:00
|
|
|
wxGridCellTextEditor* nameTextEditor = new GRID_CELL_TEXT_EDITOR();
|
|
|
|
nameTextEditor->SetValidator( ENV_VAR_NAME_VALIDATOR() );
|
|
|
|
nameCellAttr->SetEditor( nameTextEditor );
|
2021-06-22 00:35:11 +00:00
|
|
|
nameCellAttr->SetReadOnly( ENV_VAR::IsEnvVarImmutable( aName ) );
|
2018-03-07 13:05:12 +00:00
|
|
|
nameCellAttr->DecRef();
|
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
m_EnvVars->SetCellValue( i, TV_VALUE_COL, aPath );
|
2018-03-07 13:05:12 +00:00
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
wxGridCellAttr* pathCellAttr = m_EnvVars->GetOrCreateCellAttr( i, TV_VALUE_COL );
|
2018-03-07 13:05:12 +00:00
|
|
|
wxSystemColour c = isExternal ? wxSYS_COLOUR_MENU : wxSYS_COLOUR_LISTBOX;
|
|
|
|
pathCellAttr->SetBackgroundColour( wxSystemSettings::GetColour( c ) );
|
|
|
|
pathCellAttr->DecRef();
|
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
m_EnvVars->SetCellValue( i, TV_FLAG_COL, isExternal ? wxT( "external" ) : wxEmptyString );
|
2018-03-07 13:05:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIGURE_PATHS::AppendSearchPath( const wxString& aName, const wxString& aPath,
|
2021-07-15 19:26:35 +00:00
|
|
|
const wxString& aDescription )
|
2018-03-07 13:05:12 +00:00
|
|
|
{
|
|
|
|
int i = m_SearchPaths->GetNumberRows();
|
|
|
|
|
|
|
|
m_SearchPaths->AppendRows( 1 );
|
|
|
|
|
|
|
|
m_SearchPaths->SetCellValue( i, SP_ALIAS_COL, aName );
|
|
|
|
|
|
|
|
wxGridCellAttr* nameCellAttr = m_SearchPaths->GetOrCreateCellAttr( i, SP_ALIAS_COL );
|
|
|
|
wxGridCellTextEditor* nameTextEditor = new GRID_CELL_TEXT_EDITOR();
|
|
|
|
nameTextEditor->SetValidator( m_aliasValidator );
|
|
|
|
nameCellAttr->SetEditor( nameTextEditor );
|
|
|
|
nameCellAttr->DecRef();
|
|
|
|
|
|
|
|
m_SearchPaths->SetCellValue( i, SP_PATH_COL, aPath );
|
|
|
|
m_SearchPaths->SetCellValue( i, SP_DESC_COL, aDescription );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_CONFIGURE_PATHS::TransferDataFromWindow()
|
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_EnvVars->CommitPendingChanges() || !m_SearchPaths->CommitPendingChanges() )
|
2018-03-07 13:05:12 +00:00
|
|
|
return false;
|
|
|
|
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
2018-03-07 13:05:12 +00:00
|
|
|
|
2021-11-09 09:35:49 +00:00
|
|
|
// Update environment variables
|
2021-05-01 17:39:35 +00:00
|
|
|
ENV_VAR_MAP& envVarMap = Pgm().GetLocalEnvVariables();
|
2018-03-07 13:05:12 +00:00
|
|
|
|
|
|
|
for( int row = 0; row < m_EnvVars->GetNumberRows(); ++row )
|
|
|
|
{
|
2021-05-01 17:39:35 +00:00
|
|
|
wxString name = m_EnvVars->GetCellValue( row, TV_NAME_COL );
|
|
|
|
wxString path = m_EnvVars->GetCellValue( row, TV_VALUE_COL );
|
|
|
|
bool external = !m_EnvVars->GetCellValue( row, TV_FLAG_COL ).IsEmpty();
|
2018-12-26 21:19:47 +00:00
|
|
|
|
2021-05-01 17:39:35 +00:00
|
|
|
if( external )
|
2020-08-11 23:25:58 +00:00
|
|
|
{
|
|
|
|
// Don't check for consistency on external variables, just use them as-is
|
|
|
|
}
|
|
|
|
else if( name.IsEmpty() )
|
2018-03-07 13:05:12 +00:00
|
|
|
{
|
|
|
|
m_errorGrid = m_EnvVars;
|
|
|
|
m_errorRow = row;
|
2020-03-26 11:02:59 +00:00
|
|
|
m_errorCol = TV_NAME_COL;
|
2018-03-07 13:05:12 +00:00
|
|
|
m_errorMsg = _( "Environment variable name cannot be empty." );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if( path.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_errorGrid = m_EnvVars;
|
|
|
|
m_errorRow = row;
|
2020-03-26 11:02:59 +00:00
|
|
|
m_errorCol = TV_VALUE_COL;
|
2018-03-07 13:05:12 +00:00
|
|
|
m_errorMsg = _( "Environment variable path cannot be empty." );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-01 17:39:35 +00:00
|
|
|
if( envVarMap.count( name ) )
|
|
|
|
envVarMap.at( name ).SetValue( path );
|
|
|
|
else
|
|
|
|
envVarMap[ name ] = ENV_VAR_ITEM( name, path );
|
2018-03-07 13:05:12 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 09:35:49 +00:00
|
|
|
// Remove deleted env vars
|
|
|
|
for( auto it = envVarMap.begin(); it != envVarMap.end(); )
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for( int row = 0; row < m_EnvVars->GetNumberRows(); ++row )
|
|
|
|
{
|
|
|
|
wxString name = m_EnvVars->GetCellValue( row, TV_NAME_COL );
|
|
|
|
|
|
|
|
if( it->first == name )
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( found )
|
|
|
|
++it;
|
|
|
|
else
|
|
|
|
it = envVarMap.erase( it );
|
|
|
|
}
|
|
|
|
|
2021-05-01 17:39:35 +00:00
|
|
|
Pgm().SetLocalEnvVariables();
|
2018-03-07 13:05:12 +00:00
|
|
|
|
|
|
|
// 3D search paths
|
|
|
|
|
|
|
|
if( m_resolver )
|
|
|
|
{
|
|
|
|
std::vector<SEARCH_PATH> alist;
|
|
|
|
SEARCH_PATH alias;
|
|
|
|
|
|
|
|
for( int row = 0; row < m_SearchPaths->GetNumberRows(); ++row )
|
|
|
|
{
|
2020-11-16 11:16:44 +00:00
|
|
|
alias.m_Alias = m_SearchPaths->GetCellValue( row, SP_ALIAS_COL );
|
|
|
|
alias.m_Pathvar = m_SearchPaths->GetCellValue( row, SP_PATH_COL );
|
|
|
|
alias.m_Description = m_SearchPaths->GetCellValue( row, SP_DESC_COL );
|
2018-03-07 13:05:12 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
if( alias.m_Alias.IsEmpty() )
|
2018-03-07 13:05:12 +00:00
|
|
|
{
|
|
|
|
m_errorGrid = m_SearchPaths;
|
|
|
|
m_errorRow = row;
|
|
|
|
m_errorCol = SP_ALIAS_COL;
|
|
|
|
m_errorMsg = _( "3D search path alias cannot be empty." );
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-16 11:16:44 +00:00
|
|
|
else if( alias.m_Pathvar.IsEmpty() )
|
2018-03-07 13:05:12 +00:00
|
|
|
{
|
|
|
|
m_errorGrid = m_SearchPaths;
|
|
|
|
m_errorRow = row;
|
|
|
|
m_errorCol = SP_PATH_COL;
|
|
|
|
m_errorMsg = _( "3D search path cannot be empty." );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
alist.push_back( alias );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_resolver->UpdatePathList( alist ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIGURE_PATHS::OnGridCellChanging( wxGridEvent& event )
|
|
|
|
{
|
|
|
|
wxGrid* grid = dynamic_cast<wxGrid*>( event.GetEventObject() );
|
|
|
|
int row = event.GetRow();
|
|
|
|
int col = event.GetCol();
|
|
|
|
wxString text = event.GetString();
|
|
|
|
|
|
|
|
if( text.IsEmpty() )
|
|
|
|
{
|
|
|
|
if( grid == m_EnvVars )
|
|
|
|
{
|
2020-03-26 11:02:59 +00:00
|
|
|
if( col == TV_NAME_COL )
|
2018-03-07 13:05:12 +00:00
|
|
|
m_errorMsg = _( "Environment variable name cannot be empty." );
|
|
|
|
else
|
|
|
|
m_errorMsg = _( "Environment variable path cannot be empty." );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( col == SP_ALIAS_COL )
|
|
|
|
m_errorMsg = _( "3D search path alias cannot be empty." );
|
|
|
|
else
|
|
|
|
m_errorMsg = _( "3D search path cannot be empty." );
|
|
|
|
}
|
2021-07-15 19:26:35 +00:00
|
|
|
|
2018-03-07 13:05:12 +00:00
|
|
|
m_errorGrid = dynamic_cast<wxGrid*>( event.GetEventObject() );
|
|
|
|
m_errorRow = row;
|
|
|
|
m_errorCol = col;
|
|
|
|
|
|
|
|
event.Veto();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( grid == m_EnvVars )
|
|
|
|
{
|
2021-07-27 14:13:26 +00:00
|
|
|
if( col == TV_VALUE_COL && m_EnvVars->GetCellValue( row, TV_FLAG_COL ).Length()
|
|
|
|
&& !Pgm().GetCommonSettings()->m_DoNotShowAgain.env_var_overwrite_warning )
|
2018-03-07 13:05:12 +00:00
|
|
|
{
|
|
|
|
wxString msg1 = _( "This path was defined externally to the running process and\n"
|
|
|
|
"will only be temporarily overwritten." );
|
|
|
|
wxString msg2 = _( "The next time KiCad is launched, any paths that have already\n"
|
|
|
|
"been defined are honored and any settings defined in the path\n"
|
|
|
|
"configuration dialog are ignored. If you did not intend for\n"
|
|
|
|
"this behavior, either rename any conflicting entries or remove\n"
|
|
|
|
"the external environment variable(s) from your system." );
|
|
|
|
KIDIALOG dlg( this, msg1, KIDIALOG::KD_WARNING );
|
|
|
|
dlg.ShowDetailedText( msg2 );
|
2018-08-29 22:37:20 +00:00
|
|
|
dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
2018-03-07 13:05:12 +00:00
|
|
|
dlg.ShowModal();
|
2021-07-27 14:13:26 +00:00
|
|
|
|
|
|
|
if( dlg.DoNotShowAgain() )
|
|
|
|
Pgm().GetCommonSettings()->m_DoNotShowAgain.env_var_overwrite_warning = true;
|
2018-03-07 13:05:12 +00:00
|
|
|
}
|
2020-03-26 11:02:59 +00:00
|
|
|
else if( col == TV_NAME_COL && m_EnvVars->GetCellValue( row, TV_NAME_COL ) != text )
|
2018-03-07 13:05:12 +00:00
|
|
|
{
|
2021-07-15 19:26:35 +00:00
|
|
|
// This env var name is reserved and cannot be added here.
|
|
|
|
if( text == PROJECT_VAR_NAME )
|
2019-04-16 09:41:30 +00:00
|
|
|
{
|
2021-07-27 14:13:26 +00:00
|
|
|
wxMessageBox( wxString::Format( _( "The name %s is reserved, and cannot be used." ),
|
2019-04-16 09:41:30 +00:00
|
|
|
PROJECT_VAR_NAME ) );
|
|
|
|
event.Veto();
|
|
|
|
}
|
|
|
|
else // Changing name; clear external flag
|
2021-07-15 19:26:35 +00:00
|
|
|
{
|
2020-03-26 11:02:59 +00:00
|
|
|
m_EnvVars->SetCellValue( row, TV_FLAG_COL, wxEmptyString );
|
2021-07-15 19:26:35 +00:00
|
|
|
}
|
2018-03-07 13:05:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIGURE_PATHS::OnAddEnvVar( wxCommandEvent& event )
|
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_EnvVars->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2018-03-07 13:05:12 +00:00
|
|
|
AppendEnvVar( wxEmptyString, wxEmptyString, false );
|
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
m_EnvVars->MakeCellVisible( m_EnvVars->GetNumberRows() - 1, TV_NAME_COL );
|
|
|
|
m_EnvVars->SetGridCursor( m_EnvVars->GetNumberRows() - 1, TV_NAME_COL );
|
2018-03-07 13:05:12 +00:00
|
|
|
|
|
|
|
m_EnvVars->EnableCellEditControl( true );
|
|
|
|
m_EnvVars->ShowCellEditControl();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIGURE_PATHS::OnAddSearchPath( wxCommandEvent& event )
|
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_SearchPaths->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2018-03-07 13:05:12 +00:00
|
|
|
AppendSearchPath( wxEmptyString, wxEmptyString, wxEmptyString);
|
|
|
|
|
|
|
|
m_SearchPaths->MakeCellVisible( m_SearchPaths->GetNumberRows() - 1, SP_ALIAS_COL );
|
|
|
|
m_SearchPaths->SetGridCursor( m_SearchPaths->GetNumberRows() - 1, SP_ALIAS_COL );
|
|
|
|
|
|
|
|
m_SearchPaths->EnableCellEditControl( true );
|
|
|
|
m_SearchPaths->ShowCellEditControl();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIGURE_PATHS::OnRemoveEnvVar( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
int curRow = m_EnvVars->GetGridCursorRow();
|
|
|
|
|
2018-08-30 12:21:01 +00:00
|
|
|
if( curRow < 0 || m_EnvVars->GetNumberRows() <= curRow )
|
2021-12-12 17:27:40 +00:00
|
|
|
{
|
2018-03-07 13:05:12 +00:00
|
|
|
return;
|
2021-12-12 17:27:40 +00:00
|
|
|
}
|
2021-06-22 00:35:11 +00:00
|
|
|
else if( ENV_VAR::IsEnvVarImmutable( m_EnvVars->GetCellValue( curRow, TV_NAME_COL ) ) )
|
2018-03-07 13:05:12 +00:00
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-24 18:28:11 +00:00
|
|
|
m_EnvVars->CommitPendingChanges( true /* silent mode; we don't care if it's valid */ );
|
2018-03-07 13:05:12 +00:00
|
|
|
m_EnvVars->DeleteRows( curRow, 1 );
|
|
|
|
|
2018-08-19 16:10:14 +00:00
|
|
|
m_EnvVars->MakeCellVisible( std::max( 0, curRow-1 ), m_EnvVars->GetGridCursorCol() );
|
|
|
|
m_EnvVars->SetGridCursor( std::max( 0, curRow-1 ), m_EnvVars->GetGridCursorCol() );
|
2018-03-07 13:05:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIGURE_PATHS::OnDeleteSearchPath( wxCommandEvent& event )
|
|
|
|
{
|
2021-12-12 17:27:40 +00:00
|
|
|
wxArrayInt selectedRows = m_SearchPaths->GetSelectedRows();
|
2018-03-07 13:05:12 +00:00
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
if( selectedRows.empty() && m_SearchPaths->GetGridCursorRow() >= 0 )
|
|
|
|
selectedRows.push_back( m_SearchPaths->GetGridCursorRow() );
|
|
|
|
|
|
|
|
if( selectedRows.empty() )
|
2018-03-07 13:05:12 +00:00
|
|
|
return;
|
|
|
|
|
2018-08-24 18:28:11 +00:00
|
|
|
m_SearchPaths->CommitPendingChanges( true /* silent mode; we don't care if it's valid */ );
|
2018-03-07 13:05:12 +00:00
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
// Reverse sort so deleting a row doesn't change the indexes of the other rows.
|
|
|
|
selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } );
|
|
|
|
|
|
|
|
for( int row : selectedRows )
|
2020-04-30 18:42:20 +00:00
|
|
|
{
|
2021-12-12 17:27:40 +00:00
|
|
|
m_SearchPaths->DeleteRows( row, 1 );
|
|
|
|
|
|
|
|
// if there are still rows in grid, make previous row visible
|
|
|
|
if( m_SearchPaths->GetNumberRows() )
|
|
|
|
{
|
|
|
|
m_SearchPaths->MakeCellVisible( std::max( 0, row-1 ),
|
|
|
|
m_SearchPaths->GetGridCursorCol() );
|
|
|
|
m_SearchPaths->SetGridCursor( std::max( 0, row-1 ),
|
|
|
|
m_SearchPaths->GetGridCursorCol() );
|
|
|
|
}
|
2020-04-30 18:42:20 +00:00
|
|
|
}
|
2018-03-07 13:05:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIGURE_PATHS::OnSearchPathMoveUp( wxCommandEvent& event )
|
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_SearchPaths->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2018-03-07 13:05:12 +00:00
|
|
|
int curRow = m_SearchPaths->GetGridCursorRow();
|
|
|
|
int prevRow = curRow - 1;
|
|
|
|
|
|
|
|
if( curRow > 0 )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < m_SearchPaths->GetNumberCols(); ++i )
|
|
|
|
{
|
|
|
|
wxString tmp = m_SearchPaths->GetCellValue( curRow, i );
|
|
|
|
m_SearchPaths->SetCellValue( curRow, i, m_SearchPaths->GetCellValue( prevRow, i ) );
|
|
|
|
m_SearchPaths->SetCellValue( prevRow, i, tmp );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_SearchPaths->SetGridCursor( prevRow, m_SearchPaths->GetGridCursorCol() );
|
|
|
|
}
|
2018-08-24 18:28:11 +00:00
|
|
|
else
|
2021-07-15 19:26:35 +00:00
|
|
|
{
|
2018-08-24 18:28:11 +00:00
|
|
|
wxBell();
|
2021-07-15 19:26:35 +00:00
|
|
|
}
|
2018-03-07 13:05:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIGURE_PATHS::OnSearchPathMoveDown( wxCommandEvent& event )
|
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_SearchPaths->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2018-03-07 13:05:12 +00:00
|
|
|
int curRow = m_SearchPaths->GetGridCursorRow();
|
|
|
|
int nextRow = curRow + 1;
|
|
|
|
|
|
|
|
if( curRow < m_SearchPaths->GetNumberRows() - 1 )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < m_SearchPaths->GetNumberCols(); ++i )
|
|
|
|
{
|
|
|
|
wxString tmp = m_SearchPaths->GetCellValue( curRow, i );
|
|
|
|
m_SearchPaths->SetCellValue( curRow, i, m_SearchPaths->GetCellValue( nextRow, i ) );
|
|
|
|
m_SearchPaths->SetCellValue( nextRow, i, tmp );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_SearchPaths->SetGridCursor( nextRow, m_SearchPaths->GetGridCursorCol() );
|
|
|
|
}
|
2018-08-24 18:28:11 +00:00
|
|
|
else
|
2021-07-15 19:26:35 +00:00
|
|
|
{
|
2018-08-24 18:28:11 +00:00
|
|
|
wxBell();
|
2021-07-15 19:26:35 +00:00
|
|
|
}
|
2018-03-07 13:05:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIGURE_PATHS::OnGridCellRightClick( wxGridEvent& aEvent )
|
|
|
|
{
|
2020-03-26 11:02:59 +00:00
|
|
|
wxASSERT((int) TV_VALUE_COL == (int) SP_PATH_COL );
|
2018-03-07 13:05:12 +00:00
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
if( aEvent.GetCol() == TV_VALUE_COL )
|
2018-03-07 13:05:12 +00:00
|
|
|
{
|
|
|
|
wxMenu menu;
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
AddMenuItem( &menu, 1, _( "File Browser..." ), KiBitmap( BITMAPS::small_folder ) );
|
2021-07-15 19:26:35 +00:00
|
|
|
|
2018-03-07 13:05:12 +00:00
|
|
|
if( GetPopupMenuSelectionFromUser( menu ) == 1 )
|
|
|
|
{
|
2018-03-28 17:14:04 +00:00
|
|
|
wxDirDialog dlg( nullptr, _( "Select Path" ), m_curdir,
|
|
|
|
wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
|
2018-03-07 13:05:12 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
wxGrid* grid = dynamic_cast<wxGrid*>( aEvent.GetEventObject() );
|
2020-03-26 11:02:59 +00:00
|
|
|
grid->SetCellValue( aEvent.GetRow(), TV_VALUE_COL, dlg.GetPath() );
|
2018-03-28 17:14:04 +00:00
|
|
|
m_curdir = dlg.GetPath();
|
2018-03-07 13:05:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIGURE_PATHS::OnUpdateUI( wxUpdateUIEvent& event )
|
|
|
|
{
|
2020-10-20 22:31:15 +00:00
|
|
|
if( m_gridWidthsDirty )
|
2018-07-20 17:46:56 +00:00
|
|
|
{
|
|
|
|
int width = m_EnvVars->GetClientRect().GetWidth();
|
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
m_EnvVars->AutoSizeColumn( TV_NAME_COL );
|
|
|
|
m_EnvVars->SetColSize( TV_NAME_COL, std::max( m_EnvVars->GetColSize( TV_NAME_COL ), 120 ) );
|
2018-07-20 17:46:56 +00:00
|
|
|
|
2020-03-26 11:02:59 +00:00
|
|
|
m_EnvVars->SetColSize( TV_VALUE_COL, width - m_EnvVars->GetColSize( TV_NAME_COL ) );
|
2018-07-20 17:46:56 +00:00
|
|
|
|
|
|
|
width = m_SearchPaths->GetClientRect().GetWidth();
|
|
|
|
|
|
|
|
m_SearchPaths->AutoSizeColumn( SP_ALIAS_COL );
|
2021-07-15 19:26:35 +00:00
|
|
|
m_SearchPaths->SetColSize( SP_ALIAS_COL,
|
|
|
|
std::max( m_SearchPaths->GetColSize( SP_ALIAS_COL ), 120 ) );
|
2018-07-20 17:46:56 +00:00
|
|
|
|
|
|
|
m_SearchPaths->AutoSizeColumn( SP_PATH_COL );
|
2021-07-15 19:26:35 +00:00
|
|
|
m_SearchPaths->SetColSize( SP_PATH_COL,
|
|
|
|
std::max( m_SearchPaths->GetColSize( SP_PATH_COL ), 300 ) );
|
2018-07-20 17:46:56 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
m_SearchPaths->SetColSize( SP_DESC_COL, width -
|
|
|
|
( m_SearchPaths->GetColSize( SP_ALIAS_COL ) +
|
|
|
|
m_SearchPaths->GetColSize( SP_PATH_COL ) ) );
|
2020-10-30 17:40:13 +00:00
|
|
|
m_gridWidth = m_EnvVars->GetSize().GetX();
|
2018-07-20 17:46:56 +00:00
|
|
|
m_gridWidthsDirty = false;
|
|
|
|
}
|
2018-03-07 13:05:12 +00:00
|
|
|
|
2022-08-07 10:26:42 +00:00
|
|
|
// Handle a grid error. This is delayed to OnUpdateUI so that we can change focus even when
|
|
|
|
// the original validation was triggered from a killFocus event.
|
2018-03-07 13:05:12 +00:00
|
|
|
if( m_errorGrid )
|
|
|
|
{
|
2022-08-07 10:26:42 +00:00
|
|
|
// We will re-enter this routine when the error dialog is displayed, so make sure we don't
|
|
|
|
// keep putting up more dialogs.
|
2018-03-07 13:05:12 +00:00
|
|
|
wxGrid* grid = m_errorGrid;
|
|
|
|
m_errorGrid = nullptr;
|
|
|
|
|
|
|
|
DisplayErrorMessage( this, m_errorMsg );
|
|
|
|
|
|
|
|
grid->SetFocus();
|
|
|
|
grid->MakeCellVisible( m_errorRow, m_errorCol );
|
|
|
|
grid->SetGridCursor( m_errorRow, m_errorCol );
|
|
|
|
|
|
|
|
grid->EnableCellEditControl( true );
|
|
|
|
grid->ShowCellEditControl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIGURE_PATHS::OnGridSize( wxSizeEvent& event )
|
|
|
|
{
|
2020-10-30 17:40:13 +00:00
|
|
|
if( event.GetSize().GetX() != m_gridWidth )
|
|
|
|
m_gridWidthsDirty = true;
|
2018-03-07 13:05:12 +00:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIGURE_PATHS::OnHelp( wxCommandEvent& event )
|
|
|
|
{
|
2022-08-07 10:26:42 +00:00
|
|
|
wxSizer* sizerMain = GetSizer();
|
2020-12-07 09:28:54 +00:00
|
|
|
|
2022-08-07 10:26:42 +00:00
|
|
|
if( !m_helpBox )
|
2018-09-28 21:08:31 +00:00
|
|
|
{
|
2022-08-07 10:26:42 +00:00
|
|
|
m_helpBox = new HTML_WINDOW( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxHW_SCROLLBAR_AUTO );
|
|
|
|
|
|
|
|
wxString msg = _( "Enter the name and value for each environment variable. Grey entries "
|
|
|
|
"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." );
|
|
|
|
msg << "<br><br><b>";
|
|
|
|
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." );
|
|
|
|
msg << "</b>";
|
|
|
|
|
|
|
|
for( const wxString& var : ENV_VAR::GetPredefinedEnvVars() )
|
|
|
|
{
|
|
|
|
msg << "<br><br><b>" << var << "</b>";
|
|
|
|
|
|
|
|
const auto desc = ENV_VAR::LookUpEnvVarHelp( var );
|
|
|
|
|
|
|
|
if( desc.size() > 0 )
|
|
|
|
msg << ": " << desc;
|
2018-03-07 13:05:12 +00:00
|
|
|
|
2022-08-07 10:26:42 +00:00
|
|
|
}
|
2018-03-07 13:05:12 +00:00
|
|
|
|
2022-08-07 10:26:42 +00:00
|
|
|
m_helpBox->SetPage( msg );
|
|
|
|
m_helpBox->Show( false );
|
2018-03-07 13:05:12 +00:00
|
|
|
|
2022-08-07 10:26:42 +00:00
|
|
|
sizerMain->Insert( sizerMain->GetItemCount() - 1, m_helpBox, 1, wxALL|wxEXPAND, 10 );
|
2018-03-07 13:05:12 +00:00
|
|
|
}
|
|
|
|
|
2022-08-07 10:26:42 +00:00
|
|
|
if( m_helpBox->IsShown() )
|
|
|
|
{
|
|
|
|
m_helpBox->Show( false );
|
|
|
|
SetClientSize( wxSize( GetClientSize().x, m_heightBeforeHelp ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_helpBox->Show( true );
|
|
|
|
m_heightBeforeHelp = GetClientSize().y;
|
|
|
|
|
|
|
|
int minHelpBoxHeight = GetTextExtent( wxT( "T" ) ).y * 20;
|
2020-12-07 09:28:54 +00:00
|
|
|
|
2022-08-07 10:26:42 +00:00
|
|
|
if( GetClientSize().y < minHelpBoxHeight * 2 )
|
|
|
|
SetClientSize( wxSize( GetClientSize().x, GetClientSize().y + minHelpBoxHeight ) );
|
|
|
|
}
|
2018-09-28 21:08:31 +00:00
|
|
|
|
2022-08-07 10:26:42 +00:00
|
|
|
Layout();
|
2018-03-07 13:05:12 +00:00
|
|
|
}
|