| 1 |
#include "EventsEditorDlg.h" |
| 2 |
|
| 3 |
#include "allocator_mgr.h" |
| 4 |
#include "wxc_project_metadata.h" |
| 5 |
#include "wxc_widget.h" |
| 6 |
#include "wxcrafter_plugin.h" |
| 7 |
#include "wxgui_helpers.h" |
| 8 |
#include "wxguicraft_main_view.h" |
| 9 |
|
| 10 |
#include <ctags_manager.h> |
| 11 |
#include <event_notifier.h> |
| 12 |
#include <imanager.h> |
| 13 |
#include <istorage.h> |
| 14 |
#include <windowattrmanager.h> |
| 15 |
#include <wx/msgdlg.h> |
| 16 |
#include <wx/stc/stc.h> |
| 17 |
|
| 18 |
wxString EventsEditorPane::PANE_NAME = "Control Events"; |
| 19 |
|
| 20 |
EventsEditorPane::EventsEditorPane(wxWindow* parent, wxcWidget* control, wxCrafterPlugin* plugin) |
| 21 |
: EventsEditorPaneBase(parent) |
| 22 |
, m_control(control) |
| 23 |
, m_plugin(plugin) |
| 24 |
{ |
| 25 |
DoInitialize(); |
| 26 |
EventNotifier::Get()->Connect(wxEVT_TREE_ITEM_SELECTED, wxCommandEventHandler(EventsEditorPane::OnWidgetSelected), |
| 27 |
NULL, this); |
| 28 |
EventNotifier::Get()->Connect(wxEVT_UPDATE_EVENTSEDITORPANE, wxCommandEventHandler(EventsEditorPane::OnUpdatePanes), |
| 29 |
NULL, this); |
| 30 |
EventNotifier::Get()->Connect(wxEVT_WXC_CLOSE_PROJECT, wxCommandEventHandler(EventsEditorPane::OnProjectClosed), |
| 31 |
NULL, this); |
| 32 |
m_controlEventsTable->Connect(wxEVT_PG_DOUBLE_CLICK, wxPropertyGridEventHandler(EventsEditorPane::OnDoubleClick), |
| 33 |
NULL, this); |
| 34 |
m_inheritedEventsTable->Connect(wxEVT_PG_DOUBLE_CLICK, wxPropertyGridEventHandler(EventsEditorPane::OnDoubleClick), |
| 35 |
NULL, this); |
| 36 |
m_controlEventsTable->Connect(wxEVT_PG_CHANGED, wxPropertyGridEventHandler(EventsEditorPane::OnValueChanged), NULL, |
| 37 |
this); |
| 38 |
m_inheritedEventsTable->Connect(wxEVT_PG_CHANGED, wxPropertyGridEventHandler(EventsEditorPane::OnValueChanged), |
| 39 |
NULL, this); |
| 40 |
} |
| 41 |
|
| 42 |
EventsEditorPane::~EventsEditorPane() |
| 43 |
{ |
| 44 |
|
| 45 |
EventNotifier::Get()->Disconnect(wxEVT_TREE_ITEM_SELECTED, |
| 46 |
wxCommandEventHandler(EventsEditorPane::OnWidgetSelected), NULL, this); |
| 47 |
EventNotifier::Get()->Disconnect(wxEVT_UPDATE_EVENTSEDITORPANE, |
| 48 |
wxCommandEventHandler(EventsEditorPane::OnUpdatePanes), NULL, this); |
| 49 |
EventNotifier::Get()->Disconnect(wxEVT_WXC_CLOSE_PROJECT, wxCommandEventHandler(EventsEditorPane::OnProjectClosed), |
| 50 |
NULL, this); |
| 51 |
|
| 52 |
m_controlEventsTable->Disconnect(wxEVT_PG_CHANGED, wxPropertyGridEventHandler(EventsEditorPane::OnValueChanged), |
| 53 |
NULL, this); |
| 54 |
m_controlEventsTable->Disconnect(wxEVT_PG_DOUBLE_CLICK, wxPropertyGridEventHandler(EventsEditorPane::OnDoubleClick), |
| 55 |
NULL, this); |
| 56 |
|
| 57 |
m_inheritedEventsTable->Disconnect(wxEVT_PG_CHANGED, wxPropertyGridEventHandler(EventsEditorPane::OnValueChanged), |
| 58 |
NULL, this); |
| 59 |
m_inheritedEventsTable->Disconnect(wxEVT_PG_DOUBLE_CLICK, |
| 60 |
wxPropertyGridEventHandler(EventsEditorPane::OnDoubleClick), NULL, this); |
| 61 |
} |
| 62 |
|
| 63 |
void EventsEditorPane::DoInitialize() |
| 64 |
{ |
| 65 |
if(m_control) { |
| 66 |
m_staticTextEventsPaneTitle->SetLabel(_("Showing events for - ") + m_control->GetName()); |
| 67 |
} |
| 68 |
|
| 69 |
m_controlEventsTable->GetGrid()->Clear(); |
| 70 |
m_inheritedEventsTable->GetGrid()->Clear(); |
| 71 |
|
| 72 |
if(m_control) { |
| 73 |
m_controlEventsTable->Construct(this, m_control, m_control->GetControlEvents()); |
| 74 |
m_inheritedEventsTable->Construct(this, m_control, Allocator::GetCommonEvents()); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
void EventsEditorPane::SplitterPositionChanged() |
| 79 |
{ |
| 80 |
if(m_control) { |
| 81 |
wxString label = m_control->GetName(); |
| 82 |
// Without this rewrite, a name that's too long to display fully disappears forever if the splitter-sash is |
| 83 |
// moved :/ |
| 84 |
m_staticTextEventsPaneTitle->SetLabel(_("Showing events for - ") + label); |
| 85 |
} |
| 86 |
|
| 87 |
// Try not to let the Description section of the wxPG entirely disappear. Or if it already has, try to show it |
| 88 |
// again. |
| 89 |
int charHt = m_controlEventsTable->GetCharHeight() * 3; |
| 90 |
if((m_controlEventsTable->GetDescBoxHeight() < charHt) && (m_controlEventsTable->GetClientSize().GetY() > charHt)) { |
| 91 |
m_controlEventsTable->SetDescBoxHeight(charHt / 2); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
void EventsEditorPane::Save() |
| 96 |
{ |
| 97 |
m_controlEventsTable->Save(); |
| 98 |
if(m_inheritedEventsTable) { |
| 99 |
m_inheritedEventsTable->Save(); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
void EventsEditorPane::OpenFunction(const wxString& kind, const wxString& fooname) |
| 104 |
{ |
| 105 |
wxUnusedVar(kind); |
| 106 |
wxUnusedVar(fooname); |
| 107 |
} |
| 108 |
|
| 109 |
void EventsEditorPane::OnWidgetSelected(wxCommandEvent& e) |
| 110 |
{ |
| 111 |
e.Skip(); |
| 112 |
|
| 113 |
// Load the new item |
| 114 |
GUICraftItemData* selection = GUICraftMainPanel::m_MainPanel->GetSelItemData(); |
| 115 |
CHECK_PTR_RET(selection); |
| 116 |
Clear(); |
| 117 |
|
| 118 |
CHECK_PTR_RET(selection->m_wxcWidget); |
| 119 |
if(selection->m_wxcWidget->IsEventHandler()) { |
| 120 |
InitEventsForWidget(selection->m_wxcWidget); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
void EventsEditorPane::OnUpdatePanes(wxCommandEvent& e) // Called when the current control has been altered |
| 125 |
{ |
| 126 |
e.Skip(); |
| 127 |
|
| 128 |
CHECK_POINTER(m_control); |
| 129 |
DoInitialize(); |
| 130 |
} |
| 131 |
|
| 132 |
void EventsEditorPane::InitEventsForWidget(wxcWidget* control) |
| 133 |
{ |
| 134 |
m_control = control; |
| 135 |
DoInitialize(); |
| 136 |
} |
| 137 |
|
| 138 |
void EventsEditorPane::OnProjectClosed(wxCommandEvent& e) |
| 139 |
{ |
| 140 |
e.Skip(); |
| 141 |
Clear(); |
| 142 |
} |
| 143 |
|
| 144 |
void EventsEditorPane::Clear() |
| 145 |
{ |
| 146 |
m_control = NULL; |
| 147 |
m_controlEventsTable->GetGrid()->Clear(); |
| 148 |
m_inheritedEventsTable->GetGrid()->Clear(); |
| 149 |
m_staticTextEventsPaneTitle->SetLabel(""); |
| 150 |
} |
| 151 |
|
| 152 |
void EventsEditorPane::OnValueChanged(wxPropertyGridEvent& e) |
| 153 |
{ |
| 154 |
e.Skip(); |
| 155 |
Save(); |
| 156 |
wxcEditManager::Get().PushState("events updated"); |
| 157 |
} |
| 158 |
|
| 159 |
void EventsEditorPane::OnDoubleClick(wxPropertyGridEvent& e) |
| 160 |
{ |
| 161 |
e.Skip(); |
| 162 |
// Generate function name using the following format: |
| 163 |
// On<ControlName><EventName> |
| 164 |
wxString eventName = e.GetPropertyName(); |
| 165 |
eventName.Replace("wxEVT_COMMAND_", ""); |
| 166 |
eventName.Replace("wxEVT_", ""); |
| 167 |
wxArrayString parts = ::wxStringTokenize(eventName, "_", wxTOKEN_STRTOK); |
| 168 |
wxString eventHandler = "On"; |
| 169 |
|
| 170 |
// for non top level window, append the control name as well |
| 171 |
if(!m_control->IsTopWindow()) { |
| 172 |
wxString controlName = m_control->GetName(); |
| 173 |
controlName.Replace("m_", ""); |
| 174 |
if(controlName.StartsWith("_")) { |
| 175 |
controlName = controlName.Mid(1); |
| 176 |
} |
| 177 |
controlName.MakeCapitalized(); |
| 178 |
eventHandler << controlName; |
| 179 |
} |
| 180 |
|
| 181 |
for(size_t i = 0; i < parts.GetCount(); ++i) { |
| 182 |
wxString part = parts.Item(i); |
| 183 |
part.MakeLower(); |
| 184 |
part.MakeCapitalized(); |
| 185 |
eventHandler << part; |
| 186 |
} |
| 187 |
e.GetProperty()->SetValue(eventHandler); |
| 188 |
Save(); |
| 189 |
wxcEditManager::Get().PushState("events updated"); |
| 190 |
} |