/
ClassnamePropertyEditor.cpp
79 lines (60 loc) · 2.83 KB
/
ClassnamePropertyEditor.cpp
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
#include "ClassnamePropertyEditor.h"
#include "PropertyEditorFactory.h"
#include "i18n.h"
#include "ientity.h"
#include "icommandsystem.h"
#include <wx/panel.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include "wxutil/EntityClassChooser.h"
#include "wxutil/Bitmap.h"
#include "Algorithm.h"
namespace ui
{
// Main constructor
ClassnamePropertyEditor::ClassnamePropertyEditor(wxWindow* parent, IEntitySelection& entities, const ITargetKey::Ptr& key)
: PropertyEditor(entities),
_key(key)
{
wxPanel* mainVBox = new wxPanel(parent, wxID_ANY);
mainVBox->SetSizer(new wxBoxSizer(wxHORIZONTAL));
// Register the main widget in the base class
setMainWidget(mainVBox);
auto browseButton = new wxButton(mainVBox, wxID_ANY, _("Choose Entity Class..."));
browseButton->SetBitmap(PropertyEditorFactory::getBitmapFor("classname"));
browseButton->Bind(wxEVT_BUTTON, &ClassnamePropertyEditor::_onBrowseButton, this);
auto showDefinition = new wxButton(mainVBox, wxID_ANY, _("Show Definition..."));
showDefinition->SetBitmap(wxutil::GetLocalBitmap("decl.png"));
showDefinition->Bind(wxEVT_BUTTON, &ClassnamePropertyEditor::_onShowDefinition, this);
auto showInDefTree = new wxButton(mainVBox, wxID_ANY, _("Show in Def Tree..."));
showInDefTree->SetBitmap(PropertyEditorFactory::getBitmapFor("classname"));
showInDefTree->Bind(wxEVT_BUTTON, &ClassnamePropertyEditor::_onShowInDefTree, this);
mainVBox->GetSizer()->Add(browseButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 6);
mainVBox->GetSizer()->Add(showDefinition, 0, wxALIGN_CENTER_VERTICAL | wxALL, 6);
mainVBox->GetSizer()->Add(showInDefTree, 0, wxALIGN_CENTER_VERTICAL | wxALL, 6);
}
void ClassnamePropertyEditor::_onBrowseButton(wxCommandEvent& ev)
{
auto currentEclass = _entities.getSharedKeyValue(_key->getFullKey(), false);
// Use the EntityClassChooser dialog to get a selection from the user
auto selectedEclass = wxutil::EntityClassChooser::ChooseEntityClass(
wxutil::EntityClassChooser::Purpose::SelectClassname, currentEclass);
// Only apply if the classname has actually changed
if (!selectedEclass.empty() && selectedEclass != currentEclass)
{
// Apply the classname change to the current selection, dispatch the command
GlobalCommandSystem().executeCommand("SetEntityKeyValue", _key->getFullKey(), selectedEclass);
signal_keyValueApplied().emit(_key->getFullKey(), selectedEclass);
}
}
void ClassnamePropertyEditor::_onShowDefinition(wxCommandEvent& ev)
{
auto currentEclass = _entities.getSharedKeyValue(_key->getFullKey(), true);
algorithm::showEntityClassDefinition(getWidget(), currentEclass);
}
void ClassnamePropertyEditor::_onShowInDefTree(wxCommandEvent& ev)
{
auto currentEclass = _entities.getSharedKeyValue(_key->getFullKey(), true);
algorithm::showEntityClassInTree(currentEclass);
}
} // namespace ui