File: clConfigurationSelectionCtrl.cpp

package info (click to toggle)
codelite 17.0.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 136,244 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 (191 lines) | stat: -rw-r--r-- 7,048 bytes parent folder | download | duplicates (3)
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
#include "clConfigurationSelectionCtrl.h"

#include "bitmap_loader.h"
#include "clThemedChoice.h"
#include "cl_config.h"
#include "codelite_events.h"
#include "configuration_manager_dlg.h"
#include "event_notifier.h"
#include "frame.h"
#include "globals.h"
#include "imanager.h"
#include "manager.h"
#include "wxStringHash.h"

clConfigurationSelectionCtrl::clConfigurationSelectionCtrl(wxWindow* parent, wxWindowID winid, const wxPoint& pos,
                                                           const wxSize& size, long style)
    : wxPanel(parent, winid, pos, size, style)
{
    SetBackgroundColour(clSystemSettings::GetDefaultPanelColour());
    SetSizer(new wxBoxSizer(wxVERTICAL));
    m_choice = new wxChoice(this, wxID_ANY, pos, size, {});
    m_choice->Bind(wxEVT_CHOICE, &clConfigurationSelectionCtrl::OnChoice, this);
    GetSizer()->Add(m_choice, 1, wxEXPAND | wxALL, 5);

    EventNotifier::Get()->Bind(wxEVT_WORKSPACE_LOADED, &clConfigurationSelectionCtrl::OnWorkspaceLoaded, this);
    EventNotifier::Get()->Bind(wxEVT_WORKSPACE_CLOSED, &clConfigurationSelectionCtrl::OnWorkspaceClosed, this);
    EventNotifier::Get()->Bind(wxEVT_PROJ_ADDED, &clConfigurationSelectionCtrl::OnProjectAdded, this);
    EventNotifier::Get()->Bind(wxEVT_PROJ_REMOVED, &clConfigurationSelectionCtrl::OnProjectRemoved, this);
    wxTheApp->Bind(wxEVT_MENU, &clConfigurationSelectionCtrl::OnConfigurationManager, this,
                   XRCID("configuration_manager"));
    EventNotifier::Get()->Bind(wxEVT_ACTIVE_PROJECT_CHANGED, &clConfigurationSelectionCtrl::OnActiveProjectChanged,
                               this);
    EventNotifier::Get()->Bind(wxEVT_SYS_COLOURS_CHANGED, [this](clCommandEvent& e) {
        e.Skip();
        SetBackgroundColour(clSystemSettings::GetDefaultPanelColour());
        Refresh();
    });
}

clConfigurationSelectionCtrl::~clConfigurationSelectionCtrl()
{
    m_choice->Unbind(wxEVT_CHOICE, &clConfigurationSelectionCtrl::OnChoice, this);
    EventNotifier::Get()->Unbind(wxEVT_WORKSPACE_LOADED, &clConfigurationSelectionCtrl::OnWorkspaceLoaded, this);
    EventNotifier::Get()->Unbind(wxEVT_WORKSPACE_CLOSED, &clConfigurationSelectionCtrl::OnWorkspaceClosed, this);
    EventNotifier::Get()->Unbind(wxEVT_PROJ_ADDED, &clConfigurationSelectionCtrl::OnProjectAdded, this);
    EventNotifier::Get()->Unbind(wxEVT_PROJ_REMOVED, &clConfigurationSelectionCtrl::OnProjectRemoved, this);
    wxTheApp->Unbind(wxEVT_MENU, &clConfigurationSelectionCtrl::OnConfigurationManager, this,
                     XRCID("configuration_manager"));
    EventNotifier::Get()->Unbind(wxEVT_ACTIVE_PROJECT_CHANGED, &clConfigurationSelectionCtrl::OnActiveProjectChanged,
                                 this);
}

void clConfigurationSelectionCtrl::Update(const wxArrayString& projects, const wxArrayString& configurations)
{
    m_projects = projects;
    m_configurations = configurations;
    m_configurations.push_back(OPEN_CONFIG_MGR_STR);
    m_choice->Set(configurations);
}

void clConfigurationSelectionCtrl::SetActiveConfiguration(const wxString& activeConfiguration)
{
    m_activeConfiguration = activeConfiguration;

    int where = m_choice->FindString(m_activeConfiguration);
    if(where != wxNOT_FOUND) {
        m_choice->SetSelection(where);
    }
}

void clConfigurationSelectionCtrl::OnChoice(wxCommandEvent& event)
{
    int where = event.GetSelection();
    if(where == wxNOT_FOUND)
        return;

    wxString selectedString = m_choice->GetString(where);
    if(selectedString != OPEN_CONFIG_MGR_STR) {

        SetActiveConfiguration(selectedString);
        DoConfigChanged(selectedString);

        // Fire 'config-changed' event
        clCommandEvent changeEvent(wxEVT_WORKSPACE_BUILD_CONFIG_CHANGED);
        changeEvent.SetString(selectedString);
        EventNotifier::Get()->AddPendingEvent(changeEvent);
    } else {
        DoOpenConfigurationManagerDlg();
    }
}

void clConfigurationSelectionCtrl::Clear() {}

void clConfigurationSelectionCtrl::SetConfigurations(const wxArrayString& configurations, const wxString& activeConfig)
{
    m_configurations = configurations;
    m_activeConfiguration = activeConfig;
    m_configurations.push_back(OPEN_CONFIG_MGR_STR);
    m_choice->Set(m_configurations);
    int where = m_choice->FindString(m_activeConfiguration);
    if(where != wxNOT_FOUND) {
        m_choice->SetSelection(where);
    }
}

void clConfigurationSelectionCtrl::OnWorkspaceLoaded(clWorkspaceEvent& event)
{
    event.Skip();
    if(ManagerST::Get()->IsWorkspaceOpen()) {
        Enable(true);
        DoWorkspaceConfig();
        DoUpdateChoiceWithProjects();
    }
}

void clConfigurationSelectionCtrl::OnWorkspaceClosed(clWorkspaceEvent& event)
{
    event.Skip();
    Clear();
    Enable(false);
}

void clConfigurationSelectionCtrl::OnProjectAdded(clCommandEvent& event)
{
    event.Skip();
    DoUpdateChoiceWithProjects();
}

void clConfigurationSelectionCtrl::OnProjectRemoved(clCommandEvent& event)
{
    event.Skip();
    DoUpdateChoiceWithProjects();
}

void clConfigurationSelectionCtrl::DoUpdateChoiceWithProjects() {}

void clConfigurationSelectionCtrl::DoWorkspaceConfig()
{
    // Update the workspace configuration
    BuildMatrixPtr matrix = clCxxWorkspaceST::Get()->GetBuildMatrix();
    auto confs = matrix->GetConfigurations();

    confs.sort([](WorkspaceConfigurationPtr one, WorkspaceConfigurationPtr two) {
        return one->GetName().CmpNoCase(two->GetName()) < 0;
    });

    wxArrayString configurations;
    std::for_each(confs.begin(), confs.end(),
                  [&](WorkspaceConfigurationPtr conf) { configurations.push_back(conf->GetName()); });

    wxString activeConfig = configurations.IsEmpty() ? "" : matrix->GetSelectedConfigurationName();
    SetConfigurations(configurations, activeConfig);
    clMainFrame::Get()->SelectBestEnvSet();
}

void clConfigurationSelectionCtrl::OnConfigurationManager(wxCommandEvent& e)
{
    wxUnusedVar(e);
    DoOpenConfigurationManagerDlg();
}

void clConfigurationSelectionCtrl::DoOpenConfigurationManagerDlg()
{
    ConfigurationManagerDlg dlg(EventNotifier::Get()->TopFrame());
    dlg.ShowModal();

    // in case user added configurations, update the choice control
    DoWorkspaceConfig();
    DoUpdateChoiceWithProjects();

    BuildMatrixPtr matrix = ManagerST::Get()->GetWorkspaceBuildMatrix();
    SetActiveConfiguration(matrix->GetSelectedConfigurationName());
}

void clConfigurationSelectionCtrl::DoConfigChanged(const wxString& newConfigName)
{
    wxBusyCursor bc;
    BuildMatrixPtr matrix = ManagerST::Get()->GetWorkspaceBuildMatrix();
    matrix->SetSelectedConfigurationName(newConfigName);
    ManagerST::Get()->SetWorkspaceBuildMatrix(matrix);

    // Set the focus to the active editor if any
    clEditor* editor = clMainFrame::Get()->GetMainBook()->GetActiveEditor();
    if(editor) {
        editor->SetActive();
    }

    ManagerST::Get()->UpdateParserPaths(true);
}

void clConfigurationSelectionCtrl::OnActiveProjectChanged(clProjectSettingsEvent& event) { event.Skip(); }