Code::Blocks  SVN r11506
debuggeroptionsprjdlg.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3  * http://www.gnu.org/licenses/gpl-3.0.html
4  *
5  * $Revision: 9231 $
6  * $Id: debuggeroptionsprjdlg.cpp 9231 2013-07-25 18:58:24Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/debuggergdb/debuggeroptionsprjdlg.cpp $
8  */
9 
10 #include <sdk.h>
11 #include "debuggeroptionsprjdlg.h"
12 #include <wx/intl.h>
13 #include <wx/xrc/xmlres.h>
14 #include <wx/listbox.h>
15 #include <wx/button.h>
16 #include <wx/choice.h>
17 #include <wx/checkbox.h>
18 #include <cbproject.h>
19 #include <editpathdlg.h>
20 #include <manager.h>
21 #include <globals.h>
22 
23 #include "debuggergdb.h"
24 
25 BEGIN_EVENT_TABLE(DebuggerOptionsProjectDlg, wxPanel)
26  EVT_UPDATE_UI(-1, DebuggerOptionsProjectDlg::OnUpdateUI)
27  EVT_BUTTON(XRCID("btnAdd"), DebuggerOptionsProjectDlg::OnAdd)
28  EVT_BUTTON(XRCID("btnEdit"), DebuggerOptionsProjectDlg::OnEdit)
29  EVT_BUTTON(XRCID("btnDelete"), DebuggerOptionsProjectDlg::OnDelete)
30  EVT_LISTBOX(XRCID("lstTargets"), DebuggerOptionsProjectDlg::OnTargetSel)
31 END_EVENT_TABLE()
32 
34  : m_pDBG(debugger),
35  m_pProject(project),
36  m_LastTargetSel(-1)
37 {
38  if (!wxXmlResource::Get()->LoadPanel(this, parent, _T("pnlDebuggerProjectOptions")))
39  return;
40 
41  m_OldPaths = m_pDBG->GetSearchDirs(project);
42  m_CurrentRemoteDebugging = m_pDBG->GetRemoteDebuggingMap(project);
43 
44  wxListBox* control = XRCCTRL(*this, "lstSearchDirs", wxListBox);
45  control->Clear();
46  for (size_t i = 0; i < m_OldPaths.GetCount(); ++i)
47  {
48  control->Append(m_OldPaths[i]);
49  }
50 
51  control = XRCCTRL(*this, "lstTargets", wxListBox);
52  control->Clear();
53  control->Append(_("<Project>"));
54  for (int i = 0; i < project->GetBuildTargetsCount(); ++i)
55  {
56  control->Append(project->GetBuildTarget(i)->GetTitle());
57  }
58  control->SetSelection(-1);
59 
60  LoadCurrentRemoteDebuggingRecord();
64 }
65 
67 {
69 }
70 
72 {
73  cbProject* project = event.GetProject();
74  if(project != m_pProject)
75  {
76  return;
77  }
78  wxString theTarget = event.GetBuildTargetName();
79  ProjectBuildTarget* bt = project->GetBuildTarget(theTarget);
80 
81  wxListBox* lstBox = XRCCTRL(*this, "lstTargets", wxListBox);
82  int idx = lstBox->FindString(theTarget);
83  if (idx > 0)
84  {
85  lstBox->Delete(idx);
86  }
87  if((size_t)idx >= lstBox->GetCount())
88  {
89  idx--;
90  }
91  lstBox->SetSelection(idx);
92  // remove the target from the map to ensure that there are no dangling pointers in it.
93  m_CurrentRemoteDebugging.erase(bt);
95 }
96 
98 {
99  cbProject* project = event.GetProject();
100  if(project != m_pProject)
101  {
102  return;
103  }
104  wxString newTarget = event.GetBuildTargetName();
105  wxString oldTarget = event.GetOldBuildTargetName();
106  if(!oldTarget.IsEmpty())
107  {
108  for (RemoteDebuggingMap::iterator it = m_CurrentRemoteDebugging.begin(); it != m_CurrentRemoteDebugging.end(); ++it)
109  {
110  // find our target
111  if ( !it->first || it->first->GetTitle() != oldTarget)
112  continue;
113  ProjectBuildTarget* bt = m_pProject->GetBuildTarget(newTarget);
114  if(bt)
115  m_CurrentRemoteDebugging.insert(m_CurrentRemoteDebugging.end(), std::make_pair(bt, it->second));
116  // if we inserted it, just break, there can only be one map per target
117  break;
118  }
119  }
120  wxListBox* lstBox = XRCCTRL(*this, "lstTargets", wxListBox);
121  int idx = lstBox->FindString(newTarget);
122  if (idx == wxNOT_FOUND)
123  {
124  idx = lstBox->Append(newTarget);
125  }
126  lstBox->SetSelection(idx);
128 }
129 
131 {
132  cbProject* project = event.GetProject();
133  if(project != m_pProject)
134  {
135  return;
136  }
137  wxString newTarget = event.GetBuildTargetName();
138  wxString oldTarget = event.GetOldBuildTargetName();
139  for (RemoteDebuggingMap::iterator it = m_CurrentRemoteDebugging.begin(); it != m_CurrentRemoteDebugging.end(); ++it)
140  {
141  // find our target
142  if ( !it->first || it->first->GetTitle() != oldTarget)
143  continue;
144  it->first->SetTitle(newTarget);
145  // if we renamed it, just break, there can only be one map per target
146  break;
147  }
148 
149  wxListBox* lstBox = XRCCTRL(*this, "lstTargets", wxListBox);
150  int idx = lstBox->FindString(oldTarget);
151  if (idx == wxNOT_FOUND)
152  {
153  return;
154  }
155  lstBox->SetString(idx, newTarget);
156  lstBox->SetSelection(idx);
158 }
159 
161 {
162  // -1 because entry 0 is "<Project>"
163  m_LastTargetSel = XRCCTRL(*this, "lstTargets", wxListBox)->GetSelection() - 1;
164 
167  {
169  XRCCTRL(*this, "cmbConnType", wxChoice)->SetSelection((int)rd.connType);
170  XRCCTRL(*this, "txtSerial", wxTextCtrl)->SetValue(rd.serialPort);
171  XRCCTRL(*this, "cmbBaud", wxChoice)->SetStringSelection(rd.serialBaud);
172  XRCCTRL(*this, "txtIP", wxTextCtrl)->SetValue(rd.ip);
173  XRCCTRL(*this, "txtPort", wxTextCtrl)->SetValue(rd.ipPort);
174  XRCCTRL(*this, "txtCmds", wxTextCtrl)->SetValue(rd.additionalCmds);
175  XRCCTRL(*this, "txtCmdsBefore", wxTextCtrl)->SetValue(rd.additionalCmdsBefore);
176  XRCCTRL(*this, "chkSkipLDpath", wxCheckBox)->SetValue(rd.skipLDpath);
177  XRCCTRL(*this, "chkExtendedRemote", wxCheckBox)->SetValue(rd.extendedRemote);
178  XRCCTRL(*this, "txtShellCmdsAfter", wxTextCtrl)->SetValue(rd.additionalShellCmdsAfter);
179  XRCCTRL(*this, "txtShellCmdsBefore", wxTextCtrl)->SetValue(rd.additionalShellCmdsBefore);
180  }
181  else
182  {
183  XRCCTRL(*this, "cmbConnType", wxChoice)->SetSelection(0);
184  XRCCTRL(*this, "txtSerial", wxTextCtrl)->SetValue(wxEmptyString);
185  XRCCTRL(*this, "cmbBaud", wxChoice)->SetSelection(0);
186  XRCCTRL(*this, "txtIP", wxTextCtrl)->SetValue(wxEmptyString);
187  XRCCTRL(*this, "txtPort", wxTextCtrl)->SetValue(wxEmptyString);
188  XRCCTRL(*this, "txtCmds", wxTextCtrl)->SetValue(wxEmptyString);
189  XRCCTRL(*this, "txtCmdsBefore", wxTextCtrl)->SetValue(wxEmptyString);
190  XRCCTRL(*this, "chkSkipLDpath", wxCheckBox)->SetValue(false);
191  XRCCTRL(*this, "chkExtendedRemote", wxCheckBox)->SetValue(false);
192  XRCCTRL(*this, "txtShellCmdsAfter", wxTextCtrl)->SetValue(wxEmptyString);
193  XRCCTRL(*this, "txtShellCmdsBefore", wxTextCtrl)->SetValue(wxEmptyString);
194  }
195 }
196 
198 {
199 // if (m_LastTargetSel == -1)
200 // return;
201 
203 // if (!bt)
204 // return;
205 
206  RemoteDebuggingMap::iterator it = m_CurrentRemoteDebugging.find(bt);
207  if (it == m_CurrentRemoteDebugging.end())
208  it = m_CurrentRemoteDebugging.insert(m_CurrentRemoteDebugging.end(), std::make_pair(bt, RemoteDebugging()));
209 
210  RemoteDebugging& rd = it->second;
211 
212  rd.connType = (RemoteDebugging::ConnectionType)XRCCTRL(*this, "cmbConnType", wxChoice)->GetSelection();
213  rd.serialPort = XRCCTRL(*this, "txtSerial", wxTextCtrl)->GetValue();
214  rd.serialBaud = XRCCTRL(*this, "cmbBaud", wxChoice)->GetStringSelection();
215  rd.ip = XRCCTRL(*this, "txtIP", wxTextCtrl)->GetValue();
216  rd.ipPort = XRCCTRL(*this, "txtPort", wxTextCtrl)->GetValue();
217  rd.additionalCmds = XRCCTRL(*this, "txtCmds", wxTextCtrl)->GetValue();
218  rd.additionalCmdsBefore = XRCCTRL(*this, "txtCmdsBefore", wxTextCtrl)->GetValue();
219  rd.skipLDpath = XRCCTRL(*this, "chkSkipLDpath", wxCheckBox)->GetValue();
220  rd.extendedRemote = XRCCTRL(*this, "chkExtendedRemote", wxCheckBox)->GetValue();
221  rd.additionalShellCmdsAfter = XRCCTRL(*this, "txtShellCmdsAfter", wxTextCtrl)->GetValue();
222  rd.additionalShellCmdsBefore = XRCCTRL(*this, "txtShellCmdsBefore", wxTextCtrl)->GetValue();
223 }
224 
226 {
227  // update remote debugging controls
230 }
231 
233 {
234  wxListBox* control = XRCCTRL(*this, "lstSearchDirs", wxListBox);
235 
236  EditPathDlg dlg(this,
237  m_pProject ? m_pProject->GetBasePath() : _T(""),
238  m_pProject ? m_pProject->GetBasePath() : _T(""),
239  _("Add directory"));
240 
241  PlaceWindow(&dlg);
242  if (dlg.ShowModal() == wxID_OK)
243  {
244  wxString path = dlg.GetPath();
245  control->Append(path);
246  }
247 }
248 
250 {
251  wxListBox* control = XRCCTRL(*this, "lstSearchDirs", wxListBox);
252  int sel = control->GetSelection();
253  if (sel < 0)
254  return;
255 
256  EditPathDlg dlg(this,
257  control->GetString(sel),
258  m_pProject ? m_pProject->GetBasePath() : _T(""),
259  _("Edit directory"));
260 
261  PlaceWindow(&dlg);
262  if (dlg.ShowModal() == wxID_OK)
263  {
264  wxString path = dlg.GetPath();
265  control->SetString(sel, path);
266  }
267 }
268 
270 {
271  wxListBox* control = XRCCTRL(*this, "lstSearchDirs", wxListBox);
272  int sel = control->GetSelection();
273  if (sel < 0)
274  return;
275 
276  control->Delete(sel);
277 }
278 
280 {
281  wxListBox* control = XRCCTRL(*this, "lstSearchDirs", wxListBox);
282  bool en = control->GetSelection() >= 0;
283 
284  XRCCTRL(*this, "btnEdit", wxButton)->Enable(en);
285  XRCCTRL(*this, "btnDelete", wxButton)->Enable(en);
286 
287  en = XRCCTRL(*this, "lstTargets", wxListBox)->GetSelection() != wxNOT_FOUND;
288 
289  XRCCTRL(*this, "cmbConnType", wxChoice)->Enable(en);
290  XRCCTRL(*this, "txtSerial", wxTextCtrl)->Enable(en);
291  XRCCTRL(*this, "cmbBaud", wxChoice)->Enable(en);
292  XRCCTRL(*this, "txtIP", wxTextCtrl)->Enable(en);
293  XRCCTRL(*this, "txtPort", wxTextCtrl)->Enable(en);
294  XRCCTRL(*this, "txtCmds", wxTextCtrl)->Enable(en);
295  XRCCTRL(*this, "txtCmdsBefore", wxTextCtrl)->Enable(en);
296  XRCCTRL(*this, "chkSkipLDpath", wxCheckBox)->Enable(en);
297  XRCCTRL(*this, "chkExtendedRemote", wxCheckBox)->Enable(en);
298  XRCCTRL(*this, "txtShellCmdsAfter", wxTextCtrl)->Enable(en);
299  XRCCTRL(*this, "txtShellCmdsBefore", wxTextCtrl)->Enable(en);
300 }
301 
303 {
304  wxListBox* control = XRCCTRL(*this, "lstSearchDirs", wxListBox);
305 
306  m_OldPaths.Clear();
307  for (int i = 0; i < (int)control->GetCount(); ++i)
308  {
309  m_OldPaths.Add(control->GetString(i));
310  }
311 
313 
316 }
RemoteDebuggingMap m_CurrentRemoteDebugging
EVTIMPORT const wxEventType cbEVT_BUILDTARGET_RENAMED
Definition: sdk_events.cpp:118
wxArrayString & GetSearchDirs(cbProject *prj)
void OnAdd(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
wxString additionalCmds
commands after remote connection established
void OnEdit(wxCommandEvent &event)
void OnDelete(wxCommandEvent &event)
wxString additionalShellCmdsAfter
shell commands after remote connection established
#define _T(string)
void OnBuildTargetAdded(CodeBlocksEvent &event)
#define wxNOT_FOUND
A generic Code::Blocks event.
Definition: sdk_events.h:20
wxString additionalCmdsBefore
commands before establishing remote connection
void OnBuildTargetRenamed(CodeBlocksEvent &event)
Event functor class.
Definition: cbfunctor.h:37
Represents a Code::Blocks project.
Definition: cbproject.h:96
bool extendedRemote
connect with extended remote or not
void RemoveAllEventSinksFor(void *owner)
Definition: manager.cpp:570
EVTIMPORT const wxEventType cbEVT_BUILDTARGET_REMOVED
Definition: sdk_events.cpp:117
virtual wxString GetBasePath() const
Read the target&#39;s base path, e.g. if GetFilename() returns "/usr/local/bin/xxx", base path will retur...
wxString wxEmptyString
const wxString & _(const wxString &string)
ProjectBuildTarget * GetBuildTarget(int index)
Access a build target.
Definition: cbproject.cpp:1392
bool IsEmpty() const
DLLIMPORT void PlaceWindow(wxTopLevelWindow *w, cbPlaceDialogMode mode=pdlBest, bool enforce=false)
Definition: globals.cpp:1177
RemoteDebuggingMap & GetRemoteDebuggingMap(cbProject *project=0)
virtual void OnApply()
Called when the user chooses to apply the configuration.
void RegisterEventSink(wxEventType eventType, IEventFunctorBase< CodeBlocksEvent > *functor)
Definition: manager.cpp:550
size_t Add(const wxString &str, size_t copies=1)
wxString additionalShellCmdsBefore
shell commands before establishing remote connection
Represents a Code::Blocks project build target.
void OnTargetSel(wxCommandEvent &event)
static wxXmlResource * Get()
EVTIMPORT const wxEventType cbEVT_BUILDTARGET_ADDED
Definition: sdk_events.cpp:116
bool skipLDpath
skip adjusting LD_LIBRARY_PATH before launching debugger
ConnectionType connType
void OnUpdateUI(wxUpdateUIEvent &event)
void OnBuildTargetRemoved(CodeBlocksEvent &event)