Debian Codegraph @

plugins/dm.editing/AIVocalSetPropertyEditor.cpp

raw
1 #include "AIVocalSetPropertyEditor.h"
2
3 #include "i18n.h"
4 #include "ieclass.h"
5 #include "ientity.h"
6
7 #include <wx/panel.h>
8 #include <wx/button.h>
9 #include "wxutil/Bitmap.h"
10 #include <wx/sizer.h>
11
12 #include "AIVocalSetChooserDialog.h"
13
14 namespace ui
15 {
16
17 AIVocalSetPropertyEditor::AIVocalSetPropertyEditor(wxWindow* parent, IEntitySelection& entities, const ITargetKey::Ptr& key) :
18 _entities(entities),
19 _key(key)
20 {
21 // Construct the main widget (will be managed by the base class)
22 _widget = new wxPanel(parent, wxID_ANY);
23 _widget->SetSizer(new wxBoxSizer(wxHORIZONTAL));
24
25 // Create the browse button
26 wxButton* browseButton = new wxButton(_widget, wxID_ANY, _("Select Vocal Set..."));
27 browseButton->SetBitmap(wxutil::GetLocalBitmap("icon_sound.png"));
28 browseButton->Bind(wxEVT_BUTTON, &AIVocalSetPropertyEditor::onChooseButton, this);
29
30 _widget->GetSizer()->Add(browseButton, 0, wxALIGN_CENTER_VERTICAL);
31 }
32
33 AIVocalSetPropertyEditor::~AIVocalSetPropertyEditor()
34 {
35 if (_widget != nullptr)
36 {
37 _widget->Destroy();
38 }
39 }
40
41 wxPanel* AIVocalSetPropertyEditor::getWidget()
42 {
43 return _widget;
44 }
45
46 void AIVocalSetPropertyEditor::updateFromEntities()
47 {
48 // Nothing to do
49 }
50
51 sigc::signal<void(const std::string&, const std::string&)>& AIVocalSetPropertyEditor::signal_keyValueApplied()
52 {
53 return _sigKeyValueApplied;
54 }
55
56 IPropertyEditor::Ptr AIVocalSetPropertyEditor::CreateNew(wxWindow* parent, IEntitySelection& entities,
57 const ITargetKey::Ptr& key)
58 {
59 return std::make_shared<AIVocalSetPropertyEditor>(parent, entities, key);
60 }
61
62 void AIVocalSetPropertyEditor::onChooseButton(wxCommandEvent& ev)
63 {
64 // Construct a new vocal set chooser dialog
65 AIVocalSetChooserDialog* dialog = new AIVocalSetChooserDialog;
66
67 dialog->setSelectedVocalSet(_entities.getSharedKeyValue(DEF_VOCAL_SET_KEY, true));
68
69 // Show and block
70 if (dialog->ShowModal() == wxID_OK)
71 {
72 auto selectedSet = dialog->getSelectedVocalSet();
73
74 _entities.foreachEntity([&](const IEntityNodePtr& entity)
75 {
76 entity->getEntity().setKeyValue(DEF_VOCAL_SET_KEY, selectedSet);
77 });
78
79 signal_keyValueApplied().emit(DEF_VOCAL_SET_KEY, selectedSet);
80 }
81
82 dialog->Destroy();
83 }
84
85 std::string AIVocalSetEditorDialogWrapper::runDialog(Entity* entity, const std::string& key)
86 {
87 // Construct a new vocal set chooser dialog
88 AIVocalSetChooserDialog* dialog = new AIVocalSetChooserDialog;
89
90 std::string oldValue = entity->getKeyValue(DEF_VOCAL_SET_KEY);
91 dialog->setSelectedVocalSet(oldValue);
92
93 // Show and block
94 std::string rv = oldValue;
95
96 if (dialog->ShowModal() == wxID_OK)
97 {
98 rv = dialog->getSelectedVocalSet();
99 }
100
101 dialog->Destroy();
102
103 return rv;
104 }
105
106 } // namespace ui