Skip to content

Commit 47b0549

Browse files
committed
Add Optional Environment In Builtin Terminal Pane
Update the built-in terminal creation path to pass an explicit optional environment list, keeping the default behavior of inheriting the parent process environment while aligning the terminal constructor call with the updated submodule API. Also apply style and formatting cleanup in the environment variables dialog to keep the codebase consistent. * Builtin terminal * Environment variables dialog **Generated by CodeLite** Signed-off-by: Eran Ifrah <eran@codelite.org>
1 parent d78a046 commit 47b0549

File tree

3 files changed

+39
-29
lines changed

3 files changed

+39
-29
lines changed

Plugin/EnvironmentVariablesDlg.cpp

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ EnvironmentVariablesDlg::EnvironmentVariablesDlg(wxWindow* parent)
3030

3131
wxStyledTextCtrl* sci = m_textCtrlDefault;
3232
LexerConf::Ptr_t lexer = ColoursAndFontsManager::Get().GetLexer("text");
33-
if(lexer) {
33+
if (lexer) {
3434
lexer->Apply(sci);
3535
}
3636

@@ -47,14 +47,14 @@ EnvironmentVariablesDlg::EnvironmentVariablesDlg(wxWindow* parent)
4747
}
4848

4949
m_book->SetSelection(0);
50-
for(size_t i = 0; i < m_book->GetPageCount(); i++) {
51-
if(m_book->GetPageText(i) == activePage) {
50+
for (size_t i = 0; i < m_book->GetPageCount(); i++) {
51+
if (m_book->GetPageText(i) == activePage) {
5252
m_book->GetPage(i)->SetFocus();
5353
m_book->SetSelection(i);
5454
}
5555
wxWindow* page = m_book->GetPage(i);
5656
wxStyledTextCtrl* ctrl = dynamic_cast<wxStyledTextCtrl*>(page);
57-
if(ctrl) {
57+
if (ctrl) {
5858
ctrl->SetSavePoint();
5959
ctrl->EmptyUndoBuffer();
6060
}
@@ -68,7 +68,7 @@ void EnvironmentVariablesDlg::DoAddPage(const wxString& name, const wxString& co
6868
{
6969
wxStyledTextCtrl* page = new wxStyledTextCtrl(m_book, wxID_ANY, wxDefaultPosition, wxSize(0, 0));
7070
LexerConf::Ptr_t lexer = ColoursAndFontsManager::Get().GetLexer("text");
71-
if(lexer) {
71+
if (lexer) {
7272
lexer->Apply(page);
7373
}
7474

@@ -83,14 +83,15 @@ void EnvironmentVariablesDlg::OnButtonOk(wxCommandEvent& event)
8383
wxStringMap_t envSets;
8484
envSets[wxT("Default")] = m_textCtrlDefault->GetText().Trim().Trim(false);
8585

86-
for(size_t i = 1; i < m_book->GetPageCount(); i++) {
87-
if(i == (size_t)m_book->GetSelection()) {
86+
for (size_t i = 1; i < m_book->GetPageCount(); i++) {
87+
if (i == (size_t)m_book->GetSelection()) {
8888
vars.SetActiveSet(m_book->GetPageText(i));
8989
}
9090

9191
const wxStyledTextCtrl* page = (wxStyledTextCtrl*)m_book->GetPage(i);
9292
envSets[m_book->GetPageText(i)] = page->GetText().Trim().Trim(false);
9393
}
94+
9495
vars.SetEnvVarSets(envSets);
9596
EnvironmentConfig::Instance()->WriteObject(wxT("Variables"), &vars);
9697

@@ -105,12 +106,14 @@ void EnvironmentVariablesDlg::OnDeleteSet(wxCommandEvent& event)
105106
wxUnusedVar(event);
106107

107108
int selection = m_book->GetSelection();
108-
if(selection == wxNOT_FOUND)
109+
if (selection == wxNOT_FOUND)
109110
return;
110111

111112
wxString name = m_book->GetPageText((size_t)selection);
112-
if(wxMessageBox(wxString::Format(_("Delete environment variables set\n'%s' ?"), name.c_str()), _("Confirm"),
113-
wxYES_NO | wxICON_QUESTION, this) != wxYES)
113+
if (wxMessageBox(wxString::Format(_("Delete environment variables set\n'%s' ?"), name.c_str()),
114+
_("Confirm"),
115+
wxYES_NO | wxICON_QUESTION,
116+
this) != wxYES)
114117
return;
115118
m_book->DeletePage((size_t)selection);
116119
}
@@ -124,7 +127,7 @@ void EnvironmentVariablesDlg::OnDeleteSetUI(wxUpdateUIEvent& event)
124127
void EnvironmentVariablesDlg::OnExport(wxCommandEvent& event)
125128
{
126129
int selection = m_book->GetSelection();
127-
if(selection == wxNOT_FOUND)
130+
if (selection == wxNOT_FOUND)
128131
return;
129132

130133
#ifdef __WXMSW__
@@ -134,43 +137,45 @@ void EnvironmentVariablesDlg::OnExport(wxCommandEvent& event)
134137
#endif
135138

136139
wxString text;
137-
if(selection == 0) {
140+
if (selection == 0) {
138141
text = m_textCtrlDefault->GetText();
139142
} else {
140143
wxStyledTextCtrl* page = dynamic_cast<wxStyledTextCtrl*>(m_book->GetPage((size_t)selection));
141-
if(page) {
144+
if (page) {
142145
text = page->GetText();
143146
}
144147
}
145148

146-
if(text.IsEmpty())
149+
if (text.IsEmpty())
147150
return;
148151

149152
wxArrayString lines = wxStringTokenize(text, wxT("\r\n"), wxTOKEN_STRTOK);
150153
wxString envfile;
151-
if(isWindows) {
154+
if (isWindows) {
152155
envfile << wxT("environment.bat");
153156
} else {
154157
envfile << wxT("environment");
155158
}
156159

157160
wxFileName fn(wxGetCwd(), envfile);
158161
wxFFile fp(fn.GetFullPath(), wxT("w+b"));
159-
if(fp.IsOpened() == false) {
162+
if (fp.IsOpened() == false) {
160163
wxMessageBox(wxString::Format(_("Failed to open file: '%s' for write"), fn.GetFullPath().c_str()),
161-
wxT("CodeLite"), wxOK | wxCENTER | wxICON_WARNING, this);
164+
wxT("CodeLite"),
165+
wxOK | wxCENTER | wxICON_WARNING,
166+
this);
162167
return;
163168
}
164169

165-
for(size_t i = 0; i < lines.GetCount(); i++) {
170+
for (size_t i = 0; i < lines.GetCount(); i++) {
166171

167172
wxString sLine = lines.Item(i).Trim().Trim(false);
168-
if(sLine.IsEmpty())
173+
if (sLine.IsEmpty())
169174
continue;
170175

171176
static wxRegEx reVarPattern(wxT("\\$\\(( *)([a-zA-Z0-9_]+)( *)\\)"));
172-
if(isWindows) {
173-
while(reVarPattern.Matches(sLine)) {
177+
if (isWindows) {
178+
while (reVarPattern.Matches(sLine)) {
174179
wxString varName = reVarPattern.GetMatch(sLine, 2);
175180
wxString match = reVarPattern.GetMatch(sLine);
176181
sLine.Replace(match, wxString::Format(wxT("%%%s%%"), varName.c_str()));
@@ -179,7 +184,7 @@ void EnvironmentVariablesDlg::OnExport(wxCommandEvent& event)
179184
sLine.Append(wxT("\r\n"));
180185

181186
} else {
182-
while(reVarPattern.Matches(sLine)) {
187+
while (reVarPattern.Matches(sLine)) {
183188
wxString varName = reVarPattern.GetMatch(sLine, 2);
184189
wxString match = reVarPattern.GetMatch(sLine);
185190
sLine.Replace(match, wxString::Format(wxT("$%s"), varName.c_str()));
@@ -190,8 +195,10 @@ void EnvironmentVariablesDlg::OnExport(wxCommandEvent& event)
190195
fp.Write(sLine);
191196
}
192197

193-
wxMessageBox(wxString::Format(_("Environment exported to: '%s' successfully"), fn.GetFullPath()), wxT("CodeLite"),
194-
wxOK | wxCENTRE, this);
198+
wxMessageBox(wxString::Format(_("Environment exported to: '%s' successfully"), fn.GetFullPath()),
199+
wxT("CodeLite"),
200+
wxOK | wxCENTRE,
201+
this);
195202
}
196203

197204
void EnvironmentVariablesDlg::OnNewSet(wxCommandEvent& event) { CallAfter(&EnvironmentVariablesDlg::DoAddNewSet); }
@@ -207,9 +214,9 @@ void EnvironmentVariablesDlg::OnCancel(wxCommandEvent& event)
207214
void EnvironmentVariablesDlg::DoAddNewSet()
208215
{
209216
wxTextEntryDialog dlg(this, _("Name:"), wxT("Create a new set"), "My New Set");
210-
if(dlg.ShowModal() == wxID_OK) {
217+
if (dlg.ShowModal() == wxID_OK) {
211218
wxString name = dlg.GetValue();
212-
if(name.IsEmpty())
219+
if (name.IsEmpty())
213220
return;
214221
DoAddPage(name, wxT(""), false);
215222
}

Plugin/wxTerminalCtrl/clBuiltinTerminalPane.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ void clBuiltinTerminalPane::OnNew(wxCommandEvent& event)
112112
wxStringClientData* cd = dynamic_cast<wxStringClientData*>(m_terminal_types->GetClientObject(selection));
113113
const wxString& cmd = cd->GetData();
114114

115-
EnvSetter env;
116-
TerminalView* ctrl = new TerminalView(m_book, cmd);
115+
// By default, inherit parent's env.
116+
EnvSetter env_setter{};
117+
std::optional<TerminalView::EnvironmentList> env{std::nullopt};
118+
119+
TerminalView* ctrl = new TerminalView(m_book, cmd, env);
117120
m_book->AddPage(ctrl, cmd, true);
118121
m_book->SetPageToolTip(m_book->GetPageCount() - 1, cmd);
119122

0 commit comments

Comments
 (0)