diff --git a/common/jobs/job_special_execute.h b/common/jobs/job_special_execute.h index 2114052e21..59b4ca1ae7 100644 --- a/common/jobs/job_special_execute.h +++ b/common/jobs/job_special_execute.h @@ -23,6 +23,8 @@ #include #include +#define OUTPUT_TMP_PATH_VAR_NAME wxT( "JOBSET_OUTPUT_TMP_PATH" ) + class KICOMMON_API JOB_SPECIAL_EXECUTE : public JOB { public: diff --git a/kicad/dialogs/dialog_executecommand_job_settings.cpp b/kicad/dialogs/dialog_executecommand_job_settings.cpp index 79e0a10494..d225e8eef3 100644 --- a/kicad/dialogs/dialog_executecommand_job_settings.cpp +++ b/kicad/dialogs/dialog_executecommand_job_settings.cpp @@ -18,10 +18,14 @@ * with this program. If not, see . */ +#include "widgets/grid_readonly_text_helpers.h" #include #include #include +#include +#include #include +#include DIALOG_EXECUTECOMMAND_JOB_SETTINGS::DIALOG_EXECUTECOMMAND_JOB_SETTINGS( wxWindow* aParent, @@ -45,9 +49,18 @@ DIALOG_EXECUTECOMMAND_JOB_SETTINGS::DIALOG_EXECUTECOMMAND_JOB_SETTINGS( wxWindow []( const wxString& xRef, wxArrayString* tokens ) { ENV_VAR::GetEnvVarAutocompleteTokens( tokens ); + tokens->Add( OUTPUT_TMP_PATH_VAR_NAME ); } ); } ); + // add Cut, Copy, and Paste to wxGrids + m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) ); + + populateEnvironReadOnlyTable(); + + m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) ); + m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) ); + SetupStandardButtons(); finishDialogSettings(); @@ -57,6 +70,9 @@ DIALOG_EXECUTECOMMAND_JOB_SETTINGS::DIALOG_EXECUTECOMMAND_JOB_SETTINGS( wxWindow DIALOG_EXECUTECOMMAND_JOB_SETTINGS::~DIALOG_EXECUTECOMMAND_JOB_SETTINGS() { delete m_scintillaTricks; + + // Delete the GRID_TRICKS. + m_path_subs_grid->PopEventHandler( true ); } @@ -87,4 +103,87 @@ bool DIALOG_EXECUTECOMMAND_JOB_SETTINGS::TransferDataToWindow() void DIALOG_EXECUTECOMMAND_JOB_SETTINGS::OnRecordOutputClicked( wxCommandEvent& aEvent ) { m_textCtrlOutputPath->Enable( m_cbRecordOutput->GetValue() ); -} \ No newline at end of file +} + + +void DIALOG_EXECUTECOMMAND_JOB_SETTINGS::populateEnvironReadOnlyTable() +{ + wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED ); + wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required. + + std::set unique; + wxString src = m_textCtrlCommand->GetValue(); + + // clear the table + m_path_subs_grid->ClearRows(); + + while( re.Matches( src ) ) + { + wxString envvar = re.GetMatch( src, 2 ); + + // if not ${...} form then must be $(...) + if( envvar.IsEmpty() ) + envvar = re.GetMatch( src, 4 ); + + // ignore duplicates + unique.insert( envvar ); + + // delete the last match and search again + src.Replace( re.GetMatch( src, 0 ), wxEmptyString ); + } + + // Make sure these variables shows up even if not used yet. + unique.insert( OUTPUT_TMP_PATH_VAR_NAME ); + unique.insert( PROJECT_VAR_NAME ); + + for( const wxString& evName : unique ) + { + int row = m_path_subs_grid->GetNumberRows(); + m_path_subs_grid->AppendRows( 1 ); + + m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) ); + m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() ); + + wxString evValue; + + if( evName.IsSameAs( OUTPUT_TMP_PATH_VAR_NAME ) ) + { + evValue = _( "" ); + m_path_subs_grid->SetCellFont( row, 1, m_path_subs_grid->GetCellFont( row, 1 ).Italic() ); + } + else + { + wxGetEnv( evName, &evValue ); + } + + m_path_subs_grid->SetCellValue( row, 1, evValue ); + m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() ); + } + + // No combobox editors here, but it looks better if its consistent with the other + // grids in the dialog. + m_path_subs_grid->SetDefaultRowSize( m_path_subs_grid->GetDefaultRowSize() + 2 ); + + adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() ); +} + + +void DIALOG_EXECUTECOMMAND_JOB_SETTINGS::adjustPathSubsGridColumns( int aWidth ) +{ + // Account for scroll bars + aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x ); + + m_path_subs_grid->AutoSizeColumn( 0 ); + m_path_subs_grid->SetColSize( 0, std::max( 200, m_path_subs_grid->GetColSize( 0 ) ) ); + m_path_subs_grid->SetColSize( 1, std::max( 300, aWidth - m_path_subs_grid->GetColSize( 0 ) ) ); +} + + +void DIALOG_EXECUTECOMMAND_JOB_SETTINGS::onSizeGrid( wxSizeEvent& event ) +{ + adjustPathSubsGridColumns( event.GetSize().GetX() ); + + event.Skip(); +} + + diff --git a/kicad/dialogs/dialog_executecommand_job_settings.h b/kicad/dialogs/dialog_executecommand_job_settings.h index f696b8755e..3f1779eb37 100644 --- a/kicad/dialogs/dialog_executecommand_job_settings.h +++ b/kicad/dialogs/dialog_executecommand_job_settings.h @@ -34,8 +34,14 @@ public: bool TransferDataToWindow() override; private: + void onSizeGrid( wxSizeEvent& event ) override; + void adjustPathSubsGridColumns( int aWidth ); void OnRecordOutputClicked( wxCommandEvent& event ) override; + /// Populate the readonly environment variable table with names and values + /// by examining the script and path. + void populateEnvironReadOnlyTable(); + private: JOB_SPECIAL_EXECUTE* m_job; diff --git a/kicad/dialogs/dialog_executecommand_job_settings_base.cpp b/kicad/dialogs/dialog_executecommand_job_settings_base.cpp index d5068cb40c..9ee7cd000c 100644 --- a/kicad/dialogs/dialog_executecommand_job_settings_base.cpp +++ b/kicad/dialogs/dialog_executecommand_job_settings_base.cpp @@ -5,6 +5,8 @@ // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// +#include "widgets/wx_grid.h" + #include "dialog_executecommand_job_settings_base.h" /////////////////////////////////////////////////////////////////////////// @@ -83,6 +85,48 @@ DIALOG_EXECUTECOMMAND_JOB_SETTINGS_BASE::DIALOG_EXECUTECOMMAND_JOB_SETTINGS_BASE bSizerMain->Add( bSizerBottom, 0, wxALL|wxEXPAND, 5 ); + + bSizerMain->Add( 0, 10, 0, wxEXPAND, 5 ); + + wxStaticText* stPathsLabel; + stPathsLabel = new wxStaticText( this, wxID_ANY, _("Available text variables:"), wxDefaultPosition, wxDefaultSize, 0 ); + stPathsLabel->Wrap( -1 ); + bSizerMain->Add( stPathsLabel, 0, wxTOP|wxRIGHT|wxLEFT, 10 ); + + + bSizerMain->Add( 0, 2, 0, wxEXPAND, 5 ); + + m_path_subs_grid = new WX_GRID( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + + // Grid + m_path_subs_grid->CreateGrid( 1, 2 ); + m_path_subs_grid->EnableEditing( false ); + m_path_subs_grid->EnableGridLines( true ); + m_path_subs_grid->EnableDragGridSize( false ); + m_path_subs_grid->SetMargins( 0, 0 ); + + // Columns + m_path_subs_grid->SetColSize( 0, 200 ); + m_path_subs_grid->SetColSize( 1, 300 ); + m_path_subs_grid->AutoSizeColumns(); + m_path_subs_grid->EnableDragColMove( false ); + m_path_subs_grid->EnableDragColSize( true ); + m_path_subs_grid->SetColLabelSize( 0 ); + m_path_subs_grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); + + // Rows + m_path_subs_grid->EnableDragRowSize( true ); + m_path_subs_grid->SetRowLabelSize( 0 ); + m_path_subs_grid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); + + // Label Appearance + + // Cell Defaults + m_path_subs_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_CENTER ); + m_path_subs_grid->SetToolTip( _("This is a read-only table which shows pertinent environment variables.") ); + + bSizerMain->Add( m_path_subs_grid, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 10 ); + m_sdbSizer1 = new wxStdDialogButtonSizer(); m_sdbSizer1OK = new wxButton( this, wxID_OK ); m_sdbSizer1->AddButton( m_sdbSizer1OK ); @@ -90,7 +134,7 @@ DIALOG_EXECUTECOMMAND_JOB_SETTINGS_BASE::DIALOG_EXECUTECOMMAND_JOB_SETTINGS_BASE m_sdbSizer1->AddButton( m_sdbSizer1Cancel ); m_sdbSizer1->Realize(); - bSizerMain->Add( m_sdbSizer1, 0, wxALL|wxEXPAND, 5 ); + bSizerMain->Add( m_sdbSizer1, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); this->SetSizer( bSizerMain ); @@ -101,11 +145,13 @@ DIALOG_EXECUTECOMMAND_JOB_SETTINGS_BASE::DIALOG_EXECUTECOMMAND_JOB_SETTINGS_BASE // Connect Events m_cbRecordOutput->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_EXECUTECOMMAND_JOB_SETTINGS_BASE::OnRecordOutputClicked ), NULL, this ); + m_path_subs_grid->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_EXECUTECOMMAND_JOB_SETTINGS_BASE::onSizeGrid ), NULL, this ); } DIALOG_EXECUTECOMMAND_JOB_SETTINGS_BASE::~DIALOG_EXECUTECOMMAND_JOB_SETTINGS_BASE() { // Disconnect Events m_cbRecordOutput->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_EXECUTECOMMAND_JOB_SETTINGS_BASE::OnRecordOutputClicked ), NULL, this ); + m_path_subs_grid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_EXECUTECOMMAND_JOB_SETTINGS_BASE::onSizeGrid ), NULL, this ); } diff --git a/kicad/dialogs/dialog_executecommand_job_settings_base.fbp b/kicad/dialogs/dialog_executecommand_job_settings_base.fbp index 92fa5f9449..9bedbf0225 100644 --- a/kicad/dialogs/dialog_executecommand_job_settings_base.fbp +++ b/kicad/dialogs/dialog_executecommand_job_settings_base.fbp @@ -481,9 +481,181 @@ + + 5 + wxEXPAND + 0 + + 10 + protected + 0 + + + + 10 + wxTOP|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + 0 + + 0 + 0 + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + Available text variables: + 0 + + 0 + + + 0 + + 1 + stPathsLabel + 1 + + + none + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxEXPAND + 0 + + 2 + protected + 0 + + + + 10 + wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + 0 + + 0 + 0 + 1 + 0 + + + + 1 + + + wxALIGN_LEFT + + wxALIGN_CENTER + 0 + 1 + wxALIGN_CENTER + 0 + + wxALIGN_CENTER + 2 + 200,300 + + 1 + 0 + Dock + 0 + Left + 0 + 0 + 1 + 0 + 1 + 0 + 1 + + 1 + + + 1 + 0 + 0 + wxID_ANY + + + + 0 + 0 + + 0 + + + 0 + + 1 + m_path_subs_grid + 1 + + + protected + 1 + + Resizable + wxALIGN_CENTER + 0 + + wxALIGN_CENTER + + 1 + 1 + + WX_GRID; widgets/wx_grid.h; forward_declare + 0 + This is a read-only table which shows pertinent environment variables. + + + + onSizeGrid + + 5 - wxALL|wxEXPAND + wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT 0 0 diff --git a/kicad/dialogs/dialog_executecommand_job_settings_base.h b/kicad/dialogs/dialog_executecommand_job_settings_base.h index accf922c5c..9369bca4c4 100644 --- a/kicad/dialogs/dialog_executecommand_job_settings_base.h +++ b/kicad/dialogs/dialog_executecommand_job_settings_base.h @@ -10,6 +10,8 @@ #include #include #include +class WX_GRID; + #include "dialog_shim.h" #include #include @@ -21,6 +23,7 @@ #include #include #include +#include #include #include @@ -40,12 +43,14 @@ class DIALOG_EXECUTECOMMAND_JOB_SETTINGS_BASE : public DIALOG_SHIM wxTextCtrl* m_textCtrlOutputPath; wxCheckBox* m_cbRecordOutput; wxCheckBox* m_cbIgnoreExitCode; + WX_GRID* m_path_subs_grid; wxStdDialogButtonSizer* m_sdbSizer1; wxButton* m_sdbSizer1OK; wxButton* m_sdbSizer1Cancel; // Virtual event handlers, override them in your derived class virtual void OnRecordOutputClicked( wxCommandEvent& event ) { event.Skip(); } + virtual void onSizeGrid( wxSizeEvent& event ) { event.Skip(); } public: diff --git a/kicad/jobs_runner.cpp b/kicad/jobs_runner.cpp index 27ce722f17..84924cc34d 100644 --- a/kicad/jobs_runner.cpp +++ b/kicad/jobs_runner.cpp @@ -242,7 +242,7 @@ bool JOBS_RUNNER::RunJobsForDestination( JOBSET_DESTINATION* aDestination, bool int failCount = 0; int successCount = 0; - wxSetEnv( "JOBSET_OUTPUT_TMP_PATH", tempDirPath ); + wxSetEnv( OUTPUT_TMP_PATH_VAR_NAME, tempDirPath ); for( const JOBSET_JOB& job : jobsForDestination ) {