ENV_VAR config dialog enhancements.

From an initial work of Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
jean-pierre charras 2017-10-26 11:47:57 +02:00
parent d2d1237506
commit fc5e8e5f52
5 changed files with 1696 additions and 565 deletions

View File

@ -28,32 +28,52 @@
#include <dialog_env_var_config.h> #include <dialog_env_var_config.h>
#include <confirm.h>
#include <validators.h> #include <validators.h>
#include <html_messagebox.h> #include <html_messagebox.h>
#include <wx/regex.h> #include <wx/regex.h>
/** A helper dialog to edit a env var name and/or its value (often a path)
*/
class DIALOG_ENV_VAR_SINGLE : public DIALOG_ENV_VAR_SINGLE_BASE
{
public:
DIALOG_ENV_VAR_SINGLE( wxWindow* parent, const wxString& aEnvVarName,
const wxString& aEnvVarPath );
/// @return the new environment variable name
wxString GetEnvVarName() const
{
return m_envVarName->GetValue();
}
/// @return the new environment variable value
wxString GetEnvVarValue() const
{
return m_envVarPath->GetValue();
}
/// disable the environment variable name (must be called
/// for predefined environment variable names, not editable
void SetEnvVarProtected()
{
m_envVarName->Enable( false );
}
protected:
void OnSelectPath( wxCommandEvent& event ) override;
void onHelpClick( wxCommandEvent& event ) override;
bool TransferDataFromWindow() override;
};
DIALOG_ENV_VAR_CONFIG::DIALOG_ENV_VAR_CONFIG( wxWindow* aParent, const ENV_VAR_MAP& aEnvVarMap ) : DIALOG_ENV_VAR_CONFIG::DIALOG_ENV_VAR_CONFIG( wxWindow* aParent, const ENV_VAR_MAP& aEnvVarMap ) :
DIALOG_ENV_VAR_CONFIG_BASE( aParent ) DIALOG_ENV_VAR_CONFIG_BASE( aParent )
{ {
m_extDefsChanged = false; // Copy environment variables across
m_envVarMap = aEnvVarMap; 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 );
}
} }
@ -64,26 +84,24 @@ bool DIALOG_ENV_VAR_CONFIG::TransferDataToWindow()
if( !wxDialog::TransferDataToWindow() ) if( !wxDialog::TransferDataToWindow() )
return false; return false;
long row = 0L; //TODO
/*
// Grab the project path var (not editable)
wxString prjPath;
for( ENV_VAR_MAP_ITER it = m_envVarMap.begin(); it != m_envVarMap.end(); ++it ) wxGetEnv( PROJECT_VAR_NAME, &prjPath );
{
m_grid->SetCellValue( row, 0, it->first );
m_grid->SetCellValue( row, 1, it->second.GetValue() );
// Highlight environment variables that are externally defined. m_kiprjmod->SetLabel( prjPath );
if( it->second.GetDefinedExternally() ) */
{
wxGridCellAttr* attr = m_grid->GetOrCreateCellAttr( row, 0 );
attr->SetBackgroundColour( *wxLIGHT_GREY );
m_grid->SetRowAttr( row, attr );
}
row++; //TODO - Call SetAlternateRowColour first to prevent assertion error
} //m_pathList->EnableAlternateRowColours( true );
PopulatePathList();
// Select the first item in the list
SelectListIndex( 0 );
m_grid->AutoSizeColumns();
m_grid->AutoSizeRows();
GetSizer()->Layout(); GetSizer()->Layout();
GetSizer()->Fit( this ); GetSizer()->Fit( this );
GetSizer()->SetSizeHints( this ); GetSizer()->SetSizeHints( this );
@ -95,162 +113,168 @@ bool DIALOG_ENV_VAR_CONFIG::TransferDataToWindow()
bool DIALOG_ENV_VAR_CONFIG::TransferDataFromWindow() bool DIALOG_ENV_VAR_CONFIG::TransferDataFromWindow()
{ {
if( !wxDialog::TransferDataFromWindow() ) 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;
wxLogDebug( wxT( "Row %d, name: %s, value %s." ), row,
GetChars( name ), GetChars( value ) );
// Name cannot be empty.
if( name.IsEmpty() )
{
wxMessageBox( _( "Environment variable name cannot be empty." ),
caption, wxOK | wxICON_ERROR, this );
m_grid->GoToCell( row, 0 );
m_grid->SetGridCursor( row, 0 );
return false; return false;
} }
// Value cannot be empty. Pgm().SetLocalEnvVariables( m_envVarMap );
if( value.IsEmpty() )
{
wxMessageBox( _( "Environment variable value cannot be empty." ), caption,
wxOK | wxICON_ERROR, this );
m_grid->GoToCell( row, 1 );
m_grid->SetGridCursor( row, 1 );
m_grid->SetFocus();
return false;
}
// First character of the environment variable name cannot be a digit (0-9).
if( name.Left( 1 ).IsNumber() )
{
wxMessageBox( _( "The first character of an environment variable name cannot be "
"a digit (0-9)." ), caption, wxOK | wxICON_ERROR, this );
m_grid->GoToCell( row, 0 );
m_grid->SetGridCursor( row, 0 );
m_grid->SelectBlock( row, 0, row, 0 );
m_grid->SetFocus();
return false;
}
// Check for duplicate environment variable names.
if( envVarNames.Index( name ) != wxNOT_FOUND )
{
wxMessageBox( _( "Cannot have duplicate environment variable names." ), caption,
wxOK | wxICON_ERROR, this );
m_grid->GoToCell( row, 0 );
m_grid->SetGridCursor( row, 0 );
m_grid->SelectRow( row );
m_grid->SetFocus();
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 environment 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;
}
}
std::vector< wxString > removeFromMap;
// 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 )
removeFromMap.push_back( it->first );
}
for( size_t i = 0; i < removeFromMap.size(); i++ )
m_envVarMap.erase( removeFromMap[i] );
return true; return true;
} }
void DIALOG_ENV_VAR_CONFIG::OnAddRow( wxCommandEvent& aEvent ) void DIALOG_ENV_VAR_CONFIG::PopulatePathList()
{ {
m_grid->AppendRows(); m_pathList->Freeze();
int row = m_grid->GetNumberRows() - 1; m_pathList->ClearAll();
wxGridCellTextEditor* editor = new wxGridCellTextEditor;
ENVIRONMENT_VARIABLE_CHAR_VALIDATOR envVarNameValidator;
editor->SetValidator( envVarNameValidator );
m_grid->SetCellEditor( row, 0, editor );
editor = new wxGridCellTextEditor; m_pathList->AppendColumn( _( "Name" ) );
FILE_NAME_WITH_PATH_CHAR_VALIDATOR pathValidator; m_pathList->AppendColumn( _( "Path" ) );
editor->SetValidator( pathValidator );
m_grid->SetCellEditor( row, 1, editor ); int row = 0;
m_grid->GoToCell( row, 0 );
m_grid->SetGridCursor( row, 0 ); for( auto it = m_envVarMap.begin(); it != m_envVarMap.end(); ++it )
m_grid->SetFocus(); {
long index = m_pathList->InsertItem( row, it->first );
m_pathList->SetItem( index, 1, it->second.GetValue() );
//TODO - Indicate via background colour if the path is defined external to KiCad
row++;
}
m_pathList->SetColumnWidth( 0, wxLIST_AUTOSIZE );
m_pathList->SetColumnWidth( 1, wxLIST_AUTOSIZE );
m_pathList->Update();
m_pathList->Thaw();
} }
void DIALOG_ENV_VAR_CONFIG::OnDeleteSelectedRows( wxCommandEvent& aEvent ) bool DIALOG_ENV_VAR_CONFIG::GetPathAtIndex( unsigned int aIndex, wxString& aEnvVar, wxString& aEnvPath )
{ {
if( !m_grid->IsSelection() ) if( aIndex < 0 || aIndex > m_envVarMap.size() )
return;
wxGridUpdateLocker locker( m_grid );
for( int n = 0; n < m_grid->GetNumberRows(); )
{ {
if( m_grid->IsInSelection( n , 0 ) ) return false;
m_grid->DeleteRows( n, 1 ); }
unsigned int idx = 0;
for( auto it = m_envVarMap.begin(); it != m_envVarMap.end(); ++it )
{
if( idx == aIndex )
{
aEnvVar = it->first;
aEnvPath = it->second.GetValue();
return true;
}
idx++;
}
return false;
}
void DIALOG_ENV_VAR_CONFIG::OnAddButton( wxCommandEvent& event )
{
DIALOG_ENV_VAR_SINGLE dlg( this, wxEmptyString, wxEmptyString );
if( dlg.ShowModal() == wxID_OK )
{
wxString newName = dlg.GetEnvVarName();
wxString newPath = dlg.GetEnvVarValue();
// Check that the name does not already exist
if( m_envVarMap.count( newName ) > 0 )
{
//TODO - Improve this message, use DisplayErrorMessage instead
DisplayError( this, _( "Path already exists" ) );
}
else else
n++; {
m_envVarMap[newName] = ENV_VAR_ITEM( newPath );
// Update path list
PopulatePathList();
}
} }
} }
void DIALOG_ENV_VAR_CONFIG::OnHelpRequest( wxCommandEvent& aEvent ) void DIALOG_ENV_VAR_CONFIG::OnEditButton( wxCommandEvent& event )
{
EditSelectedEntry();
}
void DIALOG_ENV_VAR_CONFIG::EditSelectedEntry()
{
wxString envName;
wxString envPath;
if( GetPathAtIndex( m_pathIndex, envName, envPath ) )
{
auto dlg = new DIALOG_ENV_VAR_SINGLE( nullptr, envName, envPath );
if( IsEnvVarImmutable( envName ) )
{
dlg->SetEnvVarProtected();
}
if( dlg->ShowModal() == wxID_OK )
{
wxString newName = dlg->GetEnvVarName();
wxString newPath = dlg->GetEnvVarValue();
// If the path name has not been changed
if( envName.Cmp( newName ) == 0 )
{
m_envVarMap[envName].SetValue( newPath );
if( m_envVarMap[envName].GetDefinedExternally() )
{
m_extDefsChanged = true;
}
}
// Path-name needs to be updated
else
{
if( IsEnvVarImmutable( envName ) )
{
DisplayErrorMessage( this,
wxString::Format( _( "Environment variable '%s' cannot be renamed" ),
envName.ToStdString() ),
_( "The selected environment variable name "
"is required for KiCad functionality and "
"can not be renamed." ) );
return;
}
auto envVar = m_envVarMap[envName];
m_envVarMap.erase( envName );
envVar.SetValue( newPath );
envVar.SetDefinedExternally( false );
m_envVarMap[newName] = envVar;
}
// Update the path list
PopulatePathList();
}
dlg->Destroy();
}
}
void DIALOG_ENV_VAR_CONFIG::OnHelpButton( wxCommandEvent& event )
{ {
wxString msg = _( "Enter the name and path for each environment variable. Grey entries " wxString msg = _( "Enter the name and path for each environment variable. Grey entries "
"are names that have been defined externally at the system or user " "are names that have been defined externally at the system or user "
@ -261,6 +285,8 @@ void DIALOG_ENV_VAR_CONFIG::OnHelpRequest( wxCommandEvent& aEvent )
msg << _( "To ensure environment variable names are valid on all platforms, the name field " msg << _( "To ensure environment variable names are valid on all platforms, the name field "
"will only accept upper case letters, digits, and the underscore characters." ); "will only accept upper case letters, digits, and the underscore characters." );
msg << wxT( "</b><br><br>" ); msg << wxT( "</b><br><br>" );
msg << _( "<b>KICAD_SYMBOL_DIR</b> is the base path of the locally installed symbol libraries." );
msg << wxT( "<br><br>" );
msg << _( "<b>KIGITHUB</b> is used by KiCad to define the URL of the repository " msg << _( "<b>KIGITHUB</b> is used by KiCad to define the URL of the repository "
"of the official KiCad libraries." ); "of the official KiCad libraries." );
msg << wxT( "<br><br>" ); msg << wxT( "<br><br>" );
@ -279,7 +305,165 @@ void DIALOG_ENV_VAR_CONFIG::OnHelpRequest( wxCommandEvent& aEvent )
msg << _( "<b>KICAD_PTEMPLATES</b> is optional and can be defined if you want to " msg << _( "<b>KICAD_PTEMPLATES</b> is optional and can be defined if you want to "
"create your own project templates folder." ); "create your own project templates folder." );
HTML_MESSAGE_BOX dlg( GetParent(), _( "Environment Variable Help" ) ); DisplayHtmlInfoMessage( GetParent(), _( "Environment Variable Help" ), msg );
dlg.AddHTML_Text( msg ); }
dlg.ShowModal();
bool DIALOG_ENV_VAR_CONFIG::IsEnvVarImmutable( const wxString aEnvVar )
{
/*
* TODO - Instead of defining these values here,
* extract them from elsewhere in the program
* (where they are originally defined)
*/
static const wxString immutable[] = {
"KIGITHUB",
"KISYS3DMOD",
"KISYSMOD",
"KIPRJMOD",
"KICAD_PTEMPLATES",
"KICAD_SYMBOL_DIR"
};
for( unsigned int ii=0; ii<6; ii++ )
{
if( aEnvVar.Cmp( immutable[ii] ) == 0 )
{
return true;
}
}
return false;
}
void DIALOG_ENV_VAR_CONFIG::OnRemoveButton( wxCommandEvent& event )
{
wxString envName;
wxString envPath;
if( GetPathAtIndex( m_pathIndex, envName, envPath ) )
{
if( IsEnvVarImmutable( envName ) )
{
return;
}
m_envVarMap.erase( envName );
PopulatePathList();
}
}
void DIALOG_ENV_VAR_CONFIG::SelectListIndex( unsigned int aIndex )
{
if( aIndex >= m_envVarMap.size() )
{
aIndex = 0;
}
m_pathIndex = aIndex;
wxString envName;
wxString envPath;
if( GetPathAtIndex( m_pathIndex, envName, envPath ) )
{
// Disable the 'delete' button if the path cannot be deleted
m_deletePathButton->Enable( !IsEnvVarImmutable( envName ) );
}
}
void DIALOG_ENV_VAR_CONFIG::OnPathSelected( wxListEvent& event )
{
SelectListIndex( event.GetIndex() );
}
void DIALOG_ENV_VAR_CONFIG::OnPathActivated( wxListEvent& event )
{
SelectListIndex( event.GetIndex() );
EditSelectedEntry();
}
///////////////////////////
// DIALOG_ENV_VAR_SINGLE //
///////////////////////////
DIALOG_ENV_VAR_SINGLE::DIALOG_ENV_VAR_SINGLE( wxWindow* parent,
const wxString& aEnvVarName,
const wxString& aEnvVarPath ) :
DIALOG_ENV_VAR_SINGLE_BASE( parent )
{
m_envVarName->SetValue( aEnvVarName );
m_envVarPath->SetValue( aEnvVarPath );
m_envVarName->SetValidator( ENVIRONMENT_VARIABLE_CHAR_VALIDATOR() );
}
void DIALOG_ENV_VAR_SINGLE::OnSelectPath( wxCommandEvent& event )
{
wxString title = _( "Set path for ENV_VAR" );
wxString path; // Currently the first opened path is not initialized
wxDirDialog dlg( nullptr, title, path, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
if( dlg.ShowModal() == wxID_OK )
m_envVarPath->SetValue( dlg.GetPath() );
}
bool DIALOG_ENV_VAR_SINGLE::TransferDataFromWindow()
{
// The user pressed the OK button, test data validity
wxString name = m_envVarName->GetValue();
wxString path = m_envVarPath->GetValue();
// Neither name nor path can be empty
if( name.IsEmpty() )
{
DisplayError( this, _( "Environment variable name cannot be empty." ) );
// Veto:
return false;
}
if( path.IsEmpty() )
{
DisplayError( this, _( "Environment variable value cannot be empty." ) );
// Veto:
return false;
}
// Name cannot start with a number
if( name.Left( 1 ).IsNumber() )
{
DisplayError( this, _( "Environment variable name cannot start with a digit (0-9)." ) );
// Veto:
return false;
}
// No errors detected
return true;
}
void DIALOG_ENV_VAR_SINGLE::onHelpClick( wxCommandEvent& event )
{
wxString msg = _( "An environment variable is as an equivalence of a string.<br>"
"It is used mainly in paths to make them portable between installs<br><br>"
"For instance, if an environment variable is defined as<br>"
"<b>MYLIBPATH</b> with a value like <b>e:/kicad_libs</b>, "
"if a library name is <br><b>${MYLIBPATH}/mylib.lib</b>, the actual path is"
"<br><b>e:/kicad_libs/mylib.lib</b>"
"<br><br>"
"<b>Note:</b><br>"
"Only chars <b>ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_</b> are allowed in environment variable names<br>"
"and the environment variable name cannot start with a digit (0-9)"
);
DisplayHtmlInfoMessage( GetParent(), _( "Environment Variable Help" ), msg );
} }

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 17 2015) // C++ code generated with wxFormBuilder (version Aug 4 2017)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
@ -16,61 +16,50 @@ DIALOG_ENV_VAR_CONFIG_BASE::DIALOG_ENV_VAR_CONFIG_BASE( wxWindow* parent, wxWind
wxBoxSizer* mainSizer; wxBoxSizer* mainSizer;
mainSizer = new wxBoxSizer( wxVERTICAL ); mainSizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bupperSizer; wxBoxSizer* bSizer5;
bupperSizer = new wxBoxSizer( wxHORIZONTAL ); bSizer5 = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bleftSizer; wxStaticBoxSizer* sbSizer2;
bleftSizer = new wxBoxSizer( wxVERTICAL ); sbSizer2 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("KiCad Environment Paths") ), wxVERTICAL );
m_grid = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); wxBoxSizer* bSizer7;
bSizer7 = new wxBoxSizer( wxHORIZONTAL );
// Grid m_pathList = new wxListCtrl( sbSizer2->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_HRULES|wxLC_REPORT|wxLC_VRULES );
m_grid->CreateGrid( 0, 2 ); bSizer7->Add( m_pathList, 1, wxALL|wxEXPAND, 5 );
m_grid->EnableEditing( true );
m_grid->EnableGridLines( true );
m_grid->EnableDragGridSize( true );
m_grid->SetMargins( 0, 0 );
// Columns wxBoxSizer* bSizer6;
m_grid->EnableDragColMove( false ); bSizer6 = new wxBoxSizer( wxVERTICAL );
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_addPathButton = new wxButton( sbSizer2->GetStaticBox(), ID_BUTTON_ADD_PATH, _("Add"), wxDefaultPosition, wxDefaultSize, 0 );
m_grid->EnableDragRowSize( true ); m_addPathButton->SetToolTip( _("Add path prefix") );
m_grid->SetRowLabelSize( 40 );
m_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
// Label Appearance bSizer6->Add( m_addPathButton, 0, wxALL, 5 );
// Cell Defaults m_editPathButton = new wxButton( sbSizer2->GetStaticBox(), ID_BUTTON_EDIT_PATH, _("Edit"), wxDefaultPosition, wxDefaultSize, 0 );
m_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); m_editPathButton->SetToolTip( _("Edit selected path prefix") );
bleftSizer->Add( m_grid, 1, wxALL|wxEXPAND, 5 );
bSizer6->Add( m_editPathButton, 0, wxALL, 5 );
m_deletePathButton = new wxButton( sbSizer2->GetStaticBox(), ID_BUTTON_DELETE_PATH, _("Remove"), wxDefaultPosition, wxDefaultSize, 0 );
m_deletePathButton->SetToolTip( _("Remove selected path prefix") );
bSizer6->Add( m_deletePathButton, 0, wxALL, 5 );
bupperSizer->Add( bleftSizer, 1, wxEXPAND, 5 ); bSizer6->Add( 0, 0, 1, wxEXPAND, 5 );
wxBoxSizer* brightSizer;
brightSizer = new wxBoxSizer( wxVERTICAL );
m_buttonAdd = new wxButton( this, wxID_ANY, _("Add"), wxDefaultPosition, wxDefaultSize, 0 );
m_buttonAdd->SetToolTip( _("Add a new entry to the table.") );
brightSizer->Add( m_buttonAdd, 0, wxALL|wxEXPAND, 5 );
m_buttonDelete = new wxButton( this, wxID_ANY, _("Delete"), wxDefaultPosition, wxDefaultSize, 0 );
m_buttonDelete->SetToolTip( _("Remove the selected entry from the table.") );
brightSizer->Add( m_buttonDelete, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 5 );
bupperSizer->Add( brightSizer, 0, wxALIGN_CENTER_VERTICAL, 5 ); bSizer7->Add( bSizer6, 0, wxEXPAND, 5 );
mainSizer->Add( bupperSizer, 1, wxEXPAND, 5 ); sbSizer2->Add( bSizer7, 1, wxEXPAND, 5 );
bSizer5->Add( sbSizer2, 1, wxEXPAND, 5 );
mainSizer->Add( bSizer5, 1, wxEXPAND, 5 );
m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
mainSizer->Add( m_staticline1, 0, wxEXPAND | wxALL, 5 ); mainSizer->Add( m_staticline1, 0, wxEXPAND | wxALL, 5 );
@ -93,16 +82,92 @@ DIALOG_ENV_VAR_CONFIG_BASE::DIALOG_ENV_VAR_CONFIG_BASE( wxWindow* parent, wxWind
this->Centre( wxBOTH ); this->Centre( wxBOTH );
// Connect Events // Connect Events
m_buttonAdd->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnAddRow ), NULL, this ); m_pathList->Connect( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, wxListEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnPathActivated ), NULL, this );
m_buttonDelete->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnDeleteSelectedRows ), NULL, this ); m_pathList->Connect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnPathSelected ), NULL, this );
m_sdbSizerHelp->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnHelpRequest ), NULL, this ); m_addPathButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnAddButton ), NULL, this );
m_editPathButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnEditButton ), NULL, this );
m_deletePathButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnRemoveButton ), NULL, this );
m_sdbSizerHelp->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnHelpButton ), NULL, this );
} }
DIALOG_ENV_VAR_CONFIG_BASE::~DIALOG_ENV_VAR_CONFIG_BASE() DIALOG_ENV_VAR_CONFIG_BASE::~DIALOG_ENV_VAR_CONFIG_BASE()
{ {
// Disconnect Events // Disconnect Events
m_buttonAdd->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnAddRow ), NULL, this ); m_pathList->Disconnect( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, wxListEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnPathActivated ), NULL, this );
m_buttonDelete->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnDeleteSelectedRows ), NULL, this ); m_pathList->Disconnect( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnPathSelected ), NULL, this );
m_sdbSizerHelp->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnHelpRequest ), NULL, this ); m_addPathButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnAddButton ), NULL, this );
m_editPathButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnEditButton ), NULL, this );
m_deletePathButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnRemoveButton ), NULL, this );
m_sdbSizerHelp->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_CONFIG_BASE::OnHelpButton ), NULL, this );
}
DIALOG_ENV_VAR_SINGLE_BASE::DIALOG_ENV_VAR_SINGLE_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* bSizerMain;
bSizerMain = new wxBoxSizer( wxVERTICAL );
wxFlexGridSizer* fgSizer1;
fgSizer1 = new wxFlexGridSizer( 0, 3, 0, 0 );
fgSizer1->AddGrowableCol( 1 );
fgSizer1->SetFlexibleDirection( wxBOTH );
fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_envVarNameLabel = new wxStaticText( this, wxID_ANY, _("Name"), wxDefaultPosition, wxDefaultSize, 0 );
m_envVarNameLabel->Wrap( -1 );
fgSizer1->Add( m_envVarNameLabel, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
m_envVarName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizer1->Add( m_envVarName, 0, wxALL|wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 );
m_buttonHelp = new wxButton( this, wxID_ANY, _("Help"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer1->Add( m_buttonHelp, 0, wxALL, 5 );
m_envVarPathLabel = new wxStaticText( this, wxID_ANY, _("Value"), wxDefaultPosition, wxDefaultSize, 0 );
m_envVarPathLabel->Wrap( -1 );
fgSizer1->Add( m_envVarPathLabel, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
m_envVarPath = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizer1->Add( m_envVarPath, 0, wxALL|wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 );
m_selectPathButton = new wxButton( this, wxID_ANY, _("Browse"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer1->Add( m_selectPathButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
bSizerMain->Add( fgSizer1, 0, wxEXPAND, 5 );
bSizerMain->Add( 0, 0, 1, wxEXPAND, 5 );
m_staticline2 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bSizerMain->Add( m_staticline2, 0, wxEXPAND | wxALL, 5 );
m_sdbSizer2 = new wxStdDialogButtonSizer();
m_sdbSizer2OK = new wxButton( this, wxID_OK );
m_sdbSizer2->AddButton( m_sdbSizer2OK );
m_sdbSizer2Cancel = new wxButton( this, wxID_CANCEL );
m_sdbSizer2->AddButton( m_sdbSizer2Cancel );
m_sdbSizer2->Realize();
bSizerMain->Add( m_sdbSizer2, 0, wxALIGN_RIGHT, 5 );
this->SetSizer( bSizerMain );
this->Layout();
this->Centre( wxBOTH );
// Connect Events
m_buttonHelp->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_SINGLE_BASE::onHelpClick ), NULL, this );
m_selectPathButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_SINGLE_BASE::OnSelectPath ), NULL, this );
}
DIALOG_ENV_VAR_SINGLE_BASE::~DIALOG_ENV_VAR_SINGLE_BASE()
{
// Disconnect Events
m_buttonHelp->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_SINGLE_BASE::onHelpClick ), NULL, this );
m_selectPathButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ENV_VAR_SINGLE_BASE::OnSelectPath ), NULL, this );
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 17 2015) // C++ code generated with wxFormBuilder (version Aug 4 2017)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
@ -14,19 +14,25 @@
class DIALOG_SHIM; class DIALOG_SHIM;
#include "dialog_shim.h" #include "dialog_shim.h"
#include <wx/listctrl.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h> #include <wx/colour.h>
#include <wx/settings.h> #include <wx/settings.h>
#include <wx/string.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/button.h>
#include <wx/sizer.h>
#include <wx/statbox.h>
#include <wx/statline.h> #include <wx/statline.h>
#include <wx/dialog.h> #include <wx/dialog.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
#define ID_BUTTON_ADD_PATH 1000
#define ID_BUTTON_EDIT_PATH 1001
#define ID_BUTTON_DELETE_PATH 1002
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/// Class DIALOG_ENV_VAR_CONFIG_BASE /// Class DIALOG_ENV_VAR_CONFIG_BASE
@ -36,9 +42,10 @@ class DIALOG_ENV_VAR_CONFIG_BASE : public DIALOG_SHIM
private: private:
protected: protected:
wxGrid* m_grid; wxListCtrl* m_pathList;
wxButton* m_buttonAdd; wxButton* m_addPathButton;
wxButton* m_buttonDelete; wxButton* m_editPathButton;
wxButton* m_deletePathButton;
wxStaticLine* m_staticline1; wxStaticLine* m_staticline1;
wxStdDialogButtonSizer* m_sdbSizer; wxStdDialogButtonSizer* m_sdbSizer;
wxButton* m_sdbSizerOK; wxButton* m_sdbSizerOK;
@ -46,16 +53,50 @@ class DIALOG_ENV_VAR_CONFIG_BASE : public DIALOG_SHIM
wxButton* m_sdbSizerHelp; wxButton* m_sdbSizerHelp;
// Virtual event handlers, overide them in your derived class // Virtual event handlers, overide them in your derived class
virtual void OnAddRow( wxCommandEvent& event ) { event.Skip(); } virtual void OnPathActivated( wxListEvent& event ) { event.Skip(); }
virtual void OnDeleteSelectedRows( wxCommandEvent& event ) { event.Skip(); } virtual void OnPathSelected( wxListEvent& event ) { event.Skip(); }
virtual void OnHelpRequest( wxCommandEvent& event ) { event.Skip(); } virtual void OnAddButton( wxCommandEvent& event ) { event.Skip(); }
virtual void OnEditButton( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRemoveButton( wxCommandEvent& event ) { event.Skip(); }
virtual void OnHelpButton( wxCommandEvent& event ) { event.Skip(); }
public: 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( 363,177 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); DIALOG_ENV_VAR_CONFIG_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Path Configuration"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 582,283 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_ENV_VAR_CONFIG_BASE(); ~DIALOG_ENV_VAR_CONFIG_BASE();
}; };
///////////////////////////////////////////////////////////////////////////////
/// Class DIALOG_ENV_VAR_SINGLE_BASE
///////////////////////////////////////////////////////////////////////////////
class DIALOG_ENV_VAR_SINGLE_BASE : public DIALOG_SHIM
{
private:
protected:
wxStaticText* m_envVarNameLabel;
wxTextCtrl* m_envVarName;
wxButton* m_buttonHelp;
wxStaticText* m_envVarPathLabel;
wxTextCtrl* m_envVarPath;
wxButton* m_selectPathButton;
wxStaticLine* m_staticline2;
wxStdDialogButtonSizer* m_sdbSizer2;
wxButton* m_sdbSizer2OK;
wxButton* m_sdbSizer2Cancel;
// Virtual event handlers, overide them in your derived class
virtual void onHelpClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnSelectPath( wxCommandEvent& event ) { event.Skip(); }
public:
DIALOG_ENV_VAR_SINGLE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Edit Environment Value Variable"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 439,141 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_ENV_VAR_SINGLE_BASE();
};
#endif //__DIALOG_ENV_VAR_CONFIG_BASE_H__ #endif //__DIALOG_ENV_VAR_CONFIG_BASE_H__

View File

@ -40,15 +40,53 @@ class DIALOG_ENV_VAR_CONFIG: public DIALOG_ENV_VAR_CONFIG_BASE
{ {
private: private:
ENV_VAR_MAP m_envVarMap; ENV_VAR_MAP m_envVarMap;
bool m_extDefsChanged; bool m_extDefsChanged = false;
protected: protected:
virtual void OnAddRow( wxCommandEvent& aEvent ) override;
virtual void OnDeleteSelectedRows( wxCommandEvent& aEvent ) override; /**
virtual void OnHelpRequest( wxCommandEvent& aEvent ) override; * Update the displayed list of ENV_VAR paths
*/
void PopulatePathList();
/**
* Edit the currently selected ENV_VAR entry
*/
void EditSelectedEntry();
// Various button callbacks
virtual void OnAddButton( wxCommandEvent& event ) override;
virtual void OnEditButton( wxCommandEvent& event ) override;
virtual void OnRemoveButton( wxCommandEvent& event ) override;
virtual void OnHelpButton( wxCommandEvent& event ) override;
virtual void OnPathSelected( wxListEvent& event ) override;
virtual void OnPathActivated( wxListEvent& event ) override;
// Variable for keeping track of currently selected list index
unsigned int m_pathIndex = 0;
/**
* Extract the NAME and PATH data from the ENV_VAR at the provided index
* @param aIndex is the index to extract data from
* @return true if data was extracted else false
*/
bool GetPathAtIndex( unsigned int aIndex, wxString& aEnvVar, wxString& aEnvPath );
/**
* Determine if a particular ENV_VAR is protected
* @param aEnvVar is the name of the ENV_VAR
*/
bool IsEnvVarImmutable( const wxString aEnvVar );
/**
* Select the ENV_VAR at the provided index
*/
void SelectListIndex( unsigned int aIndex );
public: public:
DIALOG_ENV_VAR_CONFIG( wxWindow* parent, const ENV_VAR_MAP& aEnvVarMap ); DIALOG_ENV_VAR_CONFIG( wxWindow* parent, const ENV_VAR_MAP& aEnvVarMap );
virtual ~DIALOG_ENV_VAR_CONFIG() {}
bool TransferDataToWindow() override; bool TransferDataToWindow() override;
bool TransferDataFromWindow() override; bool TransferDataFromWindow() override;