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"
22 #include "debuggersettingscommonpanel.h"
23
24 //(*IdInit(DebuggerSettingsDlg)
25 const long DebuggerSettingsDlg::ID_LABEL_ACTIVE_INFO = wxNewId();
26 const long DebuggerSettingsDlg::ID_TREEBOOK = wxNewId();
27 //*)
28
BEGIN_EVENT_TABLE(DebuggerSettingsDlg,wxScrollingDialog)29 BEGIN_EVENT_TABLE(DebuggerSettingsDlg, wxScrollingDialog)
30 //(*EventTable(DebuggerSettingsDlg)
31 //*)
32 EVT_BUTTON(wxID_OK, DebuggerSettingsDlg::OnOK)
33 END_EVENT_TABLE()
34
35 DebuggerSettingsDlg::DebuggerSettingsDlg(wxWindow* parent)
36 {
37 //(*Initialize(DebuggerSettingsDlg)
38 wxStaticLine* staticLine;
39 wxBoxSizer* headerSizer;
40 wxBoxSizer* mainSizer;
41 wxStdDialogButtonSizer* stdDialogButtons;
42 wxPanel* header;
43
44 Create(parent, wxID_ANY, _("Debugger settings"), wxDefaultPosition, wxDefaultSize, wxCAPTION|wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxCLOSE_BOX|wxMAXIMIZE_BOX|wxMINIMIZE_BOX, _T("wxID_ANY"));
45 mainSizer = new wxBoxSizer(wxVERTICAL);
46 header = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTRANSPARENT_WINDOW, _T("wxID_ANY"));
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));
52 wxFont m_activeInfoFont(12,wxFONTFAMILY_DEFAULT,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,wxEmptyString,wxFONTENCODING_DEFAULT);
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
79 const DebuggerManager::RegisteredPlugins &plugins = Manager::Get()->GetDebuggerManager()->GetAllDebuggers();
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
~DebuggerSettingsDlg()107 DebuggerSettingsDlg::~DebuggerSettingsDlg()
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
OnOK(cb_unused wxCommandEvent & event)117 void DebuggerSettingsDlg::OnOK(cb_unused wxCommandEvent &event)
118 {
119 wxString t;
120
121 m_commonPanel->SaveChanges();
122
123 DebuggerManager *dbgManager = Manager::Get()->GetDebuggerManager();
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
FindPageIndex(wxTreebook * treebook,wxWindow * page)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
CreateConfig(wxWindow * panel,cbDebuggerPlugin * plugin,const wxString & name)189 bool DebuggerSettingsDlg::CreateConfig(wxWindow *panel, cbDebuggerPlugin *plugin, const wxString &name)
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
DeleteConfig(wxWindow * panel,cbDebuggerPlugin * plugin)217 void DebuggerSettingsDlg::DeleteConfig(wxWindow *panel, cbDebuggerPlugin *plugin)
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);
256 m_treebook->DeletePage(p);
257 }
258 }
259 break;
260 }
261 }
262
ResetConfig(wxWindow * panel,cbDebuggerPlugin * plugin)263 void DebuggerSettingsDlg::ResetConfig(wxWindow *panel, cbDebuggerPlugin *plugin)
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
OnPageChanged(wxNotebookEvent & event)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 }
295