| 1 |
#include "events_table_list_view.h" |
| 2 |
|
| 3 |
#include "EventsEditorDlg.h" |
| 4 |
#include "wxc_project_metadata.h" |
| 5 |
#include "wxgui_bitmaploader.h" |
| 6 |
#include "wxgui_helpers.h" |
| 7 |
|
| 8 |
#include <wx/wxcrtvararg.h> |
| 9 |
|
| 10 |
namespace |
| 11 |
{ |
| 12 |
wxString PLACE_HOLDER = ""; |
| 13 |
} |
| 14 |
|
| 15 |
wxDECLARE_EVENT(wxEVT_EVENTS_PROPERTIES_UPDATED, wxCommandEvent); |
| 16 |
|
| 17 |
EventsTableListView::EventsTableListView(wxWindow* parent) |
| 18 |
: wxPropertyGridManager(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, |
| 19 |
wxPG_SPLITTER_AUTO_CENTER | wxPG_BOLD_MODIFIED | wxPG_DESCRIPTION | |
| 20 |
wxCrafter::GetControlBorder()) |
| 21 |
, m_eventsDb(NULL) |
| 22 |
{ |
| 23 |
Connect(wxEVT_PG_CHANGED, wxPropertyGridEventHandler(EventsTableListView::OnPropertyChanged), NULL, this); |
| 24 |
} |
| 25 |
|
| 26 |
EventsTableListView::~EventsTableListView() |
| 27 |
{ |
| 28 |
Disconnect(wxEVT_PG_CHANGED, wxPropertyGridEventHandler(EventsTableListView::OnPropertyChanged), NULL, this); |
| 29 |
} |
| 30 |
|
| 31 |
void EventsTableListView::Construct(EventsEditorPane* dlg, wxcWidget* control, const EventsDatabase& events) |
| 32 |
{ |
| 33 |
wxPropertyGrid* grid = GetGrid(); |
| 34 |
grid->Append(new wxPropertyCategory(_("Event Handlers"))); |
| 35 |
|
| 36 |
m_dlg = dlg; |
| 37 |
m_eventsDb = const_cast<EventsDatabase*>(&events); |
| 38 |
CHECK_POINTER(control); |
| 39 |
m_control = control; |
| 40 |
EventsDatabase::MapEvents_t::const_iterator iter = events.GetEvents().begin(); |
| 41 |
for(; iter != events.GetEvents().end(); ++iter) { |
| 42 |
ConnectDetails cd = iter->second; |
| 43 |
|
| 44 |
wxString eventName = cd.GetEventName(); |
| 45 |
eventName.Trim().Trim(false); |
| 46 |
if(eventName.IsEmpty()) |
| 47 |
continue; |
| 48 |
|
| 49 |
// Check to see if this event has a user defined function |
| 50 |
wxString fooname; |
| 51 |
if(control->HasEvent(eventName)) { |
| 52 |
fooname = control->GetEvent(eventName).GetFunctionNameAndSignature(); |
| 53 |
} else if(!cd.GetFunctionNameAndSignature().empty()) { |
| 54 |
// A few events (well, just 1 atm) come with a default function |
| 55 |
fooname = cd.GetFunctionNameAndSignature(); |
| 56 |
} else { |
| 57 |
fooname = PLACE_HOLDER; |
| 58 |
} |
| 59 |
|
| 60 |
fooname = fooname.BeforeFirst(wxT('(')); |
| 61 |
wxPGProperty* prop = grid->Append(new wxStringProperty(eventName, wxPG_LABEL, fooname)); |
| 62 |
SetDescription("", ""); // SetHelpString("") doesn't seem to clear any stale description, so clear it first |
| 63 |
prop->SetHelpString(cd.GetDescription()); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
void EventsTableListView::Save() |
| 68 |
{ |
| 69 |
wxPropertyGrid* grid = GetGrid(); |
| 70 |
|
| 71 |
wxPropertyGridIterator it; |
| 72 |
for(it = grid->GetIterator(); !it.AtEnd(); it++) { |
| 73 |
wxPGProperty* p = *it; |
| 74 |
wxString event = p->GetLabel(); |
| 75 |
wxString func = p->GetValueAsString(); |
| 76 |
|
| 77 |
func.Trim().Trim(false); |
| 78 |
|
| 79 |
// If the handler is empty delete the event |
| 80 |
if(func.IsEmpty() || func == PLACE_HOLDER) { |
| 81 |
m_control->RemoveEvent(event); |
| 82 |
|
| 83 |
} else if(m_eventsDb) { |
| 84 |
ConnectDetails cd = m_eventsDb->GetEvents().Item(event); |
| 85 |
cd.MakeSignatureForName(func); |
| 86 |
// insert or update |
| 87 |
m_control->AddEvent(cd); |
| 88 |
} |
| 89 |
|
| 90 |
// Out of politeness, tell our control; it might even be interested e.g. dropdown tools |
| 91 |
wxCommandEvent evt(wxEVT_EVENTS_PROPERTIES_UPDATED); |
| 92 |
evt.SetString(event); |
| 93 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
void EventsTableListView::OnPropertyChanged(wxPropertyGridEvent& e) { e.Skip(); } |