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
76 // Delete the GRID_TRICKS.
77 m_path_subs_grid->PopEventHandler( true );
78}
79
80
82{
83 m_job->m_command = m_textCtrlCommand->GetValue();
84 m_job->m_ignoreExitcode = m_cbIgnoreExitCode->GetValue();
85 m_job->m_recordOutput = m_cbRecordOutput->GetValue();
86 m_job->SetConfiguredOutputPath( m_textCtrlOutputPath->GetValue() );
87
88 return true;
89}
90
91
93{
94 m_textCtrlCommand->SetValue( m_job->m_command );
95 m_cbIgnoreExitCode->SetValue( m_job->m_ignoreExitcode );
96 m_cbRecordOutput->SetValue( m_job->m_recordOutput );
97
98 m_textCtrlOutputPath->SetValue( m_job->GetConfiguredOutputPath() );
99 m_textCtrlOutputPath->Enable( m_cbRecordOutput->GetValue() );
100
101 return true;
102}
103
104
106{
107 m_textCtrlOutputPath->Enable( m_cbRecordOutput->GetValue() );
108}
109
110
112{
113 wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
114 wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
115
116 std::set<wxString> unique;
117 wxString src = m_textCtrlCommand->GetValue();
118
119 // clear the table
120 m_path_subs_grid->ClearRows();
121
122 while( re.Matches( src ) )
123 {
124 wxString envvar = re.GetMatch( src, 2 );
125
126 // if not ${...} form then must be $(...)
127 if( envvar.IsEmpty() )
128 envvar = re.GetMatch( src, 4 );
129
130 // ignore duplicates
131 unique.insert( envvar );
132
133 // delete the last match and search again
134 src.Replace( re.GetMatch( src, 0 ), wxEmptyString );
135 }
136
137 // Make sure these variables shows up even if not used yet.
138 unique.insert( OUTPUT_TMP_PATH_VAR_NAME );
139 unique.insert( PROJECT_VAR_NAME );
140
141 for( const wxString& evName : unique )
142 {
143 int row = m_path_subs_grid->GetNumberRows();
144 m_path_subs_grid->AppendRows( 1 );
145
146 m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
147 m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
148
149 wxString evValue;
150
151 if( evName.IsSameAs( OUTPUT_TMP_PATH_VAR_NAME ) )
152 {
153 evValue = _( "<value set at runtime>" );
154 m_path_subs_grid->SetCellFont( row, 1, m_path_subs_grid->GetCellFont( row, 1 ).Italic() );
155 }
156 else
157 {
158 wxGetEnv( evName, &evValue );
159 }
160
161 m_path_subs_grid->SetCellValue( row, 1, evValue );
162 m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
163 }
164
165 adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
166}
167
168
170{
171 // Account for scroll bars
172 aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
173
174 m_path_subs_grid->AutoSizeColumn( 0 );
175 m_path_subs_grid->SetColSize( 0, std::max( 200, m_path_subs_grid->GetColSize( 0 ) ) );
176 m_path_subs_grid->SetColSize( 1, std::max( 300, aWidth - m_path_subs_grid->GetColSize( 0 ) ) );
177}
178
179
181{
182 adjustPathSubsGridColumns( event.GetSize().GetX() );
183
184 event.Skip();
185}
186
187
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:40