Skip to content

Commit

Permalink
#5700: Rename the PropertyEditor base method for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Nov 13, 2022
1 parent b6a9a92 commit e0ce5a1
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion radiant/ui/einspector/AnglePropertyEditor.cpp
Expand Up @@ -67,7 +67,7 @@ void AnglePropertyEditor::_onButtonClick(wxCommandEvent& ev)
{
if (i->first->GetId() == ev.GetId())
{
setKeyValue(_key->getFullKey(), string::to_string(i->second));
setKeyValueOnSelection(_key->getFullKey(), string::to_string(i->second));
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/einspector/BooleanPropertyEditor.cpp
Expand Up @@ -41,7 +41,7 @@ void BooleanPropertyEditor::updateFromEntity()
void BooleanPropertyEditor::_onToggle(wxCommandEvent& ev)
{
// Set the key based on the checkbutton state
setKeyValue(_key->getFullKey(), _checkBox->IsChecked() ? "1" : "0");
setKeyValueOnSelection(_key->getFullKey(), _checkBox->IsChecked() ? "1" : "0");
}

} // namespace
4 changes: 2 additions & 2 deletions radiant/ui/einspector/ColourPropertyEditor.cpp
Expand Up @@ -40,7 +40,7 @@ ColourPropertyEditor::ColourPropertyEditor(wxWindow* parent, IEntitySelection& e
void ColourPropertyEditor::updateFromEntity()
{
// Set colour button's colour, also take inherited values into account
setColourButton(_entities.getSharedKeyValue(_key->getFullKey(), true));
setColourButton(getKeyValueFromSelection(_key->getFullKey()));
}

// Set displayed colour from the keyvalue
Expand Down Expand Up @@ -73,7 +73,7 @@ std::string ColourPropertyEditor::getSelectedColour()
void ColourPropertyEditor::_onColorSet(wxColourPickerEvent& ev)
{
// Set the new keyvalue on the entity
setKeyValue(_key->getFullKey(), getSelectedColour());
setKeyValueOnSelection(_key->getFullKey(), getSelectedColour());
}


Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/einspector/EntityPropertyEditor.cpp
Expand Up @@ -37,7 +37,7 @@ void EntityPropertyEditor::onBrowseButtonClick()
UndoableCommand cmd("changeKeyValue");

// Apply the change
setKeyValue(_key->getFullKey(), selection);
setKeyValueOnSelection(_key->getFullKey(), selection);
}
}

Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/einspector/FloatPropertyEditor.cpp
Expand Up @@ -59,7 +59,7 @@ void FloatPropertyEditor::_onApply(wxCommandEvent& ev)
{
float value = static_cast<float>(_spinCtrl->GetValue());

setKeyValue(_key->getFullKey(), string::to_string(value));
setKeyValueOnSelection(_key->getFullKey(), string::to_string(value));
}

}
14 changes: 8 additions & 6 deletions radiant/ui/einspector/ModelPropertyEditor.cpp
Expand Up @@ -92,31 +92,33 @@ void ModelPropertyEditor::_onModelButton(wxCommandEvent& ev)

// Save the model key now
entity.setKeyValue(_key->getFullKey(), result.name);

signal_keyValueApplied().emit(_key->getFullKey(), result.name);
}
});
}

void ModelPropertyEditor::_onParticleButton(wxCommandEvent& ev)
{
// Invoke ParticlesChooser
std::string currentSelection = _entities.getSharedKeyValue(_key->getFullKey(), true);
std::string currentSelection = getKeyValueFromSelection(_key->getFullKey());
std::string particle = ParticleChooserDialog::ChooseParticle(currentSelection);

if (!particle.empty())
{
setKeyValue(_key->getFullKey(), particle);
setKeyValueOnSelection(_key->getFullKey(), particle);
}
}

void ModelPropertyEditor::_onSkinButton(wxCommandEvent& ev)
{
// Check the key this model property editor is attached to first
auto model = _entities.getSharedKeyValue(_key->getFullKey(), true);
auto model = getKeyValueFromSelection(_key->getFullKey());

// Fall back to "model" if nothing found
if (model.empty())
{
model = _entities.getSharedKeyValue("model", true);
model = getKeyValueFromSelection("model");
}

if (model.empty())
Expand All @@ -130,13 +132,13 @@ void ModelPropertyEditor::_onSkinButton(wxCommandEvent& ev)
auto skinKey = _key->clone();
skinKey->setAffectedKey("skin");

std::string prevSkin = _entities.getSharedKeyValue(skinKey->getFullKey(), true);
std::string prevSkin = getKeyValueFromSelection(skinKey->getFullKey());
std::string skin = SkinChooser::ChooseSkin(model, prevSkin);

if (skin != prevSkin)
{
// Apply the key to the entity
setKeyValue(skinKey->getFullKey(), skin);
setKeyValueOnSelection(skinKey->getFullKey(), skin);
}
}

Expand Down
4 changes: 2 additions & 2 deletions radiant/ui/einspector/PropertyEditor.cpp
Expand Up @@ -42,12 +42,12 @@ wxPanel* PropertyEditor::getWidget()
return _mainWidget;
}

std::string PropertyEditor::getKeyValue(const std::string& key)
std::string PropertyEditor::getKeyValueFromSelection(const std::string& key)
{
return _entities.getSharedKeyValue(key, true);
}

void PropertyEditor::setKeyValue(const std::string& key, const std::string& value)
void PropertyEditor::setKeyValueOnSelection(const std::string& key, const std::string& value)
{
if (_entities.empty()) return;

Expand Down
5 changes: 3 additions & 2 deletions radiant/ui/einspector/PropertyEditor.h
Expand Up @@ -58,12 +58,13 @@ class PropertyEditor :
* 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);
virtual void setKeyValueOnSelection(const std::string& key, const std::string& value);

/**
* greebo: Convenience method to retrieve a keyvalue from the edited entity.
* Note: This also considers inherited key values.
*/
virtual std::string getKeyValue(const std::string& key);
virtual std::string getKeyValueFromSelection(const std::string& key);

/**
* greebo: Since many property editors consists of a single browse button,
Expand Down
6 changes: 3 additions & 3 deletions radiant/ui/einspector/SkinPropertyEditor.cpp
Expand Up @@ -28,7 +28,7 @@ void SkinPropertyEditor::onBrowseButtonClick()
auto modelKey = _key->clone();
modelKey->setAffectedKey("model");

auto model = _entities.getSharedKeyValue(modelKey->getFullKey(), true);
auto model = getKeyValueFromSelection(modelKey->getFullKey());

if (model.empty())
{
Expand All @@ -38,11 +38,11 @@ void SkinPropertyEditor::onBrowseButtonClick()
}

// Display the SkinChooser to get a skin from the user
std::string prevSkin = _entities.getSharedKeyValue(_key->getFullKey(), true);
std::string prevSkin = getKeyValueFromSelection(_key->getFullKey());
std::string skin = SkinChooser::ChooseSkin(model, prevSkin);

// Apply the key to the entity
setKeyValue(_key->getFullKey(), skin);
setKeyValueOnSelection(_key->getFullKey(), skin);
}

std::string SkinChooserDialogWrapper::runDialog(Entity* entity, const std::string& key)
Expand Down
4 changes: 2 additions & 2 deletions radiant/ui/einspector/SoundPropertyEditor.cpp
Expand Up @@ -33,13 +33,13 @@ void SoundPropertyEditor::onBrowseButtonClick()
IResourceChooser* chooser = GlobalDialogManager().createSoundShaderChooser(wxGetTopLevelParent(getWidget()));

// Use a SoundChooser dialog to get a selection from the user
std::string picked = chooser->chooseResource(getKeyValue(_key->getFullKey()));
std::string picked = chooser->chooseResource(getKeyValueFromSelection(_key->getFullKey()));

// Selection will be empy if user clicked cancel or X
if (!picked.empty())
{
// Apply the change to the entity
setKeyValue(_key->getFullKey(), picked);
setKeyValueOnSelection(_key->getFullKey(), picked);
}

chooser->destroyDialog();
Expand Down
4 changes: 2 additions & 2 deletions radiant/ui/einspector/TexturePropertyEditor.cpp
Expand Up @@ -26,7 +26,7 @@ void TexturePropertyEditor::onBrowseButtonClick()
{
auto dialog = new MaterialChooser(getWidget(), MaterialSelector::TextureFilter::Lights);

dialog->SetSelectedDeclName(getKeyValue(_key->getFullKey()));
dialog->SetSelectedDeclName(getKeyValueFromSelection(_key->getFullKey()));

if (dialog->ShowModal() == wxID_OK)
{
Expand All @@ -36,7 +36,7 @@ void TexturePropertyEditor::onBrowseButtonClick()
if (!texture.empty())
{
// Apply the keyvalue immediately
setKeyValue(_key->getFullKey(), texture);
setKeyValueOnSelection(_key->getFullKey(), texture);
}
}

Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/einspector/Vector3PropertyEditor.cpp
Expand Up @@ -107,7 +107,7 @@ void Vector3PropertyEditor::_onApply(wxCommandEvent& ev)
+ string::to_string(_zValue->GetValue());

// Set the key on the entity
setKeyValue(_key->getFullKey(), value);
setKeyValueOnSelection(_key->getFullKey(), value);
}

}

0 comments on commit e0ce5a1

Please sign in to comment.