~ubuntu-branches/ubuntu/oneiric/codeblocks/oneiric

« back to all changes in this revision

Viewing changes to src/sdk/virtualbuildtargetsdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
 
3
 * http://www.gnu.org/licenses/lgpl-3.0.html
 
4
 *
 
5
 * $Revision$
 
6
 * $Id$
 
7
 * $HeadURL$
 
8
 */
 
9
 
 
10
#include "sdk_precomp.h"
 
11
#include "virtualbuildtargetsdlg.h"
 
12
 
 
13
#ifndef CB_PRECOMP
 
14
    #include "cbproject.h"
 
15
    #include "globals.h"
 
16
    #include "wx/textdlg.h"
 
17
    #include "wx/utils.h"
 
18
#endif
 
19
 
 
20
//(*InternalHeaders(VirtualBuildTargetsDlg)
 
21
#include <wx/bitmap.h>
 
22
#include <wx/font.h>
 
23
#include <wx/fontenum.h>
 
24
#include <wx/fontmap.h>
 
25
#include <wx/image.h>
 
26
#include <wx/intl.h>
 
27
#include <wx/settings.h>
 
28
#include <wx/xrc/xmlres.h>
 
29
//*)
 
30
 
 
31
//(*IdInit(VirtualBuildTargetsDlg)
 
32
//*)
 
33
 
 
34
BEGIN_EVENT_TABLE(VirtualBuildTargetsDlg,wxDialog)
 
35
        //(*EventTable(VirtualBuildTargetsDlg)
 
36
        //*)
 
37
        EVT_UPDATE_UI(-1, VirtualBuildTargetsDlg::OnUpdateUI)
 
38
END_EVENT_TABLE()
 
39
 
 
40
VirtualBuildTargetsDlg::VirtualBuildTargetsDlg(wxWindow* parent,wxWindowID id, cbProject* project)
 
41
    : lstAliases(0),
 
42
    btnAdd(0),
 
43
    btnEdit(0),
 
44
    btnRemove(0),
 
45
    lstTargets(0),
 
46
    m_pProject(project)
 
47
{
 
48
        //(*Initialize(VirtualBuildTargetsDlg)
 
49
        wxXmlResource::Get()->LoadObject(this,parent,_T("VirtualBuildTargetsDlg"),_T("wxDialog"));
 
50
        lstAliases = (wxListBox*)FindWindow(XRCID("ID_LISTBOX1"));
 
51
        btnAdd = (wxButton*)FindWindow(XRCID("ID_BUTTON1"));
 
52
        btnEdit = (wxButton*)FindWindow(XRCID("ID_BUTTON2"));
 
53
        btnRemove = (wxButton*)FindWindow(XRCID("ID_BUTTON3"));
 
54
        lstTargets = (wxCheckListBox*)FindWindow(XRCID("ID_CHECKLISTBOX1"));
 
55
        Connect(XRCID("ID_LISTBOX1"),wxEVT_COMMAND_LISTBOX_SELECTED,(wxObjectEventFunction)&VirtualBuildTargetsDlg::OnAliasesSelect);
 
56
        Connect(XRCID("ID_BUTTON1"),wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&VirtualBuildTargetsDlg::OnAddClick);
 
57
        Connect(XRCID("ID_BUTTON2"),wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&VirtualBuildTargetsDlg::OnEditClick);
 
58
        Connect(XRCID("ID_BUTTON3"),wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&VirtualBuildTargetsDlg::OnRemoveClick);
 
59
        Connect(XRCID("ID_CHECKLISTBOX1"),wxEVT_COMMAND_CHECKLISTBOX_TOGGLED,(wxObjectEventFunction)&VirtualBuildTargetsDlg::OnTargetsToggled);
 
60
        //*)
 
61
 
 
62
        // fill aliases
 
63
        wxArrayString virtuals = m_pProject->GetVirtualBuildTargets();
 
64
        lstAliases->Set(virtuals);
 
65
        lstAliases->SetSelection(0);
 
66
 
 
67
        // fill build targets
 
68
        for (int i = 0; i < m_pProject->GetBuildTargetsCount(); ++i)
 
69
        lstTargets->Append(m_pProject->GetBuildTarget(i)->GetTitle());
 
70
    CheckTargets();
 
71
}
 
72
 
 
73
VirtualBuildTargetsDlg::~VirtualBuildTargetsDlg()
 
74
{
 
75
    //(*Destroy(VirtualBuildTargetsDlg)
 
76
        //*)
 
77
}
 
78
 
 
79
void VirtualBuildTargetsDlg::SetVirtualTarget(const wxString& targetName)
 
80
{
 
81
    if (!lstTargets->IsEnabled())
 
82
        return;
 
83
    wxArrayString checked;
 
84
    for (int i = 0; i < (int)lstTargets->GetCount(); ++i)
 
85
    {
 
86
        if (lstTargets->IsChecked(i))
 
87
            checked.Add(lstTargets->GetString(i));
 
88
    }
 
89
 
 
90
    if (checked.GetCount() > 0)
 
91
    {
 
92
        if (!m_pProject->DefineVirtualBuildTarget(targetName, checked))
 
93
            cbMessageBox(_("Failed to setup this virtual build target.\n"
 
94
                            "Check the debug log for more info..."), _("Error"), wxICON_ERROR);
 
95
    }
 
96
}
 
97
 
 
98
void VirtualBuildTargetsDlg::CheckTargets()
 
99
{
 
100
    const wxArrayString& group = m_pProject->GetVirtualBuildTargetGroup(lstAliases->GetStringSelection());
 
101
        for (int i = 0; i < m_pProject->GetBuildTargetsCount(); ++i)
 
102
        {
 
103
            wxString tgtName = m_pProject->GetBuildTarget(i)->GetTitle();
 
104
            bool check = group.Index(tgtName) != wxNOT_FOUND;
 
105
        lstTargets->Check(i, check);
 
106
        }
 
107
}
 
108
 
 
109
void VirtualBuildTargetsDlg::OnUpdateUI(wxUpdateUIEvent& event)
 
110
{
 
111
    bool hasSel = lstAliases->GetSelection() != -1;
 
112
    btnEdit->Enable(hasSel);
 
113
    btnRemove->Enable(hasSel);
 
114
    lstTargets->Enable(hasSel);
 
115
}
 
116
 
 
117
void VirtualBuildTargetsDlg::OnAddClick(wxCommandEvent& event)
 
118
{
 
119
    wxString targetName = wxGetTextFromUser(_("Enter the new virtual build target name:"),
 
120
                                            _("New virtual build target"));
 
121
    if (targetName.IsEmpty())
 
122
        return;
 
123
 
 
124
    if (lstAliases->FindString(targetName) != wxNOT_FOUND)
 
125
    {
 
126
        cbMessageBox(_("A virtual build target with this name already exists in this project!"),
 
127
                        _("Error"),
 
128
                        wxOK | wxCENTRE | wxICON_ERROR);
 
129
        return;
 
130
    }
 
131
 
 
132
    if (m_pProject->GetBuildTarget(targetName))
 
133
    {
 
134
        cbMessageBox(_("A real build target with this name already exists in this project!"),
 
135
                        _("Error"),
 
136
                        wxOK | wxCENTRE | wxICON_ERROR);
 
137
        return;
 
138
    }
 
139
 
 
140
    // add it with an empty group
 
141
    lstAliases->Append(targetName);
 
142
    lstAliases->SetSelection(lstAliases->GetCount() - 1);
 
143
    CheckTargets();
 
144
}
 
145
 
 
146
void VirtualBuildTargetsDlg::OnEditClick(wxCommandEvent& event)
 
147
{
 
148
    wxString targetName = wxGetTextFromUser(_("Enter the new virtual build target name:"),
 
149
                                            _("Edit virtual build target"),
 
150
                                            lstAliases->GetStringSelection());
 
151
 
 
152
    // is name unchanged, or user cancelled?
 
153
    if (targetName.IsEmpty() || targetName == lstAliases->GetStringSelection())
 
154
        return;
 
155
 
 
156
    if (lstAliases->FindString(targetName) != wxNOT_FOUND)
 
157
    {
 
158
        cbMessageBox(_("A virtual build target with this name already exists in this project!"),
 
159
                        _("Error"),
 
160
                        wxOK | wxCENTRE | wxICON_ERROR);
 
161
        return;
 
162
    }
 
163
 
 
164
    if (m_pProject->GetBuildTarget(targetName))
 
165
    {
 
166
        cbMessageBox(_("A real build target with this name already exists in this project!"),
 
167
                        _("Error"),
 
168
                        wxOK | wxCENTRE | wxICON_ERROR);
 
169
        return;
 
170
    }
 
171
 
 
172
    m_pProject->RemoveVirtualBuildTarget(lstAliases->GetStringSelection());
 
173
    lstAliases->SetString(lstAliases->GetSelection(), targetName);
 
174
    SetVirtualTarget(targetName);
 
175
}
 
176
 
 
177
void VirtualBuildTargetsDlg::OnRemoveClick(wxCommandEvent& event)
 
178
{
 
179
    if (cbMessageBox(_("Are you sure you want to remove this virtual build target?"), _("Confirmation"), wxYES_NO | wxICON_QUESTION) == wxID_NO)
 
180
        return;
 
181
    m_pProject->RemoveVirtualBuildTarget(lstAliases->GetStringSelection());
 
182
    lstAliases->Delete(lstAliases->GetSelection());
 
183
    lstAliases->SetSelection(0);
 
184
    CheckTargets();
 
185
}
 
186
 
 
187
void VirtualBuildTargetsDlg::OnAliasesSelect(wxCommandEvent& event)
 
188
{
 
189
    CheckTargets();
 
190
}
 
191
 
 
192
void VirtualBuildTargetsDlg::OnTargetsToggled(wxCommandEvent& event)
 
193
{
 
194
    SetVirtualTarget(lstAliases->GetStringSelection());
 
195
}