Debian Codegraph @

wxcrafter/src/DeleteCustomControlDlg.cpp

raw
1 #include "DeleteCustomControlDlg.h"
2 #include "wxc_settings.h"
3 #include <windowattrmanager.h>
4 #include <wx/arrstr.h>
5 #include <wx/msgdlg.h>
6
7 DeleteCustomControlDlg::DeleteCustomControlDlg(wxWindow* parent)
8 : DeleteCustomControlDlgBaseClass(parent)
9 {
10 DoPopulate();
11 SetName("DeleteCustomControlDlg");
12 WindowAttrManager::Load(this);
13 }
14
15 DeleteCustomControlDlg::~DeleteCustomControlDlg() {}
16
17 void DeleteCustomControlDlg::OnDeleteUI(wxUpdateUIEvent& event) { event.Enable(!m_controlsToDelete.IsEmpty()); }
18
19 void DeleteCustomControlDlg::OnDeleteControls(wxCommandEvent& event)
20 {
21 wxString msg;
22 msg << _("Are you sure you want to delete the following custom controls:\n");
23
24 for(size_t i = 0; i < m_controlsToDelete.GetCount(); ++i) {
25 msg << m_controlsToDelete.Item(i) << "\n";
26 }
27
28 if(::wxMessageBox(msg, wxT("wxCrafter"), wxICON_QUESTION | wxCENTER | wxYES_NO) == wxYES) {
29 for(size_t i = 0; i < m_controlsToDelete.GetCount(); ++i) {
30 wxcSettings::Get().DeleteCustomControl(m_controlsToDelete.Item(i));
31 }
32 wxcSettings::Get().Save();
33 DoPopulate();
34 }
35 }
36
37 void DeleteCustomControlDlg::OnItemValueChanged(wxDataViewEvent& event)
38 {
39 unsigned row = m_dvListCtrl->GetStore()->GetRow(event.GetItem());
40 wxString controlName = m_dvListCtrl->GetTextValue(row, 1);
41
42 wxVariant v;
43 m_dvListCtrl->GetValue(v, row, 0);
44
45 if(v.GetBool()) {
46 if(m_controlsToDelete.Index(controlName) == wxNOT_FOUND) m_controlsToDelete.Add(controlName);
47
48 } else {
49 int where = m_controlsToDelete.Index(controlName);
50 if(where != wxNOT_FOUND) m_controlsToDelete.RemoveAt(where);
51 }
52 }
53
54 void DeleteCustomControlDlg::DoPopulate()
55 {
56 m_dvListCtrl->DeleteAllItems();
57 m_controlsToDelete.Clear();
58 wxArrayString controlsArr;
59 const CustomControlTemplateMap_t& m = wxcSettings::Get().GetTemplateClasses();
60 CustomControlTemplateMap_t::const_iterator iter = m.begin();
61 for(; iter != m.end(); ++iter) {
62 wxVector<wxVariant> cols;
63 cols.push_back(false); // do not delete
64 cols.push_back(iter->second.GetClassName());
65 m_dvListCtrl->AppendItem(cols, (wxUIntPtr)NULL);
66 }
67 }