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_scintillaTricks = new SCINTILLA_TRICKS( m_textCtrlCommand, wxT( "{}" ), false,
38 // onAcceptFn
39 [this]( wxKeyEvent& aEvent )
40 {
41 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
42 },
43
44 // onCharFn
45 [this]( wxStyledTextEvent& aEvent )
46 {
48 // getTokensFn
49 []( const wxString& xRef, wxArrayString* tokens )
50 {
52 tokens->Add( OUTPUT_TMP_PATH_VAR_NAME );
53 } );
54 } );
55
56 // add Cut, Copy, and Paste to wxGrids
57 m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) );
58
60
61 m_path_subs_grid->SetColLabelValue( 0, _( "Name" ) );
62 m_path_subs_grid->SetColLabelValue( 1, _( "Value" ) );
63
65
67}
68
69
71{
72 delete m_scintillaTricks;
73
74 // Delete the GRID_TRICKS.
75 m_path_subs_grid->PopEventHandler( true );
76}
77
78
80{
81 m_job->m_command = m_textCtrlCommand->GetValue();
85
86 return true;
87}
88
89
91{
92 m_textCtrlCommand->SetValue( m_job->m_command );
95
97 m_textCtrlOutputPath->Enable( m_cbRecordOutput->GetValue() );
98
99 return true;
100}
101
102
104{
105 m_textCtrlOutputPath->Enable( m_cbRecordOutput->GetValue() );
106}
107
108
110{
111 wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
112 wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required.
113
114 std::set<wxString> unique;
115 wxString src = m_textCtrlCommand->GetValue();
116
117 // clear the table
119
120 while( re.Matches( src ) )
121 {
122 wxString envvar = re.GetMatch( src, 2 );
123
124 // if not ${...} form then must be $(...)
125 if( envvar.IsEmpty() )
126 envvar = re.GetMatch( src, 4 );
127
128 // ignore duplicates
129 unique.insert( envvar );
130
131 // delete the last match and search again
132 src.Replace( re.GetMatch( src, 0 ), wxEmptyString );
133 }
134
135 // Make sure these variables shows up even if not used yet.
136 unique.insert( OUTPUT_TMP_PATH_VAR_NAME );
137 unique.insert( PROJECT_VAR_NAME );
138
139 for( const wxString& evName : unique )
140 {
141 int row = m_path_subs_grid->GetNumberRows();
142 m_path_subs_grid->AppendRows( 1 );
143
144 m_path_subs_grid->SetCellValue( row, 0, wxT( "${" ) + evName + wxT( "}" ) );
145 m_path_subs_grid->SetCellEditor( row, 0, new GRID_CELL_READONLY_TEXT_EDITOR() );
146
147 wxString evValue;
148
149 if( evName.IsSameAs( OUTPUT_TMP_PATH_VAR_NAME ) )
150 {
151 evValue = _( "<value set at runtime>" );
152 m_path_subs_grid->SetCellFont( row, 1, m_path_subs_grid->GetCellFont( row, 1 ).Italic() );
153 }
154 else
155 {
156 wxGetEnv( evName, &evValue );
157 }
158
159 m_path_subs_grid->SetCellValue( row, 1, evValue );
160 m_path_subs_grid->SetCellEditor( row, 1, new GRID_CELL_READONLY_TEXT_EDITOR() );
161 }
162
163 adjustPathSubsGridColumns( m_path_subs_grid->GetRect().GetWidth() );
164}
165
166
168{
169 // Account for scroll bars
170 aWidth -= ( m_path_subs_grid->GetSize().x - m_path_subs_grid->GetClientSize().x );
171
172 m_path_subs_grid->AutoSizeColumn( 0 );
173 m_path_subs_grid->SetColSize( 0, std::max( 200, m_path_subs_grid->GetColSize( 0 ) ) );
174 m_path_subs_grid->SetColSize( 1, std::max( 300, aWidth - m_path_subs_grid->GetColSize( 0 ) ) );
175}
176
177
179{
180 adjustPathSubsGridColumns( event.GetSize().GetX() );
181
182 event.Skip();
183}
184
185
Class DIALOG_EXECUTECOMMAND_JOB_SETTINGS_BASE.
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
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
Definition: job.cpp:153
wxString GetConfiguredOutputPath() const
Returns the configured output path for the job.
Definition: job.h:232
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
void DoTextVarAutocomplete(const std::function< void(const wxString &xRef, wxArrayString *tokens)> &getTokensFn)
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:220
#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