/
FxPropertyEditor.cpp
50 lines (38 loc) · 1.46 KB
/
FxPropertyEditor.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
#include "FxPropertyEditor.h"
#include "i18n.h"
#include "icommandsystem.h"
#include "ientity.h"
#include "ClassnamePropertyEditor.h"
#include "PropertyEditorFactory.h"
#include "ui/fx/FxChooser.h"
#include <wx/sizer.h>
#include <wx/panel.h>
#include <wx/button.h>
namespace ui
{
FxPropertyEditor::FxPropertyEditor(wxWindow* parent, IEntitySelection& entities, const ITargetKey::Ptr& key) :
PropertyEditor(entities),
_key(key)
{
auto 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 FX..."));
browseButton->SetBitmap(PropertyEditorFactory::getBitmapFor("fx"));
browseButton->Bind(wxEVT_BUTTON, &FxPropertyEditor::_onBrowseButton, this);
mainVBox->GetSizer()->Add(browseButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 6);
}
void FxPropertyEditor::_onBrowseButton(wxCommandEvent& ev)
{
auto currentDecl = _entities.getSharedKeyValue(_key->getFullKey(), false);
// Use the EntityClassChooser dialog to get a selection from the user
auto selection = FxChooser::ChooseDeclaration(currentDecl);
// Only apply if the classname has actually changed
if (!selection.empty() && selection != currentDecl)
{
// Apply the change to the current selection, dispatch the command
GlobalCommandSystem().executeCommand("SetEntityKeyValue", _key->getFullKey(), selection);
}
}
}