Skip to content

Commit

Permalink
#5700: Add a feedback signal to the IPropertyEditor interface to get …
Browse files Browse the repository at this point in the history
…notified when key values have been set
  • Loading branch information
codereader committed Nov 13, 2022
1 parent 2236a9e commit b6a9a92
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 10 deletions.
7 changes: 7 additions & 0 deletions include/ui/ientityinspector.h
Expand Up @@ -101,6 +101,13 @@ class IPropertyEditor
* Instructs the editor to update its widgets from the edited entity's key values.
*/
virtual void updateFromEntities() = 0;

/**
* A signal that is emitted when a key value has been applied to one or more selected entities.
* (This is used as a feedback channel for the EntityInspector UI to get notified when
* a value has been set, such that the text entry boxes can follow along.)
*/
virtual sigc::signal<void(const std::string&, const std::string&)>& signal_keyValueApplied() = 0;
};

class IEntityInspectorModule :
Expand Down
11 changes: 10 additions & 1 deletion plugins/dm.editing/AIHeadPropertyEditor.cpp
Expand Up @@ -48,6 +48,11 @@ void AIHeadPropertyEditor::updateFromEntities()
// nothing to do
}

sigc::signal<void(const std::string&, const std::string&)>& AIHeadPropertyEditor::signal_keyValueApplied()
{
return _sigKeyValueApplied;
}

IPropertyEditor::Ptr AIHeadPropertyEditor::CreateNew(wxWindow* parent, IEntitySelection& entities,
const ITargetKey::Ptr& key)
{
Expand All @@ -64,10 +69,14 @@ void AIHeadPropertyEditor::onChooseButton(wxCommandEvent& ev)
// Show and block
if (dialog->ShowModal() == wxID_OK)
{
auto selectedHead = dialog->getSelectedHead();

_entities.foreachEntity([&](const IEntityNodePtr& entity)
{
entity->getEntity().setKeyValue(DEF_HEAD_KEY, dialog->getSelectedHead());
entity->getEntity().setKeyValue(DEF_HEAD_KEY, selectedHead);
});

signal_keyValueApplied().emit(DEF_HEAD_KEY, selectedHead);
}

dialog->Destroy();
Expand Down
8 changes: 4 additions & 4 deletions plugins/dm.editing/AIHeadPropertyEditor.h
Expand Up @@ -18,16 +18,16 @@ class AIHeadPropertyEditor final :
private:
// The top-level widget
wxPanel* _widget;

IEntitySelection& _entities;

ITargetKey::Ptr _key;
sigc::signal<void(const std::string&, const std::string&)> _sigKeyValueApplied;

public:
~AIHeadPropertyEditor();
~AIHeadPropertyEditor() override;

wxPanel* getWidget() override;
void updateFromEntities();
void updateFromEntities() override;
sigc::signal<void(const std::string&, const std::string&)>& signal_keyValueApplied() override;

AIHeadPropertyEditor(wxWindow* parent, IEntitySelection& entities, const ITargetKey::Ptr& key);

Expand Down
11 changes: 10 additions & 1 deletion plugins/dm.editing/AIVocalSetPropertyEditor.cpp
Expand Up @@ -48,6 +48,11 @@ void AIVocalSetPropertyEditor::updateFromEntities()
// Nothing to do
}

sigc::signal<void(const std::string&, const std::string&)>& AIVocalSetPropertyEditor::signal_keyValueApplied()
{
return _sigKeyValueApplied;
}

IPropertyEditor::Ptr AIVocalSetPropertyEditor::CreateNew(wxWindow* parent, IEntitySelection& entities,
const ITargetKey::Ptr& key)
{
Expand All @@ -64,10 +69,14 @@ void AIVocalSetPropertyEditor::onChooseButton(wxCommandEvent& ev)
// Show and block
if (dialog->ShowModal() == wxID_OK)
{
auto selectedSet = dialog->getSelectedVocalSet();

_entities.foreachEntity([&](const IEntityNodePtr& entity)
{
entity->getEntity().setKeyValue(DEF_VOCAL_SET_KEY, dialog->getSelectedVocalSet());
entity->getEntity().setKeyValue(DEF_VOCAL_SET_KEY, selectedSet);
});

signal_keyValueApplied().emit(DEF_VOCAL_SET_KEY, selectedSet);
}

dialog->Destroy();
Expand Down
6 changes: 3 additions & 3 deletions plugins/dm.editing/AIVocalSetPropertyEditor.h
Expand Up @@ -18,18 +18,18 @@ class AIVocalSetPropertyEditor final :
private:
// The top-level widget
wxPanel* _widget;

IEntitySelection& _entities;

ITargetKey::Ptr _key;
sigc::signal<void(const std::string&, const std::string&)> _sigKeyValueApplied;

public:
~AIVocalSetPropertyEditor();
~AIVocalSetPropertyEditor() override;

AIVocalSetPropertyEditor(wxWindow* parent, IEntitySelection& entities, const ITargetKey::Ptr& key);

wxPanel* getWidget() override;
void updateFromEntities() override;
sigc::signal<void(const std::string&, const std::string&)>& signal_keyValueApplied() override;

static Ptr CreateNew(wxWindow* parent, IEntitySelection& entities, const ITargetKey::Ptr& key);

Expand Down
7 changes: 7 additions & 0 deletions radiant/ui/einspector/PropertyEditor.cpp
Expand Up @@ -57,6 +57,8 @@ void PropertyEditor::setKeyValue(const std::string& key, const std::string& valu
{
entity->getEntity().setKeyValue(key, value);
});

signal_keyValueApplied().emit(key, value);
}

void PropertyEditor::constructBrowseButtonPanel(wxWindow* parent, const std::string& label,
Expand All @@ -83,4 +85,9 @@ void PropertyEditor::_onBrowseButtonClick(wxCommandEvent& ev)
onBrowseButtonClick();
}

sigc::signal<void(const std::string&, const std::string&)>& PropertyEditor::signal_keyValueApplied()
{
return _sigKeyValueApplied;
}

} // namespace ui
6 changes: 5 additions & 1 deletion radiant/ui/einspector/PropertyEditor.h
Expand Up @@ -40,6 +40,8 @@ class PropertyEditor :
// The selected entities we're working with
IEntitySelection& _entities;

sigc::signal<void(const std::string&, const std::string&)> _sigKeyValueApplied;

// Protected constructor
PropertyEditor(IEntitySelection& entities);

Expand Down Expand Up @@ -83,8 +85,10 @@ class PropertyEditor :
// IPropertyEditor implementation
wxPanel* getWidget() override;

virtual void updateFromEntities() override
void updateFromEntities() override
{}

sigc::signal<void(const std::string&, const std::string&)>& signal_keyValueApplied() override;
};

} // namespace

0 comments on commit b6a9a92

Please sign in to comment.