Code::Blocks  SVN r11506
debuggersettingsdlg.cpp
Go to the documentation of this file.
1 #include "sdk.h"
2 #include "debuggersettingsdlg.h"
3 
4 #ifndef CB_PRECOMP
5  //(*InternalHeadersPCH(DebuggerSettingsDlg)
6  #include <wx/string.h>
7  #include <wx/intl.h>
8  //*)
9 
10  #include <wx/choicdlg.h>
11 
12  #include "cbexception.h"
13  #include "cbplugin.h"
14 #endif
15 //(*InternalHeaders(DebuggerSettingsDlg)
16 #include <wx/button.h>
17 #include <wx/font.h>
18 //*)
19 
20 #include "debuggermanager.h"
21 #include "debuggersettingspanel.h"
23 
24 //(*IdInit(DebuggerSettingsDlg)
27 //*)
28 
29 BEGIN_EVENT_TABLE(DebuggerSettingsDlg, wxScrollingDialog)
30  //(*EventTable(DebuggerSettingsDlg)
31  //*)
32  EVT_BUTTON(wxID_OK, DebuggerSettingsDlg::OnOK)
33 END_EVENT_TABLE()
34 
36 {
37  //(*Initialize(DebuggerSettingsDlg)
38  wxStaticLine* staticLine;
39  wxBoxSizer* headerSizer;
40  wxBoxSizer* mainSizer;
41  wxStdDialogButtonSizer* stdDialogButtons;
42  wxPanel* header;
43 
45  mainSizer = new wxBoxSizer(wxVERTICAL);
47  header->SetBackgroundColour(wxColour(0,64,128));
48  headerSizer = new wxBoxSizer(wxHORIZONTAL);
49  m_activeInfo = new wxStaticText(header, ID_LABEL_ACTIVE_INFO, _("Active debugger config"), wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTRANSPARENT_WINDOW, _T("ID_LABEL_ACTIVE_INFO"));
50  m_activeInfo->SetForegroundColour(wxColour(255,255,255));
51  m_activeInfo->SetBackgroundColour(wxColour(0,64,128));
53  m_activeInfo->SetFont(m_activeInfoFont);
54  headerSizer->Add(m_activeInfo, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5);
55  header->SetSizer(headerSizer);
56  headerSizer->Fit(header);
57  headerSizer->SetSizeHints(header);
58  mainSizer->Add(header, 0, wxEXPAND, 5);
59  m_treebook = new wxTreebook(this, ID_TREEBOOK, wxDefaultPosition, wxDefaultSize, wxBK_DEFAULT, _T("ID_TREEBOOK"));
60  mainSizer->Add(m_treebook, 1, wxALL|wxEXPAND, 5);
61  staticLine = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("wxID_ANY"));
62  mainSizer->Add(staticLine, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 5);
63  stdDialogButtons = new wxStdDialogButtonSizer();
64  stdDialogButtons->AddButton(new wxButton(this, wxID_OK, wxEmptyString));
65  stdDialogButtons->AddButton(new wxButton(this, wxID_CANCEL, wxEmptyString));
66  stdDialogButtons->Realize();
67  mainSizer->Add(stdDialogButtons, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 5);
68  SetSizer(mainSizer);
69  mainSizer->Fit(this);
70  mainSizer->SetSizeHints(this);
71  Center();
72 
73  Connect(ID_TREEBOOK,wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED,(wxObjectEventFunction)&DebuggerSettingsDlg::OnPageChanged);
74  //*)
75 
76  m_commonPanel = new DebuggerSettingsCommonPanel(m_treebook);
77  m_treebook->AddPage(m_commonPanel, _("Common"));
78 
80  for (DebuggerManager::RegisteredPlugins::const_iterator it = plugins.begin(); it != plugins.end(); ++it)
81  {
82  const DebuggerManager::PluginData &data = it->second;
83  m_treebook->AddPage(new DebuggerSettingsPanel(m_treebook, this, it->first), it->first->GetGUIName());
84 
85  for (DebuggerManager::ConfigurationVector::const_iterator itConfig = data.GetConfigurations().begin();
86  itConfig != data.GetConfigurations().end();
87  ++itConfig)
88  {
89  wxPanel *panel = (*itConfig)->MakePanel(m_treebook);
90  m_treebook->AddSubPage(panel, (*itConfig)->GetName());
91 
92  Config conf;
93  conf.plugin = it->first;
94  conf.pluginGUIName = it->first->GetGUIName();
95  conf.config = (*itConfig)->Clone();
96  m_mapPanelToConfig[panel] = conf;
97  }
98  }
99 
100  for (size_t ii = 0; ii < m_treebook->GetPageCount(); ++ii)
101  m_treebook->ExpandNode(ii);
102 
103  mainSizer->SetSizeHints(this);
104  CentreOnParent();
105 }
106 
108 {
109  for (MapPanelToConfiguration::iterator it = m_mapPanelToConfig.begin(); it != m_mapPanelToConfig.end(); ++it)
110  delete it->second.config;
111  m_mapPanelToConfig.clear();
112 
113  //(*Destroy(DebuggerSettingsDlg)
114  //*)
115 }
116 
118 {
119  wxString t;
120 
122 
124 
125  const DebuggerManager::RegisteredPlugins &plugins = dbgManager->GetAllDebuggers();
126  ConfigManager *mainConfig = Manager::Get()->GetConfigManager(wxT("debugger_common"));
127 
128  for (DebuggerManager::RegisteredPlugins::const_iterator it = plugins.begin(); it != plugins.end(); ++it)
129  {
130  wxString path(wxT("/sets/"));
131  path << it->first->GetSettingsName();
132 
133  mainConfig->DeleteSubPath(path);
134  }
135 
136  for (size_t ii = 0; ii < m_treebook->GetPageCount(); ++ii)
137  {
138  wxWindow *page = m_treebook->GetPage(ii);
139  MapPanelToConfiguration::iterator it = m_mapPanelToConfig.find(page);
140  if (it != m_mapPanelToConfig.end())
141  {
142  cbDebuggerConfiguration *c = it->second.config;
143 
144  if (!c->GetConfig().IsValid())
145  c->SetConfig(dbgManager->NewConfig(it->second.plugin, c->GetName()));
146  if (!c->GetConfig().IsValid())
147  break;
148 
149  wxString namePath = c->GetConfig().GetBasepath();
150  namePath.Remove(namePath.length() - 7); // trim the "values/" from the path
151  mainConfig->Write(namePath + wxT("name"), c->GetName());
152 
153  t += it->second.pluginGUIName + wxT(" - ") + c->GetName() + wxT("\n");
154  if (!c->SaveChanges(static_cast<wxPanel*>(it->first)))
155  break;
156  }
157  }
158 
159  int normalIndex = -1;
160  dbgManager->GetLogger(normalIndex);
161 
162  cbDebuggerPlugin *activePlugin = dbgManager->GetActiveDebugger();
163  for (DebuggerManager::RegisteredPlugins::const_iterator it = plugins.begin(); it != plugins.end(); ++it)
164  {
165  it->first->SetupLog(normalIndex);
166  it->first->OnConfigurationChange(activePlugin == it->first);
167  }
168 
169  dbgManager->RebuildAllConfigs();
170 
171  EndModal(wxID_OK);
172 }
173 
174 inline size_t FindPageIndex(wxTreebook *treebook, wxWindow *page)
175 {
176  size_t pageIndex = treebook->GetPageCount();
177  for (size_t p = 0; p < treebook->GetPageCount(); ++p)
178  {
179  if (treebook->GetPage(p) == page)
180  {
181  pageIndex = p;
182  break;
183  }
184  }
185  return pageIndex;
186 }
187 
188 // only return false when the name is not unique
190 {
191  size_t pageIndex = FindPageIndex(m_treebook, panel);
192  if (pageIndex == m_treebook->GetPageCount())
193  return true;
194 
195  for (size_t p = 0; p < m_treebook->GetPageCount(); ++p)
196  {
197  if (m_treebook->GetPageParent(p) == static_cast<int>(pageIndex) && m_treebook->GetPageText(p) == name)
198  return false;
199  }
200 
201  cbDebuggerConfiguration *pluginConfig = plugin->LoadConfig(ConfigManagerWrapper());
202  if (!pluginConfig)
203  return true;
204  pluginConfig->SetName(name);
205 
206  wxPanel *subPanel = pluginConfig->MakePanel(m_treebook);
207  m_treebook->InsertSubPage(pageIndex, subPanel, pluginConfig->GetName());
208 
209  Config conf;
210  conf.plugin = plugin;
211  conf.pluginGUIName = plugin->GetGUIName();
212  conf.config = pluginConfig;
213  m_mapPanelToConfig[subPanel] = conf;
214  return true;
215 }
216 
218 {
219  size_t pageIndex = FindPageIndex(m_treebook, panel);
220  if (pageIndex == m_treebook->GetPageCount())
221  return;
222 
223  wxArrayString choices;
224  std::vector<wxWindow*> panels;
225  for (size_t p = 0; p < m_treebook->GetPageCount(); ++p)
226  {
227  if (m_treebook->GetPageParent(p) == static_cast<int>(pageIndex) && p != pageIndex)
228  {
229  choices.push_back(m_treebook->GetPageText(p));
230  panels.push_back(m_treebook->GetPage(p));
231  }
232  }
233 
234  wxMultiChoiceDialog dialog(panel, _("Choose which configurations to be deleted"), _("Choose"), choices);
235  PlaceWindow(&dialog);
236  while (dialog.ShowModal() == wxID_OK)
237  {
238  const wxArrayInt &selection = dialog.GetSelections();
239  if (selection.GetCount() == choices.GetCount())
240  {
241  cbMessageBox(_("Can't delete all configurations. There should be at least one."),
242  _("Error"), wxICON_ERROR, this);
243  continue;
244  }
245  for (size_t s = 0; s < selection.GetCount(); ++s)
246  {
247  int index = selection[s];
248  size_t p = FindPageIndex(m_treebook, panels[index]);
249  if (p < m_treebook->GetPageCount())
250  {
251  MapPanelToConfiguration::iterator it = m_mapPanelToConfig.find(panels[index]);
252  cbAssert(plugin == it->second.plugin);
253  delete it->second.config;
254 
255  m_mapPanelToConfig.erase(it);
257  }
258  }
259  break;
260  }
261 }
262 
264 {
265  size_t pageIndex = FindPageIndex(m_treebook, panel);
266  if (pageIndex == m_treebook->GetPageCount())
267  return;
268 
269  for (size_t p = m_treebook->GetPageCount(); p > 0; --p)
270  {
271  size_t index = p - 1;
272  if (m_treebook->GetPageParent(index) == static_cast<int>(pageIndex))
273  {
274  wxString title = m_treebook->GetPageText(index);
275  MapPanelToConfiguration::iterator it = m_mapPanelToConfig.find(m_treebook->GetPage(index));
276  cbAssert(plugin == it->second.plugin);
277  delete it->second.config;
278 
279  m_mapPanelToConfig.erase(it);
280  m_treebook->DeletePage(index);
281  }
282  }
283 
284  CreateConfig(panel, plugin, wxT("Default"));
285 }
286 
287 void DebuggerSettingsDlg::OnPageChanged(wxNotebookEvent& event)
288 {
289  wxString caption = m_treebook->GetPageText(event.GetSelection());
290  int parent = m_treebook->GetPageParent(event.GetSelection());
291  if (parent != wxNOT_FOUND)
292  caption = m_treebook->GetPageText(parent) + wxT(" : ") + caption;
293  m_activeInfo->SetLabel(caption);
294 }
wxSize Fit(wxWindow *window)
void EndModal(int retCode)
Definition: sc_dialog.cpp:112
#define wxMAXIMIZE_BOX
MapPanelToConfiguration m_mapPanelToConfig
cbDebuggerPlugin * GetActiveDebugger()
cbDebuggerConfiguration * config
TextCtrlLogger * GetLogger(int &index)
int wxNewId()
static const long ID_LABEL_ACTIVE_INFO
ConfigurationVector & GetConfigurations()
void SetupLog(int normalIndex)
Definition: cbplugin.cpp:561
ConfigManager * GetConfigManager(const wxString &name_space) const
Definition: manager.cpp:474
Base class for debugger plugins.
Definition: cbplugin.h:397
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
wxArrayInt GetSelections() const
size_t length() const
void OnOK(wxCommandEvent &event)
#define wxICON_ERROR
static const long ID_TREEBOOK
const wxString & GetName() const
virtual size_t GetPageCount() const
#define _T(string)
virtual bool SaveChanges(wxPanel *panel)=0
void OnPageChanged(wxNotebookEvent &event)
void AddButton(wxButton *button)
wxString & Remove(size_t pos)
virtual wxPanel * MakePanel(wxWindow *parent)=0
#define wxT(string)
#define wxNOT_FOUND
void DeleteConfig(wxWindow *panel, cbDebuggerPlugin *plugin)
void SetName(const wxString &name)
DebuggerSettingsCommonPanel * m_commonPanel
void Write(const wxString &name, const wxString &value, bool ignoreEmpty=false)
DebuggerManager * GetDebuggerManager() const
Definition: manager.cpp:484
wxSizerItem * Add(wxWindow *window, const wxSizerFlags &flags)
virtual bool DeletePage(size_t pagePos)
const wxSize wxDefaultSize
const wxPoint wxDefaultPosition
wxStaticText * m_activeInfo
#define wxCAPTION
virtual cbDebuggerConfiguration * LoadConfig(const ConfigManagerWrapper &config)=0
#define wxDEFAULT_DIALOG_STYLE
virtual cbDebuggerConfiguration * Clone() const =0
wxString wxEmptyString
int GetPageParent(size_t page) const
const wxString & GetBasepath() const
const wxString & _(const wxString &string)
std::map< cbDebuggerPlugin *, PluginData > RegisteredPlugins
#define cbAssert(expr)
Definition: cbexception.h:48
wxArray< int > wxArrayInt
virtual bool InsertSubPage(size_t pagePos, wxWindow *page, const wxString &text, bool bSelect=false, int imageId=wxNOT_FOUND)
void DeleteSubPath(const wxString &strPath)
DLLIMPORT void PlaceWindow(wxTopLevelWindow *w, cbPlaceDialogMode mode=pdlBest, bool enforce=false)
Definition: globals.cpp:1177
RegisteredPlugins const & GetAllDebuggers() const
wxString GetGUIName() const
Definition: cbplugin.h:618
size_t FindPageIndex(wxTreebook *treebook, wxWindow *page)
#define wxCLOSE_BOX
#define wxNO_BORDER
#define wxBK_DEFAULT
#define wxLI_HORIZONTAL
void SetConfig(const ConfigManagerWrapper &config)
void SetSizeHints(wxWindow *window)
bool CreateConfig(wxWindow *panel, cbDebuggerPlugin *plugin, const wxString &name)
virtual wxString GetPageText(size_t nPage) const=0
size_t GetCount() const
ConfigManagerWrapper NewConfig(cbDebuggerPlugin *plugin, const wxString &name)
#define wxMINIMIZE_BOX
#define wxTRANSPARENT_WINDOW
#define wxRESIZE_BORDER
const ConfigManagerWrapper & GetConfig() 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
void ResetConfig(wxWindow *panel, cbDebuggerPlugin *plugin)
bool IsValid() const
Wrapper class for reading or writing config values, without the need for the full path...