File: LanguageServerSettingsDlg.cpp

package info (click to toggle)
codelite 14.0+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 112,816 kB
  • sloc: cpp: 483,662; ansic: 150,144; php: 9,569; lex: 4,186; python: 3,417; yacc: 2,820; sh: 1,147; makefile: 52; xml: 13
file content (109 lines) | stat: -rw-r--r-- 3,832 bytes parent folder | download
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
#include "LSPDetector.hpp"
#include "LSPDetectorManager.hpp"
#include "LanguageServerConfig.h"
#include "LanguageServerEntry.h"
#include "LanguageServerPage.h"
#include "LanguageServerSettingsDlg.h"
#include "NewLanguageServerDlg.h"
#include "clPythonLocator.hpp"
#include "globals.h"
#include <vector>
#include <wx/choicdlg.h>
#include <wx/msgdlg.h>

LanguageServerSettingsDlg::LanguageServerSettingsDlg(wxWindow* parent, bool triggerScan)
    : LanguageServerSettingsDlgBase(parent)
    , m_scanOnStartup(triggerScan)
{
    DoInitialize();
    ::clSetDialogBestSizeAndPosition(this);
    if(m_scanOnStartup) { CallAfter(&LanguageServerSettingsDlg::DoScan); }
}

LanguageServerSettingsDlg::~LanguageServerSettingsDlg() {}

void LanguageServerSettingsDlg::OnAddServer(wxCommandEvent& event)
{
    NewLanguageServerDlg dlg(this);
    if(dlg.ShowModal() == wxID_OK) {
        LanguageServerEntry server = dlg.GetData();
        // Update the configuration
        LanguageServerConfig::Get().AddServer(server);
        m_notebook->AddPage(new LanguageServerPage(m_notebook, server), server.GetName());
    }
}

void LanguageServerSettingsDlg::Save()
{
    LanguageServerConfig& conf = LanguageServerConfig::Get();
    for(size_t i = 0; i < m_notebook->GetPageCount(); ++i) {
        LanguageServerPage* page = dynamic_cast<LanguageServerPage*>(m_notebook->GetPage(i));
        conf.AddServer(page->GetData());
    }
    conf.SetEnabled(GetCheckBoxEnable()->IsChecked());
    conf.Save();
}

void LanguageServerSettingsDlg::OnDeleteLSP(wxCommandEvent& event)
{
    int sel = m_notebook->GetSelection();
    if(sel == wxNOT_FOUND) { return; }
    wxString serverName = m_notebook->GetPageText(sel);

    if(::wxMessageBox(wxString() << _("Are you sure you want to delete '") << serverName << "' ?", "CodeLite",
                      wxICON_QUESTION | wxCENTRE | wxYES_NO | wxCANCEL | wxCANCEL_DEFAULT, this) != wxYES) {
        return;
    }
    LanguageServerConfig::Get().RemoveServer(serverName);
    m_notebook->DeletePage(sel);
}

void LanguageServerSettingsDlg::OnDeleteLSPUI(wxUpdateUIEvent& event) { event.Enable(m_notebook->GetPageCount()); }
void LanguageServerSettingsDlg::OnOKUI(wxUpdateUIEvent& event) { event.Enable(true); }

void LanguageServerSettingsDlg::OnScan(wxCommandEvent& event)
{
    event.Skip();
    DoScan();
}

void LanguageServerSettingsDlg::DoInitialize()
{
    m_notebook->DeleteAllPages();
    const LanguageServerEntry::Map_t& servers = LanguageServerConfig::Get().GetServers();
    for(const LanguageServerEntry::Map_t::value_type& vt : servers) {
        m_notebook->AddPage(new LanguageServerPage(m_notebook, vt.second), vt.second.GetName());
    }
    m_checkBoxEnable->SetValue(LanguageServerConfig::Get().IsEnabled());
}

void LanguageServerSettingsDlg::DoScan()
{
    wxBusyCursor bc;
    std::vector<LSPDetector::Ptr_t> matches;
    LSPDetectorManager detector;
    if(detector.Scan(matches)) {
        // Matches were found, reload the dialog
        // Prompt the user to select which entries to add
        wxArrayString options;
        wxArrayInt selections;
        for(size_t i = 0; i < matches.size(); ++i) {
            options.Add(matches[i]->GetName());
            selections.Add(i);
        }
        if((wxGetSelectedChoices(selections, _("Select Language Servers to add"), "CodeLite", options) ==
            wxNOT_FOUND) ||
           selections.empty()) {
            return;
        }
        LanguageServerConfig& conf = LanguageServerConfig::Get();
        for(size_t i = 0; i < selections.size(); ++i) {
            LanguageServerEntry entry;
            matches[selections[i]]->GetLanguageServerEntry(entry);
            conf.AddServer(entry);
        }
        conf.Save();
        DoInitialize();
        if(m_scanOnStartup) { m_checkBoxEnable->SetValue(true); }
    }
}