Code::Blocks  SVN r11506
virtualbuildtargetsdlg.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: 10982 $
6  * $Id: virtualbuildtargetsdlg.cpp 10982 2017-01-28 16:02:00Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/src/virtualbuildtargetsdlg.cpp $
8  */
9 
10 #include "sdk.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/xrc/xmlres.h>
22 //*)
23 
24 //(*IdInit(VirtualBuildTargetsDlg)
25 //*)
26 
28  //(*EventTable(VirtualBuildTargetsDlg)
29  //*)
30  EVT_UPDATE_UI(-1, VirtualBuildTargetsDlg::OnUpdateUI)
31 END_EVENT_TABLE()
32 
34  m_pProject(project)
35 {
36  //(*Initialize(VirtualBuildTargetsDlg)
37  wxXmlResource::Get()->LoadObject(this,parent,_T("VirtualBuildTargetsDlg"),_T("wxScrollingDialog"));
38  lstAliases = (wxListBox*)FindWindow(XRCID("ID_LST_ALIASES"));
39  btnAdd = (wxButton*)FindWindow(XRCID("ID_BTN_ADD"));
40  btnEdit = (wxButton*)FindWindow(XRCID("ID_BTN_EDIT"));
41  btnRemove = (wxButton*)FindWindow(XRCID("ID_BTN_REMOVE"));
42  lstTargets = (wxCheckListBox*)FindWindow(XRCID("ID_LST_TARGETS"));
43 
44  Connect(XRCID("ID_LST_ALIASES"),wxEVT_COMMAND_LISTBOX_SELECTED,(wxObjectEventFunction)&VirtualBuildTargetsDlg::OnAliasesSelect);
45  Connect(XRCID("ID_BTN_ADD"),wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&VirtualBuildTargetsDlg::OnAddClick);
46  Connect(XRCID("ID_BTN_EDIT"),wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&VirtualBuildTargetsDlg::OnEditClick);
47  Connect(XRCID("ID_BTN_REMOVE"),wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&VirtualBuildTargetsDlg::OnRemoveClick);
48  Connect(XRCID("ID_LST_TARGETS"),wxEVT_COMMAND_CHECKLISTBOX_TOGGLED,(wxObjectEventFunction)&VirtualBuildTargetsDlg::OnTargetsToggled);
49  //*)
50  XRCCTRL(*this, "wxID_OK", wxButton)->SetDefault();
51 
52  // fill aliases
53  wxArrayString virtuals = m_pProject->GetVirtualBuildTargets();
54  lstAliases->Set(virtuals);
55 
56  if (lstAliases->GetCount() > 0)
57  lstAliases->SetSelection(0);
58 
59  // fill build targets
60  for (int i = 0; i < m_pProject->GetBuildTargetsCount(); ++i)
61  lstTargets->Append(m_pProject->GetBuildTarget(i)->GetTitle());
62  CheckTargets();
63 }
64 
66 {
67  //(*Destroy(VirtualBuildTargetsDlg)
68  //*)
69 }
70 
72 {
73  if (!lstTargets->IsEnabled() || lstTargets->IsEmpty())
74  return;
75 
76  wxArrayString checked;
77  for (size_t i = 0; i < lstTargets->GetCount(); ++i)
78  {
79  if (lstTargets->IsChecked(i))
80  checked.Add(lstTargets->GetString(i));
81  }
82 
83  if (checked.GetCount() == 0)
84  {
85  cbMessageBox(_("This virtual build target is invalid.\n"
86  "A virtual target must have at least one active target.\n"
87  "Did you want to remove the virtual build target?"), _("Error"), wxICON_ERROR, this);
88  }
89  else if (checked.GetCount() > 0)
90  {
91  if ( !m_pProject->DefineVirtualBuildTarget(targetName, checked) )
92  cbMessageBox(_("Failed to setup this virtual build target.\n"
93  "Check the debug log for more info..."), _("Error"), wxICON_ERROR, this);
94  }
95 }
96 
98 {
99  const wxArrayString& group = m_pProject->GetVirtualBuildTargetGroup( lstAliases->GetStringSelection() );
100  for (int i = 0; i < m_pProject->GetBuildTargetsCount(); ++i)
101  {
102  wxString tgtName = m_pProject->GetBuildTarget(i)->GetTitle();
103  bool check = group.Index(tgtName) != wxNOT_FOUND;
104  lstTargets->Check(i, check);
105  }
106 }
107 
109 {
110  bool hasSel = lstAliases->GetSelection() != -1;
111  btnEdit->Enable(hasSel);
112  btnRemove->Enable(hasSel);
113  lstTargets->Enable(hasSel);
114 }
115 
117 {
118  wxString targetName = cbGetTextFromUser(_("Enter the new virtual build target name:"),
119  _("New virtual build target"));
120  if (targetName.IsEmpty())
121  return;
122 
123  if (lstAliases->FindString(targetName, true) != wxNOT_FOUND)
124  {
125  cbMessageBox(_("A virtual build target with this name already exists in this project!"),
126  _("Error"),
127  wxOK | wxCENTRE | wxICON_ERROR, this);
128  return;
129  }
130 
131  if (m_pProject->GetBuildTarget(targetName))
132  {
133  cbMessageBox(_("A real build target with this name already exists in this project!"),
134  _("Error"),
135  wxOK | wxCENTRE | wxICON_ERROR, this);
136  return;
137  }
138 
139  // add it with an empty group
140  lstAliases->Append(targetName);
141  lstAliases->SetSelection(lstAliases->GetCount() - 1);
142  CheckTargets();
143 }
144 
146 {
147  wxString targetName = cbGetTextFromUser(_("Enter the new virtual build target name:"),
148  _("Edit virtual build target"),
149  lstAliases->GetStringSelection());
150 
151  // is name unchanged, or user cancelled?
152  if (targetName.IsEmpty() || targetName == lstAliases->GetStringSelection())
153  return;
154 
155  if (lstAliases->FindString(targetName, true) != wxNOT_FOUND)
156  {
157  cbMessageBox(_("A virtual build target with this name already exists in this project!"),
158  _("Error"),
159  wxOK | wxCENTRE | wxICON_ERROR, this);
160  return;
161  }
162 
163  if (m_pProject->GetBuildTarget(targetName))
164  {
165  cbMessageBox(_("A real build target with this name already exists in this project!"),
166  _("Error"),
167  wxOK | wxCENTRE | wxICON_ERROR, this);
168  return;
169  }
170 
171  m_pProject->RemoveVirtualBuildTarget(lstAliases->GetStringSelection());
172  lstAliases->SetString(lstAliases->GetSelection(), targetName);
173  SetVirtualTarget(targetName);
174 }
175 
177 {
178  if (cbMessageBox(_("Are you sure you want to remove this virtual build target?"), _("Confirmation"), wxYES_NO | wxICON_QUESTION, this) == wxID_NO)
179  return;
180  m_pProject->RemoveVirtualBuildTarget(lstAliases->GetStringSelection());
181  lstAliases->Delete(lstAliases->GetSelection());
182  lstAliases->SetSelection(0);
183  CheckTargets();
184 }
185 
187 {
188  CheckTargets();
189 }
190 
192 {
193  SetVirtualTarget(lstAliases->GetStringSelection());
194 }
void OnAliasesSelect(wxCommandEvent &event)
#define wxICON_QUESTION
bool DefineVirtualBuildTarget(const wxString &alias, const wxArrayString &targets)
Define a new virtual build target.
Definition: cbproject.cpp:1449
virtual wxString GetString(unsigned int n) const
void OnAddClick(wxCommandEvent &event)
#define wxICON_ERROR
void SetVirtualTarget(const wxString &targetName)
DLLIMPORT wxString cbGetTextFromUser(const wxString &message, const wxString &caption=cbGetTextFromUserPromptStr, const wxString &default_value=wxEmptyString, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord, bool centre=true)
Definition: globals.cpp:1465
int Index(const wxString &sz, bool bCase=true, bool bFromEnd=false) const
void OnRemoveClick(wxCommandEvent &event)
#define _T(string)
#define wxYES_NO
bool IsChecked(unsigned int item) const
#define wxNOT_FOUND
void OnEditClick(wxCommandEvent &event)
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)
void OnUpdateUI(wxUpdateUIEvent &event)
const wxArrayString & GetVirtualBuildTargetGroup(const wxString &alias) const
Access a virtual build target&#39;s group of build targets.
Definition: cbproject.cpp:1496
#define wxOK
const wxString & _(const wxString &string)
int GetBuildTargetsCount()
Definition: cbproject.h:200
ProjectBuildTarget * GetBuildTarget(int index)
Access a build target.
Definition: cbproject.cpp:1392
bool IsEmpty() const
size_t Add(const wxString &str, size_t copies=1)
size_t GetCount() const
bool RemoveVirtualBuildTarget(const wxString &alias)
Remove a virtual build target.
Definition: cbproject.cpp:1475
static wxXmlResource * Get()
void OnTargetsToggled(wxCommandEvent &event)
int wxWindowID
wxObject * LoadObject(wxWindow *parent, const wxString &name, const wxString &classname)
virtual unsigned int GetCount() const
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