KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_executecommand_job_settings.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2024 Mark Roszko <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
24#include <scintilla_tricks.h>
25#include <grid_tricks.h>
26#include <project.h>
27#include <env_vars.h>
28#include <wx/regex.h>
29
30
32 JOB_SPECIAL_EXECUTE* aJob ) :
34 m_job( aJob ),
35 m_scintillaTricks( nullptr )
36{
37 m_textCtrlCommand->SetWrapMode( wxSTC_WRAP_CHAR );
38
39 m_scintillaTricks = new SCINTILLA_TRICKS( m_textCtrlCommand, wxT( "{}" ), false,
40 // onAcceptFn
41 [this]( wxKeyEvent& aEvent )
42 {
43 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
44 },
45
46 // onCharFn
47 [this]( wxStyledTextEvent& aEvent )
48 {
49 m_scintillaTricks->DoTextVarAutocomplete(
50 // getTokensFn
51 []( const wxString& xRef, wxArrayString* tokens )
52 {
54 tokens->Add( OUTPUT_TMP_PATH_VAR_NAME );
55 } );
56 } );
57
58 // add Cut, Copy, and Paste to wxGrids
59 m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) );
60
62
63 m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) );
64 m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) );
65
67
69}
70
71
73{
74 delete m_scintillaTricks;
75 m_scintillaTricks = nullptr;
76
77 // Delete the GRID_TRICKS.
78 m_path_subs_grid->PopEventHandler( true );
79}
80
81
83{
84 m_job->m_command = m_textCtrlCommand->GetValue();
85 m_job->m_ignoreExitcode = m_cbIgnoreExitCode->GetValue();
86 m_job->m_recordOutput = m_cbRecordOutput->GetValue();
87 m_job->SetConfiguredOutputPath( m_textCtrlOutputPath->GetValue() );
88
89 return true;
90}
91
92
94{
95 m_textCtrlCommand->SetValue( m_job->m_command );
96 m_cbIgnoreExitCode->SetValue( m_job->m_ignoreExitcode );
97 m_cbRecordOutput->SetValue( m_job->m_recordOutput );
98
99 m_textCtrlOutputPath->SetValue( m_job->GetConfiguredOutputPath() );
100 m_textCtrlOutputPath->Enable( m_cbRecordOutput->GetValue() );
101
102 return true;
103}
104
105
107{
108 m_textCtrlOutputPath->Enable( m_cbRecordOutput->GetValue() );
109}
110
111
113{
114 wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
115 wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
116
117 std::set<wxString> unique;
118 wxString src = m_textCtrlCommand->GetValue();
119
120 // clear the table
121 m_path_subs_grid->ClearRows();
122
123 while( re.Matches( src ) )
124 {
125 wxString envvar = re.GetMatch( src, 2 );
126
127 // if not ${...} form then must be $(...)
128 if( envvar.IsEmpty() )
129 envvar = re.GetMatch( src, 4 );
130
131 // ignore duplicates
132 unique.insert( envvar );
133
134 // delete the last match and search again
135 src.Replace( re.GetMatch( src, 0 ), wxEmptyString );
136 }
137
138 // Make sure these variables shows up even if not used yet.
139 unique.insert( OUTPUT_TMP_PATH_VAR_NAME );
140 unique.insert( PROJECT_VAR_NAME );
141
142 for( const wxString& evName : unique )
143 {
144 int row = m_path_subs_grid->GetNumberRows();
145 m_path_subs_grid->AppendRows( 1 );
146
147 m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
148 m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
149
150 wxString evValue;
151
152 if( evName.IsSameAs( OUTPUT_TMP_PATH_VAR_NAME ) )
153 {
154 evValue = _( "<value set at runtime>" );
155 m_path_subs_grid->SetCellFont( row, 1, m_path_subs_grid->GetCellFont( row, 1 ).Italic() );
156 }
157 else
158 {
159 wxGetEnv( evName, &evValue );
160 }
161
162 m_path_subs_grid->SetCellValue( row, 1, evValue );
163 m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
164 }
165
166 adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
167}
168
169
171{
172 // Account for scroll bars
173 aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
174
175 m_path_subs_grid->AutoSizeColumn( 0 );
176 m_path_subs_grid->SetColSize( 0, std::max( 200, m_path_subs_grid->GetColSize( 0 ) ) );
177 m_path_subs_grid->SetColSize( 1, std::max( 300, aWidth - m_path_subs_grid->GetColSize( 0 ) ) );
178}
179
180
182{
183 adjustPathSubsGridColumns( event.GetSize().GetX() );
184
185 event.Skip();
186}
187
188
DIALOG_EXECUTECOMMAND_JOB_SETTINGS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Execute Command Job Settings"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void populateEnvironReadOnlyTable()
Populate the readonly environment variable table with names and values by examining the script and pa...
DIALOG_EXECUTECOMMAND_JOB_SETTINGS(wxWindow *aParent, JOB_SPECIAL_EXECUTE *aJob)
void OnRecordOutputClicked(wxCommandEvent &event) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition grid_tricks.h:61
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
#define _(s)
Functions related to environment variables, including help functions.
#define OUTPUT_TMP_PATH_VAR_NAME
KICOMMON_API void GetEnvVarAutocompleteTokens(wxArrayString *aVars)
Return autocomplete tokens for environment variables for Scintilla.
Definition env_vars.cpp:67
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition project.h:41