-
Notifications
You must be signed in to change notification settings - Fork 47
/
PropertyEditor.h
98 lines (77 loc) · 2.45 KB
/
PropertyEditor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#pragma once
#include "ui/ientityinspector.h"
#include <wx/event.h>
#include <string>
#include <memory>
/* FORWARD DECLS */
class Entity;
class wxBitmap;
namespace ui
{
/**
* PropertyEditor shared pointer type.
*/
class PropertyEditor;
typedef std::shared_ptr<PropertyEditor> PropertyEditorPtr;
/**
* Base class for built-in PropertyEditor widgets. Derived classes
* need to implement the createNew method for virtual construction.
*
* Derived classes should call setMainWdiget() to pass a smart pointer
* to this base class. The reference is then
* held by the base class and destroyed along with the base class.
*/
class PropertyEditor :
public wxEvtHandler,
public IPropertyEditor
{
private:
// The main widget, should be set by the subclass using setMainWidget()
wxPanel* _mainWidget;
std::function<void()> _oneButtonPanelCallback;
protected:
// The entity being focused (NULL if none there)
Entity* _entity;
// Protected blank constructor
PropertyEditor();
// Protected constructor
PropertyEditor(Entity* entity);
protected:
/**
* Subclasses should call this method after the editor widgets
* have been created. This base class will take responsibility
* of destroying this widget along with this class.
*/
void setMainWidget(wxPanel* widget);
/**
* greebo: Central method to assign values to the entit(ies) in question.
* This takes care of calling setKeyValue() on the selected entities
* as well as managing the UndoSystem.
*/
virtual void setKeyValue(const std::string& key, const std::string& value);
/**
* greebo: Convenience method to retrieve a keyvalue from the edited entity.
*/
virtual std::string getKeyValue(const std::string& key);
/**
* greebo: Since many property editors consists of a single browse button,
* the base class provides this convenience method.
*/
void constructBrowseButtonPanel(wxWindow* parent, const std::string& label,
const wxBitmap& bitmap);
// When using constructBrowseButtonPanel() subclasses should override this method to catch the event
virtual void onBrowseButtonClick() {}
private:
// wxWidgets callback when using the browse-button-panel design
void _onBrowseButtonClick(wxCommandEvent& ev);
public:
virtual ~PropertyEditor();
// IPropertyEditor implementation
wxPanel* getWidget() override;
virtual void updateFromEntity() override
{
// nothing by default, override in subclasses if needed
}
virtual void setEntity(Entity* entity) override;
};
} // namespace