| 1 |
#ifndef EVENTSDATABASE_H |
| 2 |
#define EVENTSDATABASE_H |
| 3 |
|
| 4 |
#include "wx_ordered_map.h" |
| 5 |
#include "wxcLib/json_node.h" |
| 6 |
|
| 7 |
#include <map> |
| 8 |
#include <unordered_map> |
| 9 |
#include <wx/menu.h> |
| 10 |
#include <wx/string.h> |
| 11 |
#include <wx/xrc/xmlres.h> |
| 12 |
|
| 13 |
class ConnectDetails |
| 14 |
{ |
| 15 |
protected: |
| 16 |
wxString m_eventName; |
| 17 |
wxString m_eventClass; |
| 18 |
wxString m_description; |
| 19 |
wxString m_functionNameAndSignature; |
| 20 |
bool m_noBody; |
| 21 |
wxString m_ifBlock; // In case this event should be wrapped with #if / #endif block, mark it here |
| 22 |
|
| 23 |
public: |
| 24 |
ConnectDetails() {} |
| 25 |
|
| 26 |
ConnectDetails(const wxString& eventName, const wxString& eventClass, const wxString& description, |
| 27 |
bool noBody = false, const wxString& functionNameAndSignature = "") |
| 28 |
: m_eventName(eventName) |
| 29 |
, m_eventClass(eventClass) |
| 30 |
, m_description(description) |
| 31 |
, m_functionNameAndSignature(functionNameAndSignature) |
| 32 |
, m_noBody(noBody) |
| 33 |
{ |
| 34 |
} |
| 35 |
|
| 36 |
void SetIfBlock(const wxString& ifBlock) { this->m_ifBlock = ifBlock; } |
| 37 |
const wxString& GetIfBlock() const { return m_ifBlock; } |
| 38 |
|
| 39 |
JSONElement ToJSON() const |
| 40 |
{ |
| 41 |
JSONElement element = JSONElement::createObject(); |
| 42 |
element.addProperty(wxT("m_eventName"), m_eventName); |
| 43 |
element.addProperty(wxT("m_eventClass"), m_eventClass); |
| 44 |
element.addProperty(wxT("m_functionNameAndSignature"), m_functionNameAndSignature); |
| 45 |
element.addProperty(wxT("m_description"), m_description); |
| 46 |
element.addProperty(wxT("m_noBody"), m_noBody); |
| 47 |
return element; |
| 48 |
} |
| 49 |
|
| 50 |
void FromJSON(const JSONElement& json) |
| 51 |
{ |
| 52 |
m_eventName = json.namedObject(wxT("m_eventName")).toString(); |
| 53 |
m_eventClass = json.namedObject(wxT("m_eventClass")).toString(); |
| 54 |
m_functionNameAndSignature = json.namedObject(wxT("m_functionNameAndSignature")).toString(); |
| 55 |
m_description = json.namedObject(wxT("m_description")).toString(); |
| 56 |
m_noBody = json.namedObject(wxT("m_noBody")).toBool(); |
| 57 |
} |
| 58 |
|
| 59 |
void SetDescription(const wxString& description) { this->m_description = description; } |
| 60 |
const wxString& GetDescription() const { return m_description; } |
| 61 |
void SetEventClass(const wxString& eventClass) { this->m_eventClass = eventClass; } |
| 62 |
|
| 63 |
const wxString& GetEventClass() const { return m_eventClass; } |
| 64 |
|
| 65 |
void SetEventName(const wxString& eventName) { this->m_eventName = eventName; } |
| 66 |
void SetFunctionNameAndSignature(const wxString& functionNameAndSignature); |
| 67 |
void SetNoBody(bool noBody) { this->m_noBody = noBody; } |
| 68 |
const wxString& GetEventName() const { return m_eventName; } |
| 69 |
const wxString& GetFunctionNameAndSignature() const { return m_functionNameAndSignature; } |
| 70 |
bool GetNoBody() const { return m_noBody; } |
| 71 |
int GetMenuItemId() const { return wxXmlResource::GetXRCID(m_eventName); } |
| 72 |
void GenerateFunctionName(const wxString& controlName); |
| 73 |
void MakeSignatureForName(const wxString& name); |
| 74 |
wxString GetFunctionImpl(const wxString& classname) const; |
| 75 |
wxString GetFunctionDecl() const; |
| 76 |
}; |
| 77 |
|
| 78 |
///////////////////////////////////////////////////////////////////////////////////////// |
| 79 |
|
| 80 |
class EventsDatabase |
| 81 |
{ |
| 82 |
public: |
| 83 |
typedef wxOrderedMap<wxString, ConnectDetails> MapEvents_t; |
| 84 |
typedef std::unordered_map<int, wxString> MapMenuIdToName_t; |
| 85 |
|
| 86 |
protected: |
| 87 |
MapEvents_t m_events; |
| 88 |
MapMenuIdToName_t m_menuIdToName; |
| 89 |
|
| 90 |
public: |
| 91 |
EventsDatabase(); |
| 92 |
virtual ~EventsDatabase(); |
| 93 |
|
| 94 |
// API |
| 95 |
void FillCommonEvents(); |
| 96 |
|
| 97 |
void Add(const ConnectDetails& ed); |
| 98 |
void Add(const wxString& eventName, const wxString& className, const wxString& description, |
| 99 |
const wxString& functionNameAndSig = "", bool noBody = false); |
| 100 |
void Clear(); |
| 101 |
bool Exists(int menuId) const; |
| 102 |
ConnectDetails Item(int menuId) const; |
| 103 |
|
| 104 |
MapEvents_t& GetEvents() { return m_events; } |
| 105 |
const MapEvents_t& GetEvents() const { return m_events; } |
| 106 |
wxMenu* CreateMenu() const; |
| 107 |
}; |
| 108 |
|
| 109 |
#endif // EVENTSDATABASE_H |