Code::Blocks  SVN r11506
projectdepsdlg.cpp
Go to the documentation of this file.
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: 10912 $
6  * $Id: projectdepsdlg.cpp 10912 2016-09-25 16:10:13Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/src/projectdepsdlg.cpp $
8  */
9 
10 #include "sdk.h"
11 
12 #ifndef CB_PRECOMP
13  #include "cbproject.h"
14  #include "manager.h"
15  #include "projectmanager.h"
16  #include <wx/button.h>
17  #include <wx/intl.h>
18  #include <wx/xrc/xmlres.h>
19  #include <wx/choice.h>
20  #include <wx/msgdlg.h>
21  #include <wx/checklst.h>
22 #endif
23 
24 #include "projectdepsdlg.h"
25 
26 
27 BEGIN_EVENT_TABLE(ProjectDepsDlg, wxScrollingDialog)
28  EVT_CHOICE(XRCID("cmbProject"), ProjectDepsDlg::OnProjectChange)
29 END_EVENT_TABLE()
30 
32  : m_LastSel(-1)
33 {
34  //ctor
35  wxXmlResource::Get()->LoadObject(this, parent, _T("dlgConfigureProjectDeps"),_T("wxScrollingDialog"));
36  XRCCTRL(*this, "wxID_CANCEL", wxButton)->SetDefault();
37 
38  wxChoice* cmb = XRCCTRL(*this, "cmbProject", wxChoice);
39 
40  int idx = 0;
41  ProjectsArray* mainarr = Manager::Get()->GetProjectManager()->GetProjects();
42  for (size_t i = 0; i < mainarr->GetCount(); ++i)
43  {
44  cbProject* prj = mainarr->Item(i);
45  cmb->Append(prj->GetTitle(), prj);
46  if (prj == sel)
47  idx = i;
48  }
49  cmb->SetSelection(idx);
50  m_LastSel = idx;
51  FillList();
52 
53  Fit();
54 }
55 
57 {
58  //dtor
59 }
60 
62 {
63  wxChoice* cmb = XRCCTRL(*this, "cmbProject", wxChoice);
64  wxCheckListBox* lst = XRCCTRL(*this, "lstDeps", wxCheckListBox);
65 
66  if (m_LastSel == -1)
67  return true;
68 
69  cbProject* thisprj = static_cast<cbProject*>(cmb->GetClientData(m_LastSel));
70  if (!thisprj)
71  return true;
72 
73  // first clear all deps for this project
75 
76  // now set the the new deps
77  for (size_t i = 0; i < lst->GetCount(); ++i)
78  {
79  if (!lst->IsChecked(i))
80  continue;
81 
82  cbProject* prj = nullptr;
83 
84  ProjectsArray* mainarr = Manager::Get()->GetProjectManager()->GetProjects();
85  for (size_t x = 0; x < mainarr->GetCount(); ++x)
86  {
87  if (mainarr->Item(x)->GetTitle() == lst->GetString(i))
88  {
89  prj = mainarr->Item(x);
90  break;
91  }
92  }
93  if (!prj)
94  continue;
95 
96  if (!Manager::Get()->GetProjectManager()->AddProjectDependency(thisprj, prj))
97  {
98  cbMessageBox(wxString::Format(_("Cannot add project '%s' as a dependency to '%s' because this "
99  "would cause a circular dependency error..."),
100  thisprj->GetTitle().c_str(), prj->GetTitle().c_str()),
101  _("Error"), wxICON_ERROR, this);
102  return false;
103  }
104  }
105  return true;
106 }
107 
109 {
110  wxChoice* cmb = XRCCTRL(*this, "cmbProject", wxChoice);
111  wxCheckListBox* lst = XRCCTRL(*this, "lstDeps", wxCheckListBox);
112 
113  int idx = cmb->GetSelection();
114  if (m_LastSel != idx && m_LastSel != -1)
115  {
116  // save old list
117  SaveList();
118  }
119  m_LastSel = idx;
120  if (idx == -1)
121  return;
122 
123  cbProject* thisprj = static_cast<cbProject*>(cmb->GetClientData(idx));
124  if (!thisprj)
125  return;
126  const ProjectsArray* arr = Manager::Get()->GetProjectManager()->GetDependenciesForProject(thisprj);
127 
128  lst->Clear();
129  ProjectsArray* mainarr = Manager::Get()->GetProjectManager()->GetProjects();
130  for (size_t i = 0; i < mainarr->GetCount(); ++i)
131  {
132  cbProject* prj = mainarr->Item(i);
133  if (prj == thisprj)
134  continue;
135  lst->Append(prj->GetTitle());
136 
137  // check dependency
138  lst->Check(lst->GetCount() - 1, arr && arr->Index(prj) != wxNOT_FOUND);
139  }
140 }
141 
143 {
144  FillList();
145 }
146 
147 void ProjectDepsDlg::EndModal(int retCode)
148 {
149  if (SaveList())
150  return wxScrollingDialog::EndModal(retCode);
151 }
void EndModal(int retCode)
Definition: sc_dialog.cpp:112
void OnProjectChange(wxCommandEvent &event)
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
Definition: manager.cpp:182
virtual int GetSelection() const
virtual wxString GetString(unsigned int n) const
#define wxICON_ERROR
virtual void EndModal(int retCode)
wxCStrData c_str() const
#define _T(string)
bool IsChecked(unsigned int item) const
#define wxNOT_FOUND
ProjectManager * GetProjectManager() const
Functions returning pointers to the respective sub-manager instances.
Definition: manager.cpp:429
Represents a Code::Blocks project.
Definition: cbproject.h:96
virtual const wxString & GetTitle() const
Read the target&#39;s title.
void Check(unsigned int item, bool check=true)
const wxString & _(const wxString &string)
virtual ~ProjectDepsDlg()
static wxXmlResource * Get()
ProjectsArray * GetProjects()
Retrieve an array of all the opened projects.
virtual void SetSelection(int n)
static wxString Format(const wxString &format,...)
wxObject * LoadObject(wxWindow *parent, const wxString &name, const wxString &classname)
virtual unsigned int GetCount() const
const ProjectsArray * GetDependenciesForProject(cbProject *base)
Get the array of projects base depends on.
DLLIMPORT int cbMessageBox(const wxString &message, const wxString &caption=wxEmptyString, int style=wxOK, wxWindow *parent=NULL, int x=-1, int y=-1)
wxMessageBox wrapper.
Definition: globals.cpp:1395
void ClearProjectDependencies(cbProject *base)
Removes all dependencies from project base.