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.
This commit is contained in:
Wayne Stambaugh 2015-03-29 17:22:53 -04:00
parent 34dfbc3306
commit 45d0448bb9
23 changed files with 1358 additions and 25 deletions

View File

@ -122,6 +122,8 @@ set( COMMON_ABOUT_DLG_SRCS
dialogs/dialog_hotkeys_editor_base.cpp dialogs/dialog_hotkeys_editor_base.cpp
dialogs/dialog_list_selector_base.cpp dialogs/dialog_list_selector_base.cpp
dialogs/dialog_page_settings_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 set( COMMON_PAGE_LAYOUT_SRCS

View File

@ -0,0 +1,233 @@
/*
* 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++;
}
}

View File

@ -0,0 +1,96 @@
///////////////////////////////////////////////////////////////////////////
// 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 );
}

View File

@ -0,0 +1,616 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project>
<FileVersion major="1" minor="13" />
<object class="Project" expanded="1">
<property name="class_decoration"></property>
<property name="code_generation">C++</property>
<property name="disconnect_events">1</property>
<property name="disconnect_mode">source_name</property>
<property name="disconnect_php_events">0</property>
<property name="disconnect_python_events">0</property>
<property name="embedded_files_path">res</property>
<property name="encoding">UTF-8</property>
<property name="event_generation">connect</property>
<property name="file">dialog_env_var_config_base</property>
<property name="first_id">1000</property>
<property name="help_provider">none</property>
<property name="internationalize">1</property>
<property name="name">dialog_env_var_editor_base</property>
<property name="namespace"></property>
<property name="path">.</property>
<property name="precompiled_header"></property>
<property name="relative_path">1</property>
<property name="skip_lua_events">1</property>
<property name="skip_php_events">1</property>
<property name="skip_python_events">1</property>
<property name="ui_table">UI</property>
<property name="use_enum">0</property>
<property name="use_microsoft_bom">0</property>
<object class="Dialog" expanded="1">
<property name="aui_managed">0</property>
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
<property name="bg"></property>
<property name="center">wxBOTH</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="enabled">1</property>
<property name="event_handler">impl_virtual</property>
<property name="extra_style"></property>
<property name="fg"></property>
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">DIALOG_ENV_VAR_CONFIG_BASE</property>
<property name="pos"></property>
<property name="size">-1,-1</property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title">Path Configuration</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnActivate"></event>
<event name="OnActivateApp"></event>
<event name="OnAuiFindManager"></event>
<event name="OnAuiPaneButton"></event>
<event name="OnAuiPaneClose"></event>
<event name="OnAuiPaneMaximize"></event>
<event name="OnAuiPaneRestore"></event>
<event name="OnAuiRender"></event>
<event name="OnChar"></event>
<event name="OnClose"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnHibernate"></event>
<event name="OnIconize"></event>
<event name="OnIdle"></event>
<event name="OnInitDialog"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">mainSizer</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer1</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxGrid" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="autosize_cols">0</property>
<property name="autosize_rows">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="cell_bg"></property>
<property name="cell_font"></property>
<property name="cell_horiz_alignment">wxALIGN_LEFT</property>
<property name="cell_text"></property>
<property name="cell_vert_alignment">wxALIGN_TOP</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="col_label_horiz_alignment">wxALIGN_CENTRE</property>
<property name="col_label_size">30</property>
<property name="col_label_values">&quot;Name&quot; &quot;Path&quot;</property>
<property name="col_label_vert_alignment">wxALIGN_CENTRE</property>
<property name="cols">2</property>
<property name="column_sizes"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="drag_col_move">0</property>
<property name="drag_col_size">1</property>
<property name="drag_grid_size">1</property>
<property name="drag_row_size">1</property>
<property name="editing">1</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="grid_line_color"></property>
<property name="grid_lines">1</property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label_bg"></property>
<property name="label_font"></property>
<property name="label_text"></property>
<property name="margin_height">0</property>
<property name="margin_width">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_grid</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="row_label_horiz_alignment">wxALIGN_CENTRE</property>
<property name="row_label_size">40</property>
<property name="row_label_values"></property>
<property name="row_label_vert_alignment">wxALIGN_CENTRE</property>
<property name="row_sizes"></property>
<property name="rows">0</property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip">Enter the names and paths for each path.&#x0A;&#x0A;Grey enteries are names that have been defined externally as system or user level environment variables.</property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnGridCellChange"></event>
<event name="OnGridCellLeftClick"></event>
<event name="OnGridCellLeftDClick"></event>
<event name="OnGridCellRightClick"></event>
<event name="OnGridCellRightDClick"></event>
<event name="OnGridCmdCellChange"></event>
<event name="OnGridCmdCellLeftClick"></event>
<event name="OnGridCmdCellLeftDClick"></event>
<event name="OnGridCmdCellRightClick"></event>
<event name="OnGridCmdCellRightDClick"></event>
<event name="OnGridCmdColSize"></event>
<event name="OnGridCmdEditorCreated"></event>
<event name="OnGridCmdEditorHidden"></event>
<event name="OnGridCmdEditorShown"></event>
<event name="OnGridCmdLabelLeftClick"></event>
<event name="OnGridCmdLabelLeftDClick"></event>
<event name="OnGridCmdLabelRightClick"></event>
<event name="OnGridCmdLabelRightDClick"></event>
<event name="OnGridCmdRangeSelect"></event>
<event name="OnGridCmdRowSize"></event>
<event name="OnGridCmdSelectCell"></event>
<event name="OnGridColSize"></event>
<event name="OnGridEditorCreated"></event>
<event name="OnGridEditorHidden"></event>
<event name="OnGridEditorShown"></event>
<event name="OnGridLabelLeftClick"></event>
<event name="OnGridLabelLeftDClick"></event>
<event name="OnGridLabelRightClick"></event>
<event name="OnGridLabelRightDClick"></event>
<event name="OnGridRangeSelect"></event>
<event name="OnGridRowSize"></event>
<event name="OnGridSelectCell"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer2</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_OK</property>
<property name="label">OK</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_buttonOk</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick"></event>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_CANCEL</property>
<property name="label">Cancel</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_buttonCancel</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick"></event>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Add</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_buttonAdd</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip">Add a new entry to the table.</property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">OnAddRow</event>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Delete</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_buttonDelete</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip">Remove the selectect entry from the table.</property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">OnDeleteSelectedRows</event>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
</object>
</object>
</object>
</object>
</object>
</wxFormBuilder_Project>

View File

@ -0,0 +1,56 @@
///////////////////////////////////////////////////////////////////////////
// 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__

View File

@ -38,6 +38,7 @@
#include <wx/snglinst.h> #include <wx/snglinst.h>
#include <wx/stdpaths.h> #include <wx/stdpaths.h>
#include <wx/sysopt.h> #include <wx/sysopt.h>
#include <wx/richmsgdlg.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <wxstruct.h> #include <wxstruct.h>
@ -50,6 +51,7 @@
#include <gestfich.h> #include <gestfich.h>
#include <menus_helpers.h> #include <menus_helpers.h>
#include <confirm.h> #include <confirm.h>
#include <dialog_env_var_config.h>
#define KICAD_COMMON wxT( "kicad_common" ) #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 languageCfgKey[] = wxT( "LanguageID" );
static const wxChar kicadFpLibPath[] = wxT( "KicadFootprintLibraryPath" ); static const wxChar kicadFpLibPath[] = wxT( "KicadFootprintLibraryPath" );
static const wxChar pathEnvVariables[] = wxT( "EnvironmentVariables" ); static const wxChar pathEnvVariables[] = wxT( "EnvironmentVariables" );
static const wxChar showEnvVarWarningDialog[] = wxT( "ShowEnvVarWarningDialog" );
static const wxChar traceEnvVars[] = wxT( "KIENVVARS" ); static const wxChar traceEnvVars[] = wxT( "KIENVVARS" );
@ -269,6 +272,7 @@ PGM_BASE::PGM_BASE()
m_common_settings = NULL; m_common_settings = NULL;
m_wx_app = NULL; m_wx_app = NULL;
m_show_env_var_dialog = true;
setLanguageId( wxLANGUAGE_DEFAULT ); setLanguageId( wxLANGUAGE_DEFAULT );
@ -404,19 +408,34 @@ bool PGM_BASE::initPgm()
SetLanguagePath(); SetLanguagePath();
// Useful local environment variable settings. // OS specific instantiation of wxConfigBase derivative:
m_local_env_vars[ wxString( wxT( "KIGITHUB" ) ) ] = m_common_settings = GetNewConfig( KICAD_COMMON );
wxString( wxT( "https://github.com/KiCad" ) );
// 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; wxFileName tmpFileName;
tmpFileName.AssignDir( wxString( wxT( KICAD_DATA_PATH ) ) ); tmpFileName.AssignDir( wxString( wxT( KICAD_DATA_PATH ) ) );
tmpFileName.AppendDir( wxT( "modules" ) ); tmpFileName.AppendDir( wxT( "modules" ) );
m_local_env_vars[ wxString( wxT( "KISYSMOD" ) ) ] = tmpFileName.GetPath(); envVarName = wxT( "KISYSMOD" );
tmpFileName.AppendDir( wxT( "packages3d" ) ); envVarItem.SetValue( tmpFileName.GetPath() );
m_local_env_vars[ wxString( wxT( "KISYS3DMOD" ) ) ] = tmpFileName.GetPath(); envVarItem.SetDefinedExternally( wxGetEnv( envVarName, NULL ) );
m_local_env_vars[ envVarName ] = envVarItem;
// OS specific instantiation of wxConfigBase derivative: envVarName = wxT( "KISYS3DMOD" );
m_common_settings = GetNewConfig( KICAD_COMMON ); tmpFileName.AppendDir( wxT( "packages3d" ) );
envVarItem.SetValue( tmpFileName.GetPath() );
envVarItem.SetDefinedExternally( wxGetEnv( envVarName, NULL ) );
m_local_env_vars[ envVarName ] = envVarItem;
}
ReadPdfBrowserInfos(); // needs m_common_settings ReadPdfBrowserInfos(); // needs m_common_settings
@ -490,6 +509,8 @@ void PGM_BASE::loadCommonSettings()
m_common_settings->Read( languageCfgKey, &languageSel ); m_common_settings->Read( languageCfgKey, &languageSel );
setLanguageId( wxLANGUAGE_DEFAULT ); setLanguageId( wxLANGUAGE_DEFAULT );
m_common_settings->Read( showEnvVarWarningDialog, &m_show_env_var_dialog );
// Search for the current selection // Search for the current selection
for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ ) 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++ ) for( unsigned i = 0; i < entries.GetCount(); i++ )
{ {
wxString val = m_common_settings->Read( entries[i], wxEmptyString ); 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(); for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
it != m_local_env_vars.end(); SetLocalEnvVariable( it->first, it->second.GetValue() );
++it )
SetLocalEnvVariable( it->first, it->second );
m_common_settings->SetPath( oldPath ); m_common_settings->SetPath( oldPath );
} }
@ -540,17 +559,16 @@ void PGM_BASE::saveCommonSettings()
wxString cur_dir = wxGetCwd(); wxString cur_dir = wxGetCwd();
m_common_settings->Write( workingDirKey, cur_dir ); m_common_settings->Write( workingDirKey, cur_dir );
m_common_settings->Write( showEnvVarWarningDialog, m_show_env_var_dialog );
// Save the local environment variables. // Save the local environment variables.
m_common_settings->SetPath( pathEnvVariables ); m_common_settings->SetPath( pathEnvVariables );
for( std::map<wxString, wxString>::iterator it = m_local_env_vars.begin(); for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
it != m_local_env_vars.end();
++it )
{ {
wxLogTrace( traceEnvVars, wxT( "Saving environment varaiable config entry %s as %s" ), wxLogTrace( traceEnvVars, wxT( "Saving environment varaiable config entry %s as %s" ),
GetChars( it->first ), GetChars( it->second ) ); GetChars( it->first ), GetChars( it->second.GetValue() ) );
m_common_settings->Write( it->first, it->second ); m_common_settings->Write( it->first, it->second.GetValue() );
} }
m_common_settings->SetPath( wxT( ".." ) ); m_common_settings->SetPath( wxT( ".." ) );
@ -746,3 +764,63 @@ bool PGM_BASE::SetLocalEnvVariable( const wxString& aName, const wxString& aValu
return wxSetEnv( aName, aValue ); 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() );
}

View File

@ -72,3 +72,42 @@ FILE_NAME_WITH_PATH_CHAR_VALIDATOR::FILE_NAME_WITH_PATH_CHAR_VALIDATOR( wxString
SetExcludes( illegalCharList ); 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();
}
}

View File

@ -69,6 +69,7 @@ BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, EDA_BASE_FRAME )
EVT_MENU( wxID_HELP, CVPCB_MAINFRAME::GetKicadHelp ) EVT_MENU( wxID_HELP, CVPCB_MAINFRAME::GetKicadHelp )
EVT_MENU( wxID_ABOUT, CVPCB_MAINFRAME::GetKicadAbout ) EVT_MENU( wxID_ABOUT, CVPCB_MAINFRAME::GetKicadAbout )
EVT_MENU( ID_SAVE_PROJECT, CVPCB_MAINFRAME::SaveProjectFile ) 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_CONFIG_KEEP_OPEN_ON_SAVE, CVPCB_MAINFRAME::OnKeepOpenOnSave )
EVT_MENU( ID_CVPCB_EQUFILES_LIST_EDIT, CVPCB_MAINFRAME::OnEditEquFilesList ) 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 // returns the Footprint Viewer frame, if exists, or NULL
return (DISPLAY_FOOTPRINTS_FRAME*) wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME ); return (DISPLAY_FOOTPRINTS_FRAME*) wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME );
} }
void CVPCB_MAINFRAME::OnConfigurePaths( wxCommandEvent& aEvent )
{
Pgm().ConfigurePaths( this );
}

View File

@ -142,6 +142,8 @@ public:
*/ */
void OnEditFootprintLibraryTable( wxCommandEvent& aEvent ); void OnEditFootprintLibraryTable( wxCommandEvent& aEvent );
void OnConfigurePaths( wxCommandEvent& aEvent );
/** /**
* Function OnEditEquFilesList * Function OnEditEquFilesList
* envokes the equ files list edit dialog. * envokes the equ files list edit dialog.

View File

@ -116,6 +116,13 @@ void CVPCB_MAINFRAME::ReCreateMenuBar()
_( "Footprint Li&braries" ), _( "Configure footprint libraries" ), _( "Footprint Li&braries" ), _( "Configure footprint libraries" ),
KiBitmap( library_table_xpm ) ); 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, AddMenuItem( preferencesMenu, ID_CVPCB_EQUFILES_LIST_EDIT,
_( "Edit &Equ Files List" ), _( "Edit &Equ Files List" ),
_( "Setup equ files list (.equ files)\n" _( "Setup equ files list (.equ files)\n"

View File

@ -0,0 +1,63 @@
/*
* 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_

View File

@ -90,6 +90,7 @@ enum main_id
ID_PREFERENCES_HOTKEY_SHOW_EDITOR, ID_PREFERENCES_HOTKEY_SHOW_EDITOR,
ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST, ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST,
ID_PREFERENCES_HOTKEY_END, ID_PREFERENCES_HOTKEY_END,
ID_PREFERENCES_CONFIGURE_PATHS,
ID_PREFRENCES_MACROS, ID_PREFRENCES_MACROS,
ID_PREFRENCES_MACROS_SAVE, ID_PREFRENCES_MACROS_SAVE,

View File

@ -41,11 +41,52 @@ class wxConfigBase;
class wxSingleInstanceChecker; class wxSingleInstanceChecker;
class wxApp; class wxApp;
class wxMenu; class wxMenu;
class wxWindow;
// inter program module calling // inter program module calling
#define VTBL_ENTRY virtual #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 * Class PGM_BASE
* keeps program (whole process) data for KiCad programs. * keeps program (whole process) data for KiCad programs.
@ -185,6 +226,35 @@ public:
*/ */
VTBL_ENTRY bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue ); 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 * Function App
* returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe. * returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe.
@ -265,8 +335,10 @@ protected:
wxSize m_help_size; wxSize m_help_size;
/// Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD. /// Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
/// library table. ENV_VAR_MAP m_local_env_vars;
std::map<wxString, wxString> 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; wxApp* m_wx_app;

View File

@ -60,4 +60,23 @@ public:
FILE_NAME_WITH_PATH_CHAR_VALIDATOR( wxString* aValue = NULL ); 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 #endif // #ifndef VALIDATORS_H

View File

@ -275,6 +275,7 @@ public:
void OnUpdateAutoPlaceTracksMode( wxUpdateUIEvent& aEvent ); void OnUpdateAutoPlaceTracksMode( wxUpdateUIEvent& aEvent );
void OnUpdateMuWaveToolbar( wxUpdateUIEvent& aEvent ); void OnUpdateMuWaveToolbar( wxUpdateUIEvent& aEvent );
void OnLayerColorChange( wxCommandEvent& aEvent ); void OnLayerColorChange( wxCommandEvent& aEvent );
void OnConfigurePaths( wxCommandEvent& aEvent );
/** /**
* Function RecordMacros. * Function RecordMacros.

View File

@ -185,6 +185,7 @@ public:
void OnRunPcbCalculator( wxCommandEvent& event ); void OnRunPcbCalculator( wxCommandEvent& event );
void OnRunPageLayoutEditor( wxCommandEvent& event ); void OnRunPageLayoutEditor( wxCommandEvent& event );
void OnConfigurePaths( wxCommandEvent& aEvent );
void OnOpenTextEditor( wxCommandEvent& event ); void OnOpenTextEditor( wxCommandEvent& event );
void OnOpenFileInTextEditor( wxCommandEvent& event ); void OnOpenFileInTextEditor( wxCommandEvent& event );
void OnOpenFileInEditor( wxCommandEvent& event ); void OnOpenFileInEditor( wxCommandEvent& event );

View File

@ -560,3 +560,9 @@ void KICAD_MANAGER_FRAME::Process_Config( wxCommandEvent& event )
break; break;
} }
} }
void KICAD_MANAGER_FRAME::OnConfigurePaths( wxCommandEvent& aEvent )
{
Pgm().ConfigurePaths( this );
}

View File

@ -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, KICAD_MANAGER_FRAME::OnLoadProject )
EVT_TOOL( ID_NEW_PROJECT_FROM_TEMPLATE, KICAD_MANAGER_FRAME::OnCreateProjectFromTemplate ) EVT_TOOL( ID_NEW_PROJECT_FROM_TEMPLATE, KICAD_MANAGER_FRAME::OnCreateProjectFromTemplate )
EVT_TOOL( ID_LOAD_PROJECT, KICAD_MANAGER_FRAME::OnLoadProject ) 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 // Menu events
EVT_MENU( ID_SAVE_PROJECT, KICAD_MANAGER_FRAME::OnSaveProject ) EVT_MENU( ID_SAVE_PROJECT, KICAD_MANAGER_FRAME::OnSaveProject )
EVT_MENU( wxID_EXIT, KICAD_MANAGER_FRAME::OnExit ) EVT_MENU( wxID_EXIT, KICAD_MANAGER_FRAME::OnExit )
EVT_MENU( ID_TO_TEXT_EDITOR, KICAD_MANAGER_FRAME::OnOpenTextEditor ) EVT_MENU( ID_TO_TEXT_EDITOR, KICAD_MANAGER_FRAME::OnOpenTextEditor )
EVT_MENU( ID_BROWSE_AN_SELECT_FILE, KICAD_MANAGER_FRAME::OnOpenFileInTextEditor ) 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_PREFERED_EDITOR, EDA_BASE_FRAME::OnSelectPreferredEditor )
EVT_MENU( ID_SELECT_DEFAULT_PDF_BROWSER, KICAD_MANAGER_FRAME::OnSelectDefaultPdfBrowser ) EVT_MENU( ID_SELECT_DEFAULT_PDF_BROWSER, KICAD_MANAGER_FRAME::OnSelectDefaultPdfBrowser )
EVT_MENU( ID_SELECT_PREFERED_PDF_BROWSER, KICAD_MANAGER_FRAME::OnSelectPreferredPdfBrowser ) EVT_MENU( ID_SELECT_PREFERED_PDF_BROWSER, KICAD_MANAGER_FRAME::OnSelectPreferredPdfBrowser )
@ -301,6 +300,13 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
// Menu Preferences: // Menu Preferences:
wxMenu* preferencesMenu = new wxMenu; 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 // Text editor
AddMenuItem( preferencesMenu, AddMenuItem( preferencesMenu,
ID_SELECT_PREFERED_EDITOR, ID_SELECT_PREFERED_EDITOR,

View File

@ -284,6 +284,13 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar()
_( "Footprint Li&braries" ), _( "Configure footprint libraries" ), _( "Footprint Li&braries" ), _( "Configure footprint libraries" ),
KiBitmap( library_table_xpm ) ); 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 // Settings
AddMenuItem( prefs_menu, wxID_PREFERENCES, AddMenuItem( prefs_menu, wxID_PREFERENCES,
_( "&Settings" ), _( "Select default parameters values in Footprint Editor" ), _( "&Settings" ), _( "Select default parameters values in Footprint Editor" ),

View File

@ -484,6 +484,13 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
_( "Footprint Li&braries" ), _( "Configure footprint libraries" ), _( "Footprint Li&braries" ), _( "Configure footprint libraries" ),
KiBitmap( library_table_xpm ) ); 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 // Colors and Visibility are also handled by the layers manager toolbar
AddMenuItem( configmenu, ID_MENU_PCB_SHOW_HIDE_LAYERS_MANAGER_DIALOG, AddMenuItem( configmenu, ID_MENU_PCB_SHOW_HIDE_LAYERS_MANAGER_DIALOG,
m_show_layer_manager_tools ? m_show_layer_manager_tools ?

View File

@ -125,6 +125,7 @@ public:
void ToolOnRightClick( wxCommandEvent& event ); void ToolOnRightClick( wxCommandEvent& event );
void OnSelectOptionToolbar( wxCommandEvent& event ); void OnSelectOptionToolbar( wxCommandEvent& event );
void OnConfigurePaths( wxCommandEvent& aEvent );
/** /**
* Function OnSaveLibraryAs * Function OnSaveLibraryAs

View File

@ -129,6 +129,7 @@ BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME )
FOOTPRINT_EDIT_FRAME::ProcessPreferences ) FOOTPRINT_EDIT_FRAME::ProcessPreferences )
EVT_MENU( wxID_PREFERENCES, EVT_MENU( wxID_PREFERENCES,
FOOTPRINT_EDIT_FRAME::ProcessPreferences ) FOOTPRINT_EDIT_FRAME::ProcessPreferences )
EVT_MENU( ID_PREFERENCES_CONFIGURE_PATHS, FOOTPRINT_EDIT_FRAME::OnConfigurePaths )
// popup commands // popup commands
EVT_MENU_RANGE( ID_POPUP_PCB_START_RANGE, ID_POPUP_PCB_END_RANGE, 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 );
}

View File

@ -134,6 +134,7 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME )
// menu Config // menu Config
EVT_MENU( ID_PCB_DRAWINGS_WIDTHS_SETUP, PCB_EDIT_FRAME::OnConfigurePcbOptions ) 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_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_SAVE, PCB_EDIT_FRAME::Process_Config )
EVT_MENU( ID_CONFIG_READ, 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, 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; return change;
} }
void PCB_EDIT_FRAME::OnConfigurePaths( wxCommandEvent& aEvent )
{
Pgm().ConfigurePaths( this );
}