File: FSConfigPage.cpp

package info (click to toggle)
codelite 17.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 136,204 kB
  • sloc: cpp: 491,547; ansic: 280,393; php: 10,259; sh: 8,930; lisp: 7,664; vhdl: 6,518; python: 6,020; lex: 4,920; yacc: 3,123; perl: 2,385; javascript: 1,715; cs: 1,193; xml: 1,110; makefile: 804; cobol: 741; sql: 709; ruby: 620; f90: 566; ada: 534; asm: 464; fortran: 350; objc: 289; tcl: 258; java: 157; erlang: 61; pascal: 51; ml: 49; awk: 44; haskell: 36
file content (334 lines) | stat: -rw-r--r-- 10,908 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#include "FSConfigPage.h"

#include "BuildTargetDlg.h"
#include "ColoursAndFontsManager.h"
#include "CompileCommandsGenerator.h"
#include "EditDlg.h"
#include "StringUtils.h"
#include "build_settings_config.h"
#include "clFileSystemWorkspace.hpp"
#include "debuggermanager.h"
#include "event_notifier.h"
#include "file_logger.h"
#include "fileextmanager.h"
#include "fileutils.h"
#include "globals.h"
#include "macromanager.h"
#include "macros.h"

#include <wx/msgdlg.h>
#include <wx/tokenzr.h>

#if USE_SFTP
#include "SFTPBrowserDlg.h"
#include "SSHAccountManagerDlg.h"
#include "sftp_settings.h"
#endif

#define OPEN_SSH_ACCOUNT_MANAGER _("-- Open SSH Account Manager --")

FSConfigPage::FSConfigPage(wxWindow* parent, clFileSystemWorkspaceConfig::Ptr_t config, bool enableRemotePage)
    : FSConfigPageBase(parent)
    , m_enableRemotePage(enableRemotePage)
{
    m_config = config;
    LexerConf::Ptr_t lexer = ColoursAndFontsManager::Get().GetLexer("text");
    if(lexer) {
        lexer->Apply(m_stcCCFlags);
        lexer->Apply(m_stcEnv);
        lexer->Apply(m_stcCommands);
    }

    m_dvListCtrlTargets->SetSortFunction([](clRowEntry* a, clRowEntry* b) {
        const wxString& cellA = a->GetLabel(0);
        const wxString& cellB = b->GetLabel(0);
        return (cellA.CmpNoCase(cellB) < 0);
    });

    m_stcCCFlags->SetText(m_config->GetCompileFlagsAsString());
    m_textCtrlFileExt->ChangeValue(m_config->GetFileExtensions());

    if(m_config->GetLastExecutables().empty()) {
        m_comboBoxExecutable->Append(m_config->GetExecutable());
    } else {
        m_comboBoxExecutable->Append(m_config->GetLastExecutables());
    }
    m_comboBoxExecutable->SetValue(m_config->GetExecutable());

    m_textCtrlArgs->ChangeValue(m_config->GetArgs());
    m_stcEnv->SetText(m_config->GetEnvironment());
    const auto& targets = m_config->GetBuildTargets();
    for(const auto& vt : targets) {
        wxDataViewItem item = m_dvListCtrlTargets->AppendItem(vt.first);
        m_dvListCtrlTargets->SetItemText(item, vt.second, 1);
    }

    wxArrayString compilers = BuildSettingsConfigST::Get()->GetAllCompilersNames();
    m_choiceCompiler->Append(compilers);
    m_choiceCompiler->SetStringSelection(m_config->GetCompiler());

    DoUpdateSSHAcounts();

    m_checkBoxEnableRemote->SetValue(config->IsRemoteEnabled());
    m_checkBoxRemoteBuild->SetValue(config->IsRemoteBuild());
    m_textCtrlRemoteFolder->ChangeValue(config->GetRemoteFolder());
    m_choiceDebuggers->Append(DebuggerMgr::Get().GetAvailableDebuggers());
    m_choiceDebuggers->SetStringSelection(config->GetDebugger());
    m_textCtrlExcludeFiles->ChangeValue(config->GetExcludeFilesPattern());
    m_textCtrlExcludePaths->ChangeValue(config->GetExecludePaths());
    m_textCtrlWD->ChangeValue(config->GetWorkingDirectory());
    m_textCtrlDebugger->ChangeValue(config->GetDebuggerPath());
    m_stcCommands->SetText(config->GetDebuggerCommands());

    if(!m_enableRemotePage) {
        m_checkBoxEnableRemote->Disable();
        m_checkBoxRemoteBuild->Disable();
        m_textCtrlRemoteFolder->Disable();
        m_panelRemote->Disable();
    }
}

FSConfigPage::~FSConfigPage() {}

void FSConfigPage::OnDelete(wxCommandEvent& event)
{
    wxDataViewItem item = m_dvListCtrlTargets->GetSelection();
    CHECK_ITEM_RET(item);

    m_dvListCtrlTargets->DeleteItem(m_dvListCtrlTargets->ItemToRow(item));
}

void FSConfigPage::OnDeleteUI(wxUpdateUIEvent& event)
{
    wxDataViewItem item = m_dvListCtrlTargets->GetSelection();
    if(item.IsOk()) {
        wxString name = m_dvListCtrlTargets->GetItemText(item, 0);
        event.Enable(name != "build" && name != "clean");

    } else {
        event.Enable(false);
    }
}

void FSConfigPage::OnEditTarget(wxCommandEvent& event)
{
    wxUnusedVar(event);
    DoTargetActivated();
}

void FSConfigPage::OnEditTargetUI(wxUpdateUIEvent& event)
{
    event.Enable(m_dvListCtrlTargets->GetSelectedItemsCount());
}

void FSConfigPage::OnNewTarget(wxCommandEvent& event)
{
    BuildTargetDlg dlg(::wxGetTopLevelParent(this), "", "");
    if(dlg.ShowModal() == wxID_OK) {
        wxDataViewItem item = m_dvListCtrlTargets->AppendItem(dlg.GetTargetName());
        m_dvListCtrlTargets->SetItemText(item, dlg.GetTargetCommand(), 1);
    }
}

void FSConfigPage::Save()
{
    std::map<wxString, wxString> targets;
    for(size_t i = 0; i < m_dvListCtrlTargets->GetItemCount(); ++i) {
        wxDataViewItem item = m_dvListCtrlTargets->RowToItem(i);
        wxString name = m_dvListCtrlTargets->GetItemText(item, 0);
        wxString command = m_dvListCtrlTargets->GetItemText(item, 1);
        targets.insert({ name, command });
    }

    m_config->SetBuildTargets(targets);
    m_config->SetCompileFlags(::wxStringTokenize(m_stcCCFlags->GetText(), "\r\n", wxTOKEN_STRTOK));
    m_config->SetFileExtensions(m_textCtrlFileExt->GetValue());
    m_config->SetExecutable(m_comboBoxExecutable->GetStringSelection());

    wxArrayString last_executables = m_comboBoxExecutable->GetStrings();
    if(last_executables.Index(m_comboBoxExecutable->GetValue()) == wxNOT_FOUND) {
        last_executables.Insert(m_comboBoxExecutable->GetValue(), 0);
    }
    if(last_executables.size() > 10) {
        wxArrayString small_arr;
        small_arr.insert(small_arr.end(), last_executables.begin(), last_executables.begin() + 9);
        last_executables.swap(small_arr);
    }

    m_config->SetLastExecutables(last_executables);
    m_config->SetEnvironment(m_stcEnv->GetText());
    m_config->SetArgs(m_textCtrlArgs->GetValue());
    m_config->SetCompiler(m_choiceCompiler->GetStringSelection());
    m_config->SetRemoteFolder(m_textCtrlRemoteFolder->GetValue());
    m_config->SetRemoteEnabled(m_checkBoxEnableRemote->IsChecked());
    m_config->SetRemoteBuild(m_checkBoxRemoteBuild->IsChecked());
    m_config->SetRemoteAccount(m_choiceSSHAccount->GetStringSelection());
    m_config->SetDebugger(m_choiceDebuggers->GetStringSelection());
    m_config->SetExcludeFilesPattern(m_textCtrlExcludeFiles->GetValue());
    m_config->SetExcludePaths(m_textCtrlExcludePaths->GetValue());
    m_config->SetWorkingDirectory(m_textCtrlWD->GetValue());
    m_config->SetDebuggerPath(m_textCtrlDebugger->GetValue());
    m_config->SetDebuggerCommands(m_stcCommands->GetText());
}

void FSConfigPage::OnTargetActivated(wxDataViewEvent& event)
{
    wxUnusedVar(event);
    DoTargetActivated();
}

void FSConfigPage::DoTargetActivated()
{
    wxDataViewItem item = m_dvListCtrlTargets->GetSelection();
    CHECK_ITEM_RET(item);

    BuildTargetDlg dlg(::wxGetTopLevelParent(this), m_dvListCtrlTargets->GetItemText(item, 0),
                       m_dvListCtrlTargets->GetItemText(item, 1));
    if(dlg.ShowModal() == wxID_OK) {
        m_dvListCtrlTargets->SetItemText(item, dlg.GetTargetName(), 0);
        m_dvListCtrlTargets->SetItemText(item, dlg.GetTargetCommand(), 1);
    }
}
void FSConfigPage::OnRemoteEnabledUI(wxUpdateUIEvent& event)
{
#if USE_SFTP
    event.Enable(m_enableRemotePage && m_checkBoxEnableRemote->IsChecked());
#else
    event.Enable(false);
#endif
}

void FSConfigPage::OnSSHBrowse(wxCommandEvent& event)
{
    wxUnusedVar(event);
#if USE_SFTP
    SFTPBrowserDlg dlg(GetParent(), _("Choose folder"), "", clSFTP::SFTP_BROWSE_FOLDERS);
    dlg.Initialize(m_choiceSSHAccount->GetStringSelection(), m_textCtrlRemoteFolder->GetValue());
    if(dlg.ShowModal() == wxID_OK) {
        m_textCtrlRemoteFolder->ChangeValue(dlg.GetPath());
    }
#endif
}

void FSConfigPage::OnSSHAccountChoice(wxCommandEvent& event)
{
#if USE_SFTP
    wxString s = m_choiceSSHAccount->GetStringSelection();
    if(s == OPEN_SSH_ACCOUNT_MANAGER) {
        SSHAccountManagerDlg dlg(GetParent());
        dlg.ShowModal();
        CallAfter(&FSConfigPage::DoUpdateSSHAcounts);
    }
#endif
}

void FSConfigPage::DoUpdateSSHAcounts()
{
#if USE_SFTP
    if(!m_enableRemotePage) {
        m_choiceSSHAccount->Enable(false);
        return;
    }

    m_choiceSSHAccount->Clear();
    // Load the SSH accounts
    SFTPSettings settings;
    settings.Load();
    const SSHAccountInfo::Vect_t& accounts = settings.GetAccounts();
    const wxString& selectedAccount = m_config->GetRemoteAccount();
    int sel = wxNOT_FOUND;
    for(const auto& v : accounts) {
        int where = m_choiceSSHAccount->Append(v.GetAccountName());
        if(sel == wxNOT_FOUND && (v.GetAccountName() == selectedAccount)) {
            sel = where;
        }
    }
    if(sel != wxNOT_FOUND) {
        m_choiceSSHAccount->SetSelection(sel);
    } else if(!m_choiceSSHAccount->IsEmpty()) {
        m_choiceSSHAccount->SetSelection(0);
    }
    m_choiceSSHAccount->Append(OPEN_SSH_ACCOUNT_MANAGER);
#endif
}
void FSConfigPage::OnEnableRemoteUI(wxUpdateUIEvent& event)
{
#if USE_SFTP
    event.Enable(true);
#else
    event.Enable(false);
#endif
}

void FSConfigPage::OnEditExcludePaths(wxCommandEvent& event)
{
    wxUnusedVar(event);

    wxArrayString paths = StringUtils::BuildArgv(m_textCtrlExcludePaths->GetValue());
    wxString value;
    if(!paths.IsEmpty()) {
        value = wxJoin(paths, '\n');
    }
    value = ::clGetStringFromUser(value, wxGetTopLevelParent(this));
    if(!value.IsEmpty()) {
        wxArrayString lines = ::wxStringTokenize(value, "\n", wxTOKEN_STRTOK);
        value = wxJoin(lines, ';');
        m_textCtrlExcludePaths->ChangeValue(value);
    }
}
void FSConfigPage::OnBrowseExec(wxCommandEvent& event)
{
    wxString path;
    if(m_useRemoteBrowsing) {
        auto p = ::clRemoteFileSelector(_("Select a directory"), m_sshAccount);
        if(p.first != m_sshAccount) {
            ::wxMessageBox(_("Wrong account selected!"), "CodeLite", wxOK | wxICON_WARNING);
            return;
        }
        path = p.second;
    } else {
        path = ::wxFileSelector();
    }
    if(path.empty()) {
        return;
    }
    m_comboBoxExecutable->SetValue(path);
}

void FSConfigPage::OnBrowseWD(wxCommandEvent& event)
{
    wxString path;
    if(m_useRemoteBrowsing) {
        auto p = ::clRemoteFolderSelector(_("Select a directory"), m_sshAccount);
        if(p.first != m_sshAccount) {
            ::wxMessageBox(_("Wrong account selected!"), "CodeLite", wxOK | wxICON_WARNING);
            return;
        }
        path = p.second;
    } else {
        path = ::wxDirSelector();
    }
    if(path.empty()) {
        return;
    }
    m_textCtrlWD->ChangeValue(path);
}

void FSConfigPage::OnBrowseForGDB(wxCommandEvent& event)
{
    wxString path;
    if(m_useRemoteBrowsing) {
        auto p = ::clRemoteFileSelector(_("Select debugger executable:"), m_sshAccount);
        if(p.first != m_sshAccount) {
            ::wxMessageBox(_("Wrong account selected!"), "CodeLite", wxOK | wxICON_WARNING);
            return;
        }
        path = p.second;
    } else {
        path = ::wxFileSelector();
    }
    if(path.empty()) {
        return;
    }
    m_textCtrlDebugger->ChangeValue(path);
}