Commit 45d0448b authored by Wayne Stambaugh's avatar Wayne Stambaugh

Add path (environment variable) configuration dialog.

* Create new dialog to edit environment variables.
* Add helper class ENV_VAR_ITEM to manage environment variable values and
  if they were defined externally.
* A path configuration dialog access to KiCad, CvPcb, Pcbnew, and Footprint Editor
  window menus.
* Add validator for environment variables.
parent 34dfbc33
......@@ -122,6 +122,8 @@ set( COMMON_ABOUT_DLG_SRCS
dialogs/dialog_hotkeys_editor_base.cpp
dialogs/dialog_list_selector_base.cpp
dialogs/dialog_page_settings_base.cpp
dialogs/dialog_env_var_config_base.cpp
dialogs/dialog_env_var_config.cpp
)
set( COMMON_PAGE_LAYOUT_SRCS
......
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2015 Kicad Developers, see AUTHORS.txt for contributors.
*
* 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
*/
/**
* @file dialg_env_var_config.cpp
*/
#include <dialog_env_var_config.h>
#include <validators.h>
DIALOG_ENV_VAR_CONFIG::DIALOG_ENV_VAR_CONFIG( wxWindow* aParent, const ENV_VAR_MAP& aEnvVarMap ) :
DIALOG_ENV_VAR_CONFIG_BASE( aParent )
{
m_extDefsChanged = false;
m_envVarMap = aEnvVarMap;
m_grid->AppendRows( (int) m_envVarMap.size() );
for( size_t row = 0; row < m_envVarMap.size(); row++ )
{
wxGridCellTextEditor* editor = new wxGridCellTextEditor;
ENVIRONMENT_VARIABLE_CHAR_VALIDATOR envVarValidator;
editor->SetValidator( envVarValidator );
m_grid->SetCellEditor( (int) row, 0, editor );
editor = new wxGridCellTextEditor;
FILE_NAME_WITH_PATH_CHAR_VALIDATOR pathValidator;
editor->SetValidator( pathValidator );
m_grid->SetCellEditor( (int) row, 1, editor );
}
wxButton* okButton = (wxButton*) FindWindowById( wxID_OK );
if( okButton )
SetDefaultItem( okButton );
wxLogDebug( wxT( "In DIALOG_ENV_VAR_CONFIG ctor." ) );
}
bool DIALOG_ENV_VAR_CONFIG::TransferDataToWindow()
{
wxLogDebug( wxT( "In DIALOG_ENV_VAR_CONFIG::TransferDataToWindow()." ) );
if( !wxDialog::TransferDataToWindow() )
return false;
long row = 0L;
for( ENV_VAR_MAP_ITER it = m_envVarMap.begin(); it != m_envVarMap.end(); ++it )
{
m_grid->SetCellValue( row, 0, it->first );
m_grid->SetCellValue( row, 1, it->second.GetValue() );
// Highlight environment variables that are externally defined.
if( it->second.GetDefinedExternally() )
{
wxGridCellAttr* attr = m_grid->GetOrCreateCellAttr( row, 0 );
attr->SetBackgroundColour( *wxLIGHT_GREY );
m_grid->SetRowAttr( row, attr );
}
row++;
}
m_grid->AutoSizeColumns();
m_grid->AutoSizeRows();
GetSizer()->Layout();
GetSizer()->Fit( this );
GetSizer()->SetSizeHints( this );
return true;
}
bool DIALOG_ENV_VAR_CONFIG::TransferDataFromWindow()
{
wxString nums( wxT( "0123456789" ) );
if( !wxDialog::TransferDataFromWindow() )
return false;
int row;
wxArrayString envVarNames;
for( row = 0; row < m_grid->GetNumberRows(); row++ )
{
wxString caption = _( "Invalid Input" );
wxString name = m_grid->GetCellValue( row, 0 );
wxString value = m_grid->GetCellValue( row, 1 );
// Ignore completely empty rows.
if( name.IsEmpty() && value.IsEmpty() )
continue;
// Check for empty cells.
if( name.IsEmpty() )
{
wxMessageBox( _( "Path configuration name cannot be empty." ), caption,
wxOK | wxICON_ERROR, this );
return false;
}
if( value.IsEmpty() )
{
wxMessageBox( _( "Path configuration value cannot be empty." ), caption,
wxOK | wxICON_ERROR, this );
return false;
}
// First character of environment variable name cannot be a number.
if( nums.Find( name[0] ) != wxNOT_FOUND )
{
wxMessageBox( _( "Path configuration names cannot have a number as the first "
"character." ), caption, wxOK | wxICON_ERROR, this );
return false;
}
// Check for duplicate environment variable names.
if( envVarNames.Index( name ) != wxNOT_FOUND )
{
wxMessageBox( _( "Cannot have duplicate configuration names." ), caption,
wxOK | wxICON_ERROR, this );
return false;
}
envVarNames.Add( name );
}
// Add new entries and update any modified entries..
for( row = 0; row < m_grid->GetNumberRows(); row++ )
{
wxString name = m_grid->GetCellValue( row, 0 );
wxString value = m_grid->GetCellValue( row, 1 );
ENV_VAR_MAP_ITER it = m_envVarMap.find( name );
if( it == m_envVarMap.end() )
{
ENV_VAR_ITEM item( value, wxGetEnv( name, NULL ) );
// Add new envrionment variable.
m_envVarMap[ name ] = item;
}
else if( it->second.GetValue() != value )
{
// Environment variable already defined but it's value changed.
it->second.SetValue( value );
// Externally defined variable has been changed.
if( it->second.GetDefinedExternally() )
m_extDefsChanged = true;
}
}
// Remove deleted entries from the map.
for( ENV_VAR_MAP_ITER it = m_envVarMap.begin(); it != m_envVarMap.end(); ++it )
{
bool found = false;
for( row = 0; row < m_grid->GetNumberRows(); row++ )
{
if( m_grid->GetCellValue( row, 0 ) == it->first )
{
found = true;
break;
}
}
if( !found )
{
m_envVarMap.erase( it );
it--;
}
}
wxLogDebug( wxT( "In DIALOG_ENV_VAR_CONFIG::TransferDataFromWindow()." ) );
return true;
}
void DIALOG_ENV_VAR_CONFIG::OnAddRow( wxCommandEvent& aEvent )
{
m_grid->AppendRows();
int row = m_grid->GetNumberRows() - 1;
wxGridCellTextEditor* editor = new wxGridCellTextEditor;
ENVIRONMENT_VARIABLE_CHAR_VALIDATOR envVarValidator;
editor->SetValidator( envVarValidator );
m_grid->SetCellEditor( row, 0, editor );
editor = new wxGridCellTextEditor;
FILE_NAME_WITH_PATH_CHAR_VALIDATOR pathValidator;
editor->SetValidator( pathValidator );
m_grid->SetCellEditor( row, 1, editor );
}
void DIALOG_ENV_VAR_CONFIG::OnDeleteSelectedRows( wxCommandEvent& aEvent )
{
if( !m_grid->IsSelection() )
return;
wxGridUpdateLocker locker( m_grid );
for( int n = 0; n < m_grid->GetNumberRows(); )
{
if( m_grid->IsInSelection( n , 0 ) )
m_grid->DeleteRows( n, 1 );
else
n++;
}
}
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 5 2014)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "dialog_env_var_config_base.h"
///////////////////////////////////////////////////////////////////////////
DIALOG_ENV_VAR_CONFIG_BASE::DIALOG_ENV_VAR_CONFIG_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
wxBoxSizer* mainSizer;
mainSizer = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* bSizer1;
bSizer1 = new wxBoxSizer( wxVERTICAL );
m_grid = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
// Grid
m_grid->CreateGrid( 0, 2 );
m_grid->EnableEditing( true );
m_grid->EnableGridLines( true );
m_grid->EnableDragGridSize( true );
m_grid->SetMargins( 0, 0 );
// Columns
m_grid->EnableDragColMove( false );
m_grid->EnableDragColSize( true );
m_grid->SetColLabelSize( 30 );
m_grid->SetColLabelValue( 0, _("Name") );
m_grid->SetColLabelValue( 1, _("Path") );
m_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
// Rows
m_grid->EnableDragRowSize( true );
m_grid->SetRowLabelSize( 40 );
m_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
// Label Appearance
// Cell Defaults
m_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
m_grid->SetToolTip( _("Enter the names and paths for each path.\n\nGrey enteries are names that have been defined externally as system or user level environment variables.") );
bSizer1->Add( m_grid, 1, wxALL|wxEXPAND, 5 );
mainSizer->Add( bSizer1, 1, wxEXPAND, 5 );
wxBoxSizer* bSizer2;
bSizer2 = new wxBoxSizer( wxVERTICAL );
m_buttonOk = new wxButton( this, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );
m_buttonOk->SetDefault();
bSizer2->Add( m_buttonOk, 0, wxALL, 5 );
m_buttonCancel = new wxButton( this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer2->Add( m_buttonCancel, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 );
m_buttonAdd = new wxButton( this, wxID_ANY, _("Add"), wxDefaultPosition, wxDefaultSize, 0 );
m_buttonAdd->SetToolTip( _("Add a new entry to the table.") );
bSizer2->Add( m_buttonAdd, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 );
m_buttonDelete = new wxButton( this, wxID_ANY, _("Delete"), wxDefaultPosition, wxDefaultSize, 0 );
m_buttonDelete->SetToolTip( _("Remove the selectect entry from the table.") );
bSizer2->Add( m_buttonDelete, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 );
mainSizer->Add( bSizer2, 0, wxEXPAND, 5 );
this->SetSizer( mainSizer );
this->Layout();
mainSizer->Fit( this );
this->Centre( wxBOTH );
// Connect Events
m_buttonAdd->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnAddRow ), NULL, this );
m_buttonDelete->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnDeleteSelectedRows ), NULL, this );
}
DIALOG_ENV_VAR_CONFIG_BASE::~DIALOG_ENV_VAR_CONFIG_BASE()
{
// Disconnect Events
m_buttonAdd->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnAddRow ), NULL, this );
m_buttonDelete->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnDeleteSelectedRows ), NULL, this );
}
This diff is collapsed.
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 5 2014)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __DIALOG_ENV_VAR_CONFIG_BASE_H__
#define __DIALOG_ENV_VAR_CONFIG_BASE_H__
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
class DIALOG_SHIM;
#include "dialog_shim.h"
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/string.h>
#include <wx/font.h>
#include <wx/grid.h>
#include <wx/gdicmn.h>
#include <wx/sizer.h>
#include <wx/button.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class DIALOG_ENV_VAR_CONFIG_BASE
///////////////////////////////////////////////////////////////////////////////
class DIALOG_ENV_VAR_CONFIG_BASE : public DIALOG_SHIM
{
private:
protected:
wxGrid* m_grid;
wxButton* m_buttonOk;
wxButton* m_buttonCancel;
wxButton* m_buttonAdd;
wxButton* m_buttonDelete;
// Virtual event handlers, overide them in your derived class
virtual void OnAddRow( wxCommandEvent& event ) { event.Skip(); }
virtual void OnDeleteSelectedRows( wxCommandEvent& event ) { event.Skip(); }
public:
DIALOG_ENV_VAR_CONFIG_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Path Configuration"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_ENV_VAR_CONFIG_BASE();
};
#endif //__DIALOG_ENV_VAR_CONFIG_BASE_H__
......@@ -38,6 +38,7 @@
#include <wx/snglinst.h>
#include <wx/stdpaths.h>
#include <wx/sysopt.h>
#include <wx/richmsgdlg.h>
#include <pgm_base.h>
#include <wxstruct.h>
......@@ -50,6 +51,7 @@
#include <gestfich.h>
#include <menus_helpers.h>
#include <confirm.h>
#include <dialog_env_var_config.h>
#define KICAD_COMMON wxT( "kicad_common" )
......@@ -61,6 +63,7 @@ const wxChar PGM_BASE::workingDirKey[] = wxT( "WorkingDir" ); // public
static const wxChar languageCfgKey[] = wxT( "LanguageID" );
static const wxChar kicadFpLibPath[] = wxT( "KicadFootprintLibraryPath" );
static const wxChar pathEnvVariables[] = wxT( "EnvironmentVariables" );
static const wxChar showEnvVarWarningDialog[] = wxT( "ShowEnvVarWarningDialog" );
static const wxChar traceEnvVars[] = wxT( "KIENVVARS" );
......@@ -269,6 +272,7 @@ PGM_BASE::PGM_BASE()
m_common_settings = NULL;
m_wx_app = NULL;
m_show_env_var_dialog = true;
setLanguageId( wxLANGUAGE_DEFAULT );
......@@ -404,20 +408,35 @@ bool PGM_BASE::initPgm()
SetLanguagePath();
// Useful local environment variable settings.
m_local_env_vars[ wxString( wxT( "KIGITHUB" ) ) ] =
wxString( wxT( "https://github.com/KiCad" ) );
wxFileName tmpFileName;
tmpFileName.AssignDir( wxString( wxT( KICAD_DATA_PATH ) ) );
tmpFileName.AppendDir( wxT( "modules" ) );
m_local_env_vars[ wxString( wxT( "KISYSMOD" ) ) ] = tmpFileName.GetPath();
tmpFileName.AppendDir( wxT( "packages3d" ) );
m_local_env_vars[ wxString( wxT( "KISYS3DMOD" ) ) ] = tmpFileName.GetPath();
// OS specific instantiation of wxConfigBase derivative:
m_common_settings = GetNewConfig( KICAD_COMMON );
// Only define the default environment variable if they haven't been set in the
// .kicad_common configuration file.
if( m_common_settings && !m_common_settings->HasGroup( pathEnvVariables ) )
{
wxString envVarName = wxT( "KIGITHUB" );
ENV_VAR_ITEM envVarItem;
envVarItem.SetValue( wxString( wxT( "https://github.com/KiCad" ) ) );
envVarItem.SetDefinedExternally( wxGetEnv( envVarName, NULL ) );
m_local_env_vars[ envVarName ] = envVarItem;
wxFileName tmpFileName;
tmpFileName.AssignDir( wxString( wxT( KICAD_DATA_PATH ) ) );
tmpFileName.AppendDir( wxT( "modules" ) );
envVarName = wxT( "KISYSMOD" );
envVarItem.SetValue( tmpFileName.GetPath() );
envVarItem.SetDefinedExternally( wxGetEnv( envVarName, NULL ) );
m_local_env_vars[ envVarName ] = envVarItem;
envVarName = wxT( "KISYS3DMOD" );
tmpFileName.AppendDir( wxT( "packages3d" ) );
envVarItem.SetValue( tmpFileName.GetPath() );
envVarItem.SetDefinedExternally( wxGetEnv( envVarName, NULL ) );
m_local_env_vars[ envVarName ] = envVarItem;
}
ReadPdfBrowserInfos(); // needs m_common_settings
loadCommonSettings();
......@@ -490,6 +509,8 @@ void PGM_BASE::loadCommonSettings()
m_common_settings->Read( languageCfgKey, &languageSel );
setLanguageId( wxLANGUAGE_DEFAULT );
m_common_settings->Read( showEnvVarWarningDialog, &m_show_env_var_dialog );
// Search for the current selection
for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
{
......@@ -519,13 +540,11 @@ void PGM_BASE::loadCommonSettings()
for( unsigned i = 0; i < entries.GetCount(); i++ )
{
wxString val = m_common_settings->Read( entries[i], wxEmptyString );
m_local_env_vars[ entries[i] ] = val;
m_local_env_vars[ entries[i] ] = ENV_VAR_ITEM( val, wxGetEnv( entries[i], NULL ) );
}
for( std::map<wxString, wxString>::iterator it = m_local_env_vars.begin();
it != m_local_env_vars.end();
++it )
SetLocalEnvVariable( it->first, it->second );
for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
SetLocalEnvVariable( it->first, it->second.GetValue() );
m_common_settings->SetPath( oldPath );
}
......@@ -540,17 +559,16 @@ void PGM_BASE::saveCommonSettings()
wxString cur_dir = wxGetCwd();
m_common_settings->Write( workingDirKey, cur_dir );
m_common_settings->Write( showEnvVarWarningDialog, m_show_env_var_dialog );
// Save the local environment variables.
m_common_settings->SetPath( pathEnvVariables );
for( std::map<wxString, wxString>::iterator it = m_local_env_vars.begin();
it != m_local_env_vars.end();
++it )
for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
{
wxLogTrace( traceEnvVars, wxT( "Saving environment varaiable config entry %s as %s" ),
GetChars( it->first ), GetChars( it->second ) );
m_common_settings->Write( it->first, it->second );
GetChars( it->first ), GetChars( it->second.GetValue() ) );
m_common_settings->Write( it->first, it->second.GetValue() );
}
m_common_settings->SetPath( wxT( ".." ) );
......@@ -746,3 +764,63 @@ bool PGM_BASE::SetLocalEnvVariable( const wxString& aName, const wxString& aValu
return wxSetEnv( aName, aValue );
}
void PGM_BASE::SetLocalEnvVariables( const ENV_VAR_MAP& aEnvVarMap )
{
m_local_env_vars.clear();
m_local_env_vars = aEnvVarMap;
if( m_common_settings )
m_common_settings->DeleteGroup( pathEnvVariables );
saveCommonSettings();
// Overwrites externally defined environment variable until the next time the application
// is run.
for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
{
wxLogTrace( traceEnvVars, wxT( "Setting local environment variable %s to %s." ),
GetChars( it->first ), GetChars( it->second.GetValue() ) );
wxSetEnv( it->first, it->second.GetValue() );
}
}
void PGM_BASE::ConfigurePaths( wxWindow* aParent )
{
DIALOG_ENV_VAR_CONFIG dlg( aParent, GetLocalEnvVariables() );
if( dlg.ShowModal() == wxID_CANCEL )
return;
ENV_VAR_MAP envVarMap = dlg.GetEnvVarMap();
for( ENV_VAR_MAP_ITER it = envVarMap.begin(); it != envVarMap.end(); ++it )
{
wxLogDebug( wxT( "Environment variable %s=%s defined externally = %d" ),
GetChars( it->first ), GetChars( it->second.GetValue() ),
it->second.GetDefinedExternally() );
}
// If any of the environment variables are defined externally, warn the user that the
// next time kicad is run that the externally defined variables will be used instead of
// the user's settings. This is by design.
if( dlg.ExternalDefsChanged() && m_show_env_var_dialog )
{
wxString msg1 = _( "Warning! Some of paths you have configured have been defined \n"
"externally to the running process and will 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 this\n"
"behavior, either rename any conflicting entries or remove the\n"
"external environment variable definition(s) from your system." );
wxRichMessageDialog dlg( aParent, msg1 );
dlg.ShowDetailedText( msg2 );
dlg.ShowCheckBox( _( "Do not show this message again." ) );
dlg.ShowModal();
m_show_env_var_dialog = !dlg.IsCheckBoxChecked();
}
SetLocalEnvVariables( dlg.GetEnvVarMap() );
}
......@@ -72,3 +72,42 @@ FILE_NAME_WITH_PATH_CHAR_VALIDATOR::FILE_NAME_WITH_PATH_CHAR_VALIDATOR( wxString
SetExcludes( illegalCharList );
}
ENVIRONMENT_VARIABLE_CHAR_VALIDATOR::ENVIRONMENT_VARIABLE_CHAR_VALIDATOR( wxString* aValue ) :
wxTextValidator( wxFILTER_INCLUDE_CHAR_LIST, aValue )
{
wxString includeChars( wxT( "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_" ) );
SetCharIncludes( includeChars );
}
void ENVIRONMENT_VARIABLE_CHAR_VALIDATOR::OnChar( wxKeyEvent& aEvent )
{
wxTextValidator::OnChar( aEvent );
// Special key or error in valid character check already occurred.
if( aEvent.GetSkipped() )
return;
// Check if first character is valid. Cannot be number.
int keyCode = aEvent.GetKeyCode();
wxString str( (wxUniChar)keyCode, 1 );
wxString numbers( wxT( "0123456789" ) );
if( (m_stringValue->IsEmpty() && numbers.Contains( str ))
|| (!m_stringValue->IsEmpty() && numbers.Contains( m_stringValue[0])) )
{
if( !wxValidator::IsSilent() )
wxBell();
// eat message
return;
}
else
{
aEvent.Skip();
}
}
......@@ -69,6 +69,7 @@ BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, EDA_BASE_FRAME )
EVT_MENU( wxID_HELP, CVPCB_MAINFRAME::GetKicadHelp )
EVT_MENU( wxID_ABOUT, CVPCB_MAINFRAME::GetKicadAbout )
EVT_MENU( ID_SAVE_PROJECT, CVPCB_MAINFRAME::SaveProjectFile )
EVT_MENU( ID_PREFERENCES_CONFIGURE_PATHS, CVPCB_MAINFRAME::OnConfigurePaths )
EVT_MENU( ID_CVPCB_CONFIG_KEEP_OPEN_ON_SAVE, CVPCB_MAINFRAME::OnKeepOpenOnSave )
EVT_MENU( ID_CVPCB_EQUFILES_LIST_EDIT, CVPCB_MAINFRAME::OnEditEquFilesList )
......@@ -1034,3 +1035,9 @@ DISPLAY_FOOTPRINTS_FRAME* CVPCB_MAINFRAME::GetFpViewerFrame()
// returns the Footprint Viewer frame, if exists, or NULL
return (DISPLAY_FOOTPRINTS_FRAME*) wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME );
}
void CVPCB_MAINFRAME::OnConfigurePaths( wxCommandEvent& aEvent )
{
Pgm().ConfigurePaths( this );
}
......@@ -142,6 +142,8 @@ public:
*/
void OnEditFootprintLibraryTable( wxCommandEvent& aEvent );
void OnConfigurePaths( wxCommandEvent& aEvent );
/**
* Function OnEditEquFilesList
* envokes the equ files list edit dialog.
......
......@@ -116,6 +116,13 @@ void CVPCB_MAINFRAME::ReCreateMenuBar()
_( "Footprint Li&braries" ), _( "Configure footprint libraries" ),
KiBitmap( library_table_xpm ) );
// Path configuration edit dialog.
AddMenuItem( preferencesMenu,
ID_PREFERENCES_CONFIGURE_PATHS,
_( "Configure Pa&ths" ),
_( "Edit path configuration environment variables" ),
KiBitmap( editor_xpm ) );
AddMenuItem( preferencesMenu, ID_CVPCB_EQUFILES_LIST_EDIT,
_( "Edit &Equ Files List" ),
_( "Setup equ files list (.equ files)\n"
......
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2015 Kicad Developers, see AUTHORS.txt for contributors.
*
* 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
*/
#ifndef _DIALOG_ENV_VAR_CONFIG_H_
#define _DIALOG_ENV_VAR_CONFIG_H_
class EDA_DRAW_FRAME;
#include <../common/dialogs/dialog_env_var_config_base.h>
#include <pgm_base.h>
/**
* DIALOG_ENV_VAR_CONFIG class declaration
*/
class DIALOG_ENV_VAR_CONFIG: public DIALOG_ENV_VAR_CONFIG_BASE
{
private:
ENV_VAR_MAP m_envVarMap;
bool m_extDefsChanged;
protected:
virtual void OnAddRow( wxCommandEvent& aEvent );
virtual void OnDeleteSelectedRows( wxCommandEvent& aEvent );
public:
DIALOG_ENV_VAR_CONFIG( wxWindow* parent, const ENV_VAR_MAP& aEnvVarMap );
bool TransferDataToWindow();
bool TransferDataFromWindow();
bool ExternalDefsChanged() const { return m_extDefsChanged; }
const ENV_VAR_MAP& GetEnvVarMap() const
{
return m_envVarMap;
}
};
#endif // _DIALOG_ENV_VAR_CONFIG_H_
......@@ -90,6 +90,7 @@ enum main_id
ID_PREFERENCES_HOTKEY_SHOW_EDITOR,
ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST,
ID_PREFERENCES_HOTKEY_END,
ID_PREFERENCES_CONFIGURE_PATHS,
ID_PREFRENCES_MACROS,
ID_PREFRENCES_MACROS_SAVE,
......
......@@ -41,11 +41,52 @@ class wxConfigBase;
class wxSingleInstanceChecker;
class wxApp;
class wxMenu;
class wxWindow;
// inter program module calling
#define VTBL_ENTRY virtual
/**
* Class ENV_VAR_ITEM
*
* is a simple helper class to store environment variable values and the status of whether
* or not they were defined externally to the process created when any of the KiCad applications
* was launched.
*/
class ENV_VAR_ITEM
{
public:
ENV_VAR_ITEM( const wxString& aValue = wxEmptyString, bool aIsDefinedExternally = false ) :
m_value( aValue ),
m_isDefinedExternally( aIsDefinedExternally )
{
}
bool GetDefinedExternally() const { return m_isDefinedExternally; }
void SetDefinedExternally( bool aIsDefinedExternally )
{
m_isDefinedExternally = aIsDefinedExternally;
}
const wxString& GetValue() const { return m_value; }
void SetValue( const wxString& aValue ) { m_value = aValue; }
private:
/// The environment variable string value.
wxString m_value;
/// Flag to indicate if the environment variable was defined externally to the process.
bool m_isDefinedExternally;
};
typedef std::map<wxString, ENV_VAR_ITEM> ENV_VAR_MAP;
typedef std::map<wxString, ENV_VAR_ITEM>::iterator ENV_VAR_MAP_ITER;
typedef std::map<wxString, ENV_VAR_ITEM>::const_iterator ENV_VAR_MAP_CITER;
/**
* Class PGM_BASE
* keeps program (whole process) data for KiCad programs.
......@@ -185,6 +226,35 @@ public:
*/
VTBL_ENTRY bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue );
/**
* Function SetLocalEnvVariables
*
* sets the internal local environment variable map to \a aEnvVarMap, updates the entries
* in the .kicad_common configuration file, and sets the environment variable to the new
* settings.
*
* @param aEnvVarMap is a ENV_VAR_MAP object containing the new environment variables.
*/
VTBL_ENTRY void SetLocalEnvVariables( const ENV_VAR_MAP& aEnvVarMap );
VTBL_ENTRY const ENV_VAR_MAP& GetLocalEnvVariables() const
{
return m_local_env_vars;
}
/**
* Function ConfigurePaths
*
* presents a dialog to the user to edit local environment variable settings for use in
* the footprint library table and the 3D model importer. It was added to PGM_BASE because
* it will eventually find use for in schematic I/O design so it needs to accessible by
* almost every KiCad application.
*
* @param aParent - a pointer the wxWindow parent of the dialog or NULL to use the top level
* window.
*/
VTBL_ENTRY void ConfigurePaths( wxWindow* aParent = NULL );
/**
* Function App
* returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe.
......@@ -265,8 +335,10 @@ protected:
wxSize m_help_size;
/// Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
/// library table.
std::map<wxString, wxString> m_local_env_vars;
ENV_VAR_MAP m_local_env_vars;
/// Flag to indicate if the environment variable overwrite warning dialog should be shown.
bool m_show_env_var_dialog;
wxApp* m_wx_app;
......
......@@ -60,4 +60,23 @@ public:
FILE_NAME_WITH_PATH_CHAR_VALIDATOR( wxString* aValue = NULL );
};
/**
* Class ENVIRONMENT_VARIABLE_CHAR_VALIDATOR
*
* This class provides a custome wxValidator object for limiting the allowable characters
* when defining an environment varaible name in a text edit control. Only uppercase,
* numbers, and underscore (_) characters are valid and the first character of the name
* cannot start with a number. This is according to IEEE Std 1003.1-2001. Even though
* most systems support other characters, these characters guarantee compatibility for
* all shells.
*/
class ENVIRONMENT_VARIABLE_CHAR_VALIDATOR : public wxTextValidator
{
public:
ENVIRONMENT_VARIABLE_CHAR_VALIDATOR( wxString* aValue = NULL );
protected:
void OnChar( wxKeyEvent& aEvent );
};
#endif // #ifndef VALIDATORS_H
......@@ -275,6 +275,7 @@ public:
void OnUpdateAutoPlaceTracksMode( wxUpdateUIEvent& aEvent );
void OnUpdateMuWaveToolbar( wxUpdateUIEvent& aEvent );
void OnLayerColorChange( wxCommandEvent& aEvent );
void OnConfigurePaths( wxCommandEvent& aEvent );
/**
* Function RecordMacros.
......
......@@ -185,6 +185,7 @@ public:
void OnRunPcbCalculator( wxCommandEvent& event );
void OnRunPageLayoutEditor( wxCommandEvent& event );
void OnConfigurePaths( wxCommandEvent& aEvent );
void OnOpenTextEditor( wxCommandEvent& event );
void OnOpenFileInTextEditor( wxCommandEvent& event );
void OnOpenFileInEditor( wxCommandEvent& event );
......
......@@ -560,3 +560,9 @@ void KICAD_MANAGER_FRAME::Process_Config( wxCommandEvent& event )
break;
}
}
void KICAD_MANAGER_FRAME::OnConfigurePaths( wxCommandEvent& aEvent )
{
Pgm().ConfigurePaths( this );
}
......@@ -44,14 +44,13 @@ BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME )
EVT_TOOL( ID_NEW_PROJECT, KICAD_MANAGER_FRAME::OnLoadProject )
EVT_TOOL( ID_NEW_PROJECT_FROM_TEMPLATE, KICAD_MANAGER_FRAME::OnCreateProjectFromTemplate )
EVT_TOOL( ID_LOAD_PROJECT, KICAD_MANAGER_FRAME::OnLoadProject )
EVT_TOOL( ID_SAVE_PROJECT, KICAD_MANAGER_FRAME::OnSaveProject )
EVT_TOOL( ID_SAVE_AND_ZIP_FILES, KICAD_MANAGER_FRAME::OnArchiveFiles )
// Menu events
EVT_MENU( ID_SAVE_PROJECT, KICAD_MANAGER_FRAME::OnSaveProject )
EVT_MENU( wxID_EXIT, KICAD_MANAGER_FRAME::OnExit )
EVT_MENU( ID_TO_TEXT_EDITOR, KICAD_MANAGER_FRAME::OnOpenTextEditor )
EVT_MENU( ID_BROWSE_AN_SELECT_FILE, KICAD_MANAGER_FRAME::OnOpenFileInTextEditor )
EVT_MENU( ID_PREFERENCES_CONFIGURE_PATHS, KICAD_MANAGER_FRAME::OnConfigurePaths )
EVT_MENU( ID_SELECT_PREFERED_EDITOR, EDA_BASE_FRAME::OnSelectPreferredEditor )
EVT_MENU( ID_SELECT_DEFAULT_PDF_BROWSER, KICAD_MANAGER_FRAME::OnSelectDefaultPdfBrowser )
EVT_MENU( ID_SELECT_PREFERED_PDF_BROWSER, KICAD_MANAGER_FRAME::OnSelectPreferredPdfBrowser )
......@@ -301,6 +300,13 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
// Menu Preferences:
wxMenu* preferencesMenu = new wxMenu;
// Path configuration edit dialog.
AddMenuItem( preferencesMenu,
ID_PREFERENCES_CONFIGURE_PATHS,
_( "Configure Pa&ths" ),
_( "Edit path configuration environment variables" ),
KiBitmap( editor_xpm ) );
// Text editor
AddMenuItem( preferencesMenu,
ID_SELECT_PREFERED_EDITOR,
......
......@@ -284,6 +284,13 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar()
_( "Footprint Li&braries" ), _( "Configure footprint libraries" ),
KiBitmap( library_table_xpm ) );
// Path configuration edit dialog.
AddMenuItem( prefs_menu,
ID_PREFERENCES_CONFIGURE_PATHS,
_( "Configure Pa&ths" ),
_( "Edit path configuration environment variables" ),
KiBitmap( editor_xpm ) );
// Settings
AddMenuItem( prefs_menu, wxID_PREFERENCES,
_( "&Settings" ), _( "Select default parameters values in Footprint Editor" ),
......
......@@ -484,6 +484,13 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
_( "Footprint Li&braries" ), _( "Configure footprint libraries" ),
KiBitmap( library_table_xpm ) );
// Path configuration edit dialog.
AddMenuItem( configmenu,
ID_PREFERENCES_CONFIGURE_PATHS,
_( "Configure Pa&ths" ),
_( "Edit path configuration environment variables" ),
KiBitmap( editor_xpm ) );
// Colors and Visibility are also handled by the layers manager toolbar
AddMenuItem( configmenu, ID_MENU_PCB_SHOW_HIDE_LAYERS_MANAGER_DIALOG,
m_show_layer_manager_tools ?
......
......@@ -125,6 +125,7 @@ public:
void ToolOnRightClick( wxCommandEvent& event );
void OnSelectOptionToolbar( wxCommandEvent& event );
void OnConfigurePaths( wxCommandEvent& aEvent );
/**
* Function OnSaveLibraryAs
......
......@@ -129,6 +129,7 @@ BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME )
FOOTPRINT_EDIT_FRAME::ProcessPreferences )
EVT_MENU( wxID_PREFERENCES,
FOOTPRINT_EDIT_FRAME::ProcessPreferences )
EVT_MENU( ID_PREFERENCES_CONFIGURE_PATHS, FOOTPRINT_EDIT_FRAME::OnConfigurePaths )
// popup commands
EVT_MENU_RANGE( ID_POPUP_PCB_START_RANGE, ID_POPUP_PCB_END_RANGE,
......@@ -912,3 +913,8 @@ void FOOTPRINT_EDIT_FRAME::ProcessPreferences( wxCommandEvent& event )
}
}
void FOOTPRINT_EDIT_FRAME::OnConfigurePaths( wxCommandEvent& aEvent )
{
Pgm().ConfigurePaths( this );
}
......@@ -134,6 +134,7 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME )
// menu Config
EVT_MENU( ID_PCB_DRAWINGS_WIDTHS_SETUP, PCB_EDIT_FRAME::OnConfigurePcbOptions )
EVT_MENU( ID_PCB_LIB_TABLE_EDIT, PCB_EDIT_FRAME::Process_Config )
EVT_MENU( ID_PREFERENCES_CONFIGURE_PATHS, PCB_EDIT_FRAME::OnConfigurePaths )
EVT_MENU( ID_CONFIG_SAVE, PCB_EDIT_FRAME::Process_Config )
EVT_MENU( ID_CONFIG_READ, PCB_EDIT_FRAME::Process_Config )
EVT_MENU_RANGE( ID_PREFERENCES_HOTKEY_START, ID_PREFERENCES_HOTKEY_END,
......@@ -1044,3 +1045,9 @@ bool PCB_EDIT_FRAME::SetCurrentNetClass( const wxString& aNetClassName )
return change;
}
void PCB_EDIT_FRAME::OnConfigurePaths( wxCommandEvent& aEvent )
{
Pgm().ConfigurePaths( this );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment