File: edit_configuration.cpp

package info (click to toggle)
codelite 12.0+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 95,112 kB
  • sloc: cpp: 424,040; ansic: 18,284; php: 9,569; lex: 4,186; yacc: 2,820; python: 2,294; sh: 312; makefile: 51; xml: 13
file content (194 lines) | stat: -rw-r--r-- 7,452 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
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
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2008 by Eran Ifrah
// file name            : edit_configuration.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.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version May  5 2007)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////

#ifdef WX_PRECOMP

#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__

#else
#include <wx/wx.h>
#endif // WX_PRECOMP

#include "edit_configuration.h"
#include "manager.h"
#include "project_settings.h"
#include "macros.h"

///////////////////////////////////////////////////////////////////////////

EditConfigurationDialog::EditConfigurationDialog(
    wxWindow* parent, const wxString& projectName, int id, wxString title, wxPoint pos, wxSize size, int style)
    : wxDialog(parent, id, title, pos, size, style)
    , m_projectName(projectName)
{
    this->SetSizeHints(wxDefaultSize, wxDefaultSize);

    wxBoxSizer* bSizer15;
    bSizer15 = new wxBoxSizer(wxVERTICAL);

    m_panel6 = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
    wxBoxSizer* bSizer17;
    bSizer17 = new wxBoxSizer(wxHORIZONTAL);

    m_configurationsList = new wxListBox(m_panel6, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, 0);
    bSizer17->Add(m_configurationsList, 1, wxALL | wxEXPAND, 5);

    ProjectSettingsPtr settings = ManagerST::Get()->GetProjectSettings(m_projectName);
    if(settings) {
        ProjectSettingsCookie cookie;
        BuildConfigPtr bldConf = settings->GetFirstBuildConfiguration(cookie);
        while(bldConf) {
            m_configurationsList->Append(bldConf->GetName());
            bldConf = settings->GetNextBuildConfiguration(cookie);
        }
    }
    if(m_configurationsList->GetCount() > 0) m_configurationsList->SetSelection(0);

    wxBoxSizer* bSizer18;
    bSizer18 = new wxBoxSizer(wxVERTICAL);

    m_buttonDelete = new wxButton(m_panel6, wxID_ANY, _("&Delete"), wxDefaultPosition, wxDefaultSize, 0);
    bSizer18->Add(m_buttonDelete, 0, wxALL, 5);

    m_buttonRename = new wxButton(m_panel6, wxID_ANY, _("&Rename"), wxDefaultPosition, wxDefaultSize, 0);
    bSizer18->Add(m_buttonRename, 0, wxALL, 5);
    bSizer17->Add(bSizer18, 0, wxEXPAND, 5);

    m_panel6->SetSizer(bSizer17);
    m_panel6->Layout();
    bSizer17->Fit(m_panel6);
    bSizer15->Add(m_panel6, 1, wxALL | wxEXPAND, 5);

    m_staticline9 = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL);
    bSizer15->Add(m_staticline9, 0, wxEXPAND | wxALL, 5);

    wxBoxSizer* bSizer16;
    bSizer16 = new wxBoxSizer(wxHORIZONTAL);

    m_buttonClose = new wxButton(this, wxID_OK, _("Close"), wxDefaultPosition, wxDefaultSize, 0);
    bSizer16->Add(m_buttonClose, 0, wxALL, 5);

    bSizer15->Add(bSizer16, 0, wxALIGN_CENTER, 5);

    this->SetSizer(bSizer15);
    GetSizer()->Fit(this);
    Layout();

    ConnectListBoxDClick(m_configurationsList, EditConfigurationDialog::OnItemDclick);
    ConnectButton(m_buttonClose, EditConfigurationDialog::OnButtonClose);
    ConnectButton(m_buttonRename, EditConfigurationDialog::OnButtonRename);
    ConnectButton(m_buttonDelete, EditConfigurationDialog::OnButtonDelete);
}

void EditConfigurationDialog::RenameConfiguration(const wxString& oldName, const wxString& newName)
{
    ProjectSettingsPtr settings = ManagerST::Get()->GetProjectSettings(m_projectName);
    if(settings) {
        BuildConfigPtr bldConf = settings->GetBuildConfiguration(oldName);
        if(bldConf) {
            settings->RemoveConfiguration(oldName);
            bldConf->SetName(newName);
            settings->SetBuildConfiguration(bldConf);
            // save changes
            ManagerST::Get()->SetProjectSettings(m_projectName, settings);

            // update the control
            m_configurationsList->Clear();
            ProjectSettingsCookie cookie;
            BuildConfigPtr bldConf = settings->GetFirstBuildConfiguration(cookie);
            while(bldConf) {
                m_configurationsList->Append(bldConf->GetName());
                bldConf = settings->GetNextBuildConfiguration(cookie);
            }
            if(m_configurationsList->GetCount() > 0) m_configurationsList->SetSelection(0);
        }
    }
}

void EditConfigurationDialog::OnItemDclick(wxCommandEvent& event)
{
    wxString oldName = event.GetString();
    wxTextEntryDialog* dlg = new wxTextEntryDialog(this, _("Enter New Name:"), _("Rename"), oldName);
    dlg->SetTextValidator(wxFILTER_ASCII);

    if(dlg->ShowModal() == wxID_OK) {
        wxString newName = dlg->GetValue();
        RenameConfiguration(oldName, newName);
    }
}

void EditConfigurationDialog::OnButtonClose(wxCommandEvent& event)
{
    wxUnusedVar(event);
    EndModal(wxID_OK);
}

void EditConfigurationDialog::OnButtonRename(wxCommandEvent& event)
{
    wxUnusedVar(event);
    wxString oldName = m_configurationsList->GetStringSelection();
    if(oldName.IsEmpty()) {
        return;
    }
    wxTextEntryDialog* dlg = new wxTextEntryDialog(this, _("Enter New Name:"), _("Rename"), oldName);
    dlg->SetTextValidator(wxFILTER_ASCII);

    if(dlg->ShowModal() == wxID_OK) {
        wxString newName = dlg->GetValue();
        RenameConfiguration(oldName, newName);
    }
}

void EditConfigurationDialog::OnButtonDelete(wxCommandEvent& event)
{
    wxUnusedVar(event);
    wxString selection = m_configurationsList->GetStringSelection();
    if(selection.IsEmpty()) {
        return;
    }
    wxString msg(_("Remove configuration '"));
    msg << selection << _("' ?");
    if(wxMessageBox(msg, _("Confirm"), wxYES_NO | wxCANCEL | wxICON_QUESTION) == wxYES) {
        ProjectSettingsPtr settings = ManagerST::Get()->GetProjectSettings(m_projectName);
        if(settings) {
            settings->RemoveConfiguration(selection);
            m_configurationsList->Delete(m_configurationsList->GetSelection());
            if(m_configurationsList->GetCount() > 0) m_configurationsList->SetSelection(0);

            // save changes
            ManagerST::Get()->SetProjectSettings(m_projectName, settings);
        }
    }
}