| 1 |
#include "EditCustomControlDlg.h" |
| 2 |
#include "NewCustomEventDlg.h" |
| 3 |
#include "wxc_settings.h" |
| 4 |
#include <windowattrmanager.h> |
| 5 |
#include <wx/app.h> |
| 6 |
#include "wxgui_helpers.h" |
| 7 |
|
| 8 |
EditCustomControlDlg::EditCustomControlDlg(wxWindow* parent) |
| 9 |
: EditCustomControlDlgBaseClass(parent) |
| 10 |
, m_isModified(false) |
| 11 |
{ |
| 12 |
const CustomControlTemplateMap_t& c = wxcSettings::Get().GetTemplateClasses(); |
| 13 |
CustomControlTemplateMap_t::const_iterator iter = c.begin(); |
| 14 |
for(; iter != c.end(); ++iter) { |
| 15 |
m_choiceControls->Append(iter->first); |
| 16 |
} |
| 17 |
|
| 18 |
if(c.empty() == false) { |
| 19 |
m_choiceControls->SetSelection(0); |
| 20 |
|
| 21 |
wxCommandEvent dummy; |
| 22 |
OnSelectControl(dummy); |
| 23 |
} |
| 24 |
SetName("EditCustomControlDlg"); |
| 25 |
WindowAttrManager::Load(this); |
| 26 |
} |
| 27 |
|
| 28 |
EditCustomControlDlg::~EditCustomControlDlg() {} |
| 29 |
|
| 30 |
void EditCustomControlDlg::OnSelectControl(wxCommandEvent& event) |
| 31 |
{ |
| 32 |
if(m_isModified) { OnSave(event); } |
| 33 |
|
| 34 |
wxString controlName = m_choiceControls->GetStringSelection(); |
| 35 |
CustomControlTemplate cct = wxcSettings::Get().FindByControlName(controlName); |
| 36 |
if(cct.IsValid()) { |
| 37 |
m_textCtrlInstantiationLine->ChangeValue(cct.GetAllocationLine()); |
| 38 |
m_textCtrlIncludeFile->ChangeValue(cct.GetIncludeFile()); |
| 39 |
m_textCtrlXRCClass->ChangeValue(cct.GetXrcPreviewClass()); |
| 40 |
|
| 41 |
m_dvListCtrlEvents->DeleteAllItems(); |
| 42 |
const wxStringMap_t& events = cct.GetEvents(); |
| 43 |
wxStringMap_t::const_iterator iter = events.begin(); |
| 44 |
for(; iter != events.end(); ++iter) { |
| 45 |
wxVector<wxVariant> cols; |
| 46 |
cols.push_back(iter->first); |
| 47 |
cols.push_back(iter->second); |
| 48 |
m_dvListCtrlEvents->AppendItem(cols); |
| 49 |
} |
| 50 |
} |
| 51 |
m_isModified = false; |
| 52 |
} |
| 53 |
|
| 54 |
void EditCustomControlDlg::OnSave(wxCommandEvent& event) |
| 55 |
{ |
| 56 |
CustomControlTemplate cct; |
| 57 |
cct.SetClassName(m_choiceControls->GetStringSelection()); |
| 58 |
cct.SetAllocationLine(m_textCtrlInstantiationLine->GetValue()); |
| 59 |
cct.SetIncludeFile(m_textCtrlIncludeFile->GetValue()); |
| 60 |
cct.SetXrcPreviewClass(m_textCtrlXRCClass->GetValue()); |
| 61 |
|
| 62 |
wxStringMap_t events; |
| 63 |
int count = m_dvListCtrlEvents->GetItemCount(); |
| 64 |
for(int i = 0; i < count; ++i) { |
| 65 |
wxString eventtype = m_dvListCtrlEvents->GetTextValue(i, 0); |
| 66 |
wxString eventclss = m_dvListCtrlEvents->GetTextValue(i, 1); |
| 67 |
|
| 68 |
events.insert(std::make_pair(eventtype, eventclss)); |
| 69 |
} |
| 70 |
cct.SetEvents(events); |
| 71 |
wxcSettings::Get().RegisterCustomControl(cct); |
| 72 |
wxcSettings::Get().Save(); |
| 73 |
m_isModified = false; |
| 74 |
} |
| 75 |
|
| 76 |
void EditCustomControlDlg::OnControlModified(wxCommandEvent& event) { m_isModified = true; } |
| 77 |
|
| 78 |
void EditCustomControlDlg::OnSaveUI(wxUpdateUIEvent& event) { event.Enable(m_isModified); } |
| 79 |
|
| 80 |
void EditCustomControlDlg::OnDeleteEvent(wxCommandEvent& event) |
| 81 |
{ |
| 82 |
m_dvListCtrlEvents->DeleteItem(m_dvListCtrlEvents->GetSelectedRow()); |
| 83 |
m_isModified = true; |
| 84 |
} |
| 85 |
|
| 86 |
void EditCustomControlDlg::OnNewEvent(wxCommandEvent& event) |
| 87 |
{ |
| 88 |
NewCustomEventDlg dlg(wxCrafter::TopFrame()); |
| 89 |
if(dlg.ShowModal() == wxID_OK) { |
| 90 |
|
| 91 |
wxVector<wxVariant> cols; |
| 92 |
cols.push_back(dlg.GetEventType()); |
| 93 |
cols.push_back(dlg.GetEventClass()); |
| 94 |
m_dvListCtrlEvents->AppendItem(cols); |
| 95 |
m_isModified = true; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
void EditCustomControlDlg::OnDeleteEventUI(wxUpdateUIEvent& event) |
| 100 |
{ |
| 101 |
event.Enable(m_dvListCtrlEvents->GetSelection().IsOk()); |
| 102 |
} |
| 103 |
|
| 104 |
void EditCustomControlDlg::OnEventEditDone(wxDataViewEvent& event) |
| 105 |
{ |
| 106 |
event.Skip(); |
| 107 |
m_isModified = true; |
| 108 |
} |