File: depend_dlg_page.cpp

package info (click to toggle)
codelite 14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • 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 (223 lines) | stat: -rw-r--r-- 6,976 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
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2008 by Eran Ifrah
// file name            : depend_dlg_page.cpp
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#include "manager.h"
#include "project.h"
#include "depend_dlg_page.h"

DependenciesPage::DependenciesPage(wxWindow* parent, const wxString& projectName)
    : DependenciesPageBase(parent)
    , m_projectName(projectName)
    , m_dirty(false)
{
    Init();
}

void DependenciesPage::OnConfigChanged(wxCommandEvent& event)
{
    if(m_dirty) {
        // save old configuration
        if(wxMessageBox(
               wxString::Format(_("Build order for configuration '%s' has been modified, would you like to save it?"),
                                m_currentSelection.GetData()),
               _("CodeLite"), wxYES_NO | wxICON_QUESTION) == wxYES) {
            Save();
        }
        m_dirty = false;
    }

    m_currentSelection = event.GetString();
    // switch to new configuration
    DoPopulateControl(m_currentSelection);
}

void DependenciesPage::OnMoveUp(wxCommandEvent& event)
{
    wxUnusedVar(event);
    OnUpCommand(m_listBoxBuildOrder);
}

void DependenciesPage::OnMoveDown(wxCommandEvent& event)
{
    wxUnusedVar(event);
    OnDownCommand(m_listBoxBuildOrder);
}

void DependenciesPage::OnUpCommand(wxListBox* list)
{
    wxString selectedString = list->GetStringSelection();

    int sel = list->GetSelection();
    if(sel == wxNOT_FOUND) {
        return;
    }

    sel--;
    if(sel < 0) {
        return;
    }

    // sel contains the new position we want to place the selection string
    list->Delete(sel + 1);
    list->Insert(selectedString, sel);
    list->Select(sel);
    m_dirty = true;
}

void DependenciesPage::OnDownCommand(wxListBox* list)
{
    int sel = list->GetSelection();
    if(sel == wxNOT_FOUND) {
        return;
    }

    sel++;
    if(sel >= (int)list->GetCount()) {
        return;
    }

    // sel contains the new position we want to place the selection string
    wxString oldStr = list->GetString(sel);

    list->Delete(sel);
    list->Insert(oldStr, sel - 1);
    list->Select(sel);
    m_dirty = true;
}

void DependenciesPage::Save()
{
    // Save only if its dirty...
    if(m_dirty) {
        ProjectPtr proj = ManagerST::Get()->GetProject(m_projectName);

        wxArrayString depsArr;
        for(size_t i = 0; i < m_listBoxBuildOrder->GetCount(); i++) {
            depsArr.Add(m_listBoxBuildOrder->GetString((unsigned int)i));
        }

        if(m_currentSelection.IsEmpty()) {
            return;
        }

        proj->SetDependencies(depsArr, m_currentSelection);
    }
    m_dirty = false;
}

void DependenciesPage::OnCheckListItemToggled(wxCommandEvent& event)
{
    int item = event.GetSelection();
    wxString name = m_checkListProjectList->GetString((unsigned int)item);
    if(!m_checkListProjectList->IsChecked((unsigned int)item)) {
        unsigned int buildOrderId = m_listBoxBuildOrder->FindString(name);
        if(buildOrderId != (unsigned int)wxNOT_FOUND) {
            m_listBoxBuildOrder->Delete(buildOrderId);
        }
    } else {
        m_listBoxBuildOrder->Append(name);
    }
    m_dirty = true;
}

void DependenciesPage::Init()
{
    wxString errMsg;
    ProjectPtr proj = clCxxWorkspaceST::Get()->FindProjectByName(m_projectName, errMsg);
    if(proj) {

        // populate the choice control with the list of available configurations for this project
        ProjectSettingsPtr settings = proj->GetSettings();
        if(settings) {
            ProjectSettingsCookie cookie;
            BuildConfigPtr bldConf = settings->GetFirstBuildConfiguration(cookie);
            while(bldConf) {
                m_choiceProjectConfig->Append(bldConf->GetName());
                bldConf = settings->GetNextBuildConfiguration(cookie);
            }
        }

        // by default select the first configuration
        if(m_choiceProjectConfig->GetCount() > 0) {
            m_choiceProjectConfig->SetSelection(0);
        }

        // select the active configuration
        BuildConfigPtr selBuildConf = clCxxWorkspaceST::Get()->GetProjBuildConf(m_projectName, wxEmptyString);
        if(selBuildConf) {
            int where = m_choiceProjectConfig->FindString(selBuildConf->GetName());
            if(where != wxNOT_FOUND) {
                m_choiceProjectConfig->SetSelection(where);
            }
        }

        m_currentSelection = m_choiceProjectConfig->GetStringSelection();
        DoPopulateControl(m_choiceProjectConfig->GetStringSelection());

    } else {
        wxMessageBox(errMsg, _("CodeLite"));
        return;
    }
}

void DependenciesPage::DoPopulateControl(const wxString& configuration)
{
    wxString errMsg;
    ProjectPtr proj = clCxxWorkspaceST::Get()->FindProjectByName(m_projectName, errMsg);
    if(!proj) {
        return;
    }

    m_listBoxBuildOrder->Clear();
    m_checkListProjectList->Clear();

    // initialize the build order listbox
    wxArrayString depArr = proj->GetDependencies(configuration);
    size_t i = 0;
    for(i = 0; i < depArr.GetCount(); i++) {
        wxString item = depArr.Item(i);
        m_listBoxBuildOrder->Append(item);
    }

    // initialize the project dependencies check list
    wxArrayString projArr;
    ManagerST::Get()->GetProjectList(projArr);

    for(i = 0; i < projArr.GetCount(); i++) {

        if(projArr.Item(i) != m_projectName) {
            int idx = m_checkListProjectList->Append(projArr.Item(i));
            m_checkListProjectList->Check(idx, depArr.Index(projArr.Item(i)) != wxNOT_FOUND);
        }
    }
}

void DependenciesPage::OnApplyButton(wxCommandEvent& event)
{
    wxUnusedVar(event);
    Save();
}

void DependenciesPage::OnApplyButtonUI(wxUpdateUIEvent& event) { event.Enable(m_dirty); }