~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/sdk/projectdepsdlg.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: 4909 $
 
6
 * $Id: projectdepsdlg.cpp 4909 2008-02-27 13:15:26Z mortenmacfly $
 
7
 * $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/sdk/projectdepsdlg.cpp $
 
8
 */
 
9
 
 
10
#include "sdk_precomp.h"
 
11
 
 
12
#ifndef CB_PRECOMP
 
13
    #include "cbproject.h"
 
14
    #include "manager.h"
 
15
    #include "projectmanager.h"
 
16
    #include <wx/intl.h>
 
17
    #include <wx/xrc/xmlres.h>
 
18
    #include <wx/combobox.h>
 
19
    #include <wx/msgdlg.h>
 
20
    #include <wx/checklst.h>
 
21
#endif
 
22
 
 
23
#include "projectdepsdlg.h"
 
24
 
 
25
 
 
26
BEGIN_EVENT_TABLE(ProjectDepsDlg, wxDialog)
 
27
    EVT_COMBOBOX(XRCID("cmbProject"), ProjectDepsDlg::OnProjectChange)
 
28
END_EVENT_TABLE()
 
29
 
 
30
ProjectDepsDlg::ProjectDepsDlg(wxWindow* parent, cbProject* sel)
 
31
    : m_LastSel(-1)
 
32
{
 
33
    //ctor
 
34
    wxXmlResource::Get()->LoadDialog(this, parent, _T("dlgConfigureProjectDeps"));
 
35
 
 
36
    wxComboBox* cmb = XRCCTRL(*this, "cmbProject", wxComboBox);
 
37
 
 
38
    int idx = 0;
 
39
    ProjectsArray* mainarr = Manager::Get()->GetProjectManager()->GetProjects();
 
40
    for (size_t i = 0; i < mainarr->GetCount(); ++i)
 
41
    {
 
42
        cbProject* prj = mainarr->Item(i);
 
43
        cmb->Append(prj->GetTitle(), prj);
 
44
        if (prj == sel)
 
45
            idx = i;
 
46
    }
 
47
    cmb->SetSelection(idx);
 
48
    m_LastSel = idx;
 
49
    FillList();
 
50
}
 
51
 
 
52
ProjectDepsDlg::~ProjectDepsDlg()
 
53
{
 
54
    //dtor
 
55
}
 
56
 
 
57
bool ProjectDepsDlg::SaveList()
 
58
{
 
59
    wxComboBox* cmb = XRCCTRL(*this, "cmbProject", wxComboBox);
 
60
    wxCheckListBox* lst = XRCCTRL(*this, "lstDeps", wxCheckListBox);
 
61
 
 
62
    if (m_LastSel == -1)
 
63
        return true;
 
64
 
 
65
    cbProject* thisprj = static_cast<cbProject*>(cmb->GetClientData(m_LastSel));
 
66
    if (!thisprj)
 
67
        return true;
 
68
 
 
69
    // first clear all deps for this project
 
70
    Manager::Get()->GetProjectManager()->ClearProjectDependencies(thisprj);
 
71
 
 
72
    // now set the the new deps
 
73
    for (int i = 0; i < (int)lst->GetCount(); ++i)
 
74
    {
 
75
        if (!lst->IsChecked(i))
 
76
            continue;
 
77
 
 
78
        cbProject* prj = 0;
 
79
 
 
80
        ProjectsArray* mainarr = Manager::Get()->GetProjectManager()->GetProjects();
 
81
        for (size_t x = 0; x < mainarr->GetCount(); ++x)
 
82
        {
 
83
            if (mainarr->Item(x)->GetTitle() == lst->GetString(i))
 
84
            {
 
85
                prj = mainarr->Item(x);
 
86
                break;
 
87
            }
 
88
        }
 
89
        if (!prj)
 
90
            continue;
 
91
 
 
92
        if (!Manager::Get()->GetProjectManager()->AddProjectDependency(thisprj, prj))
 
93
        {
 
94
            cbMessageBox(wxString::Format(_("Cannot add project '%s' as a dependency to '%s' because this "
 
95
                                            "would cause a circular dependency error..."),
 
96
                                            thisprj->GetTitle().c_str(), prj->GetTitle().c_str()),
 
97
                        _("Error"), wxICON_ERROR);
 
98
            return false;
 
99
        }
 
100
    }
 
101
    return true;
 
102
}
 
103
 
 
104
void ProjectDepsDlg::FillList()
 
105
{
 
106
    wxComboBox* cmb = XRCCTRL(*this, "cmbProject", wxComboBox);
 
107
    wxCheckListBox* lst = XRCCTRL(*this, "lstDeps", wxCheckListBox);
 
108
 
 
109
    int idx = cmb->GetSelection();
 
110
    if (m_LastSel != idx && m_LastSel != -1)
 
111
    {
 
112
        // save old list
 
113
        SaveList();
 
114
    }
 
115
    m_LastSel = idx;
 
116
    if (idx == -1)
 
117
        return;
 
118
 
 
119
    cbProject* thisprj = static_cast<cbProject*>(cmb->GetClientData(idx));
 
120
    if (!thisprj)
 
121
        return;
 
122
    const ProjectsArray* arr = Manager::Get()->GetProjectManager()->GetDependenciesForProject(thisprj);
 
123
 
 
124
    lst->Clear();
 
125
    ProjectsArray* mainarr = Manager::Get()->GetProjectManager()->GetProjects();
 
126
    for (size_t i = 0; i < mainarr->GetCount(); ++i)
 
127
    {
 
128
        cbProject* prj = mainarr->Item(i);
 
129
        if (prj == thisprj)
 
130
            continue;
 
131
        lst->Append(prj->GetTitle());
 
132
 
 
133
        // check dependency
 
134
        lst->Check(lst->GetCount() - 1, arr && arr->Index(prj) != wxNOT_FOUND);
 
135
    }
 
136
}
 
137
 
 
138
void ProjectDepsDlg::OnProjectChange(wxCommandEvent& event)
 
139
{
 
140
    FillList();
 
141
}
 
142
 
 
143
void ProjectDepsDlg::EndModal(int retCode)
 
144
{
 
145
    if (SaveList())
 
146
        return wxDialog::EndModal(retCode);
 
147
}