diff --git a/libs/wxutil/EntityClassChooser.cpp b/libs/wxutil/EntityClassChooser.cpp index 25edc8baa8..de855d9c83 100644 --- a/libs/wxutil/EntityClassChooser.cpp +++ b/libs/wxutil/EntityClassChooser.cpp @@ -1,5 +1,6 @@ #include "EntityClassChooser.h" +#include #include "dataview/TreeModel.h" #include "dataview/TreeViewItemStyle.h" #include "dataview/ThreadedResourceTreePopulator.h" @@ -26,7 +27,9 @@ namespace wxutil namespace { - const char* const ECLASS_CHOOSER_TITLE = N_("Create entity"); + const char* const TITLE_ADD_ENTITY = N_("Create Entity"); + const char* const TITLE_CONVERT_TO_ENTITY = N_("Convert to Entity"); + const char* const TITLE_SELECT_ENTITY = N_("Select Entity Class"); const char* const RKEY_SPLIT_POS = "user/ui/entityClassChooser/splitPos"; const char* const RKEY_WINDOW_STATE = "user/ui/entityClassChooser/window"; const char* const RKEY_LAST_SELECTED_ECLASS = "user/ui/entityClassChooser/lastSelectedEclass"; @@ -36,6 +39,18 @@ namespace // Registry XPath to lookup key that specifies the display folder const char* const FOLDER_KEY_PATH = "/entityChooser/displayFolderKey"; + + std::string getDialogTitle(EntityClassChooser::Purpose purpose) + { + switch (purpose) + { + case EntityClassChooser::Purpose::AddEntity: return _(TITLE_ADD_ENTITY); + case EntityClassChooser::Purpose::ConvertEntity: return _(TITLE_CONVERT_TO_ENTITY); + case EntityClassChooser::Purpose::SelectClassname: return _(TITLE_SELECT_ENTITY); + default: + throw std::logic_error("Unknown entity class chooser purpose"); + } + } } /* @@ -146,18 +161,31 @@ class ThreadedEntityClassLoader final : }; // Main constructor -EntityClassChooser::EntityClassChooser() : - DialogBase(_(ECLASS_CHOOSER_TITLE)), +EntityClassChooser::EntityClassChooser(Purpose purpose) : + DialogBase(getDialogTitle(purpose)), _treeView(nullptr), _selectedName("") { loadNamedPanel(this, "EntityClassChooserMainPanel"); // Connect button signals - findNamedObject(this, "EntityClassChooserAddButton")->Bind( - wxEVT_BUTTON, &EntityClassChooser::onOK, this); - findNamedObject(this, "EntityClassChooserAddButton")->SetBitmap( - wxArtProvider::GetBitmap(wxART_PLUS)); + auto confirmButton = findNamedObject(this, "EntityClassChooserAddButton"); + confirmButton->Bind(wxEVT_BUTTON, &EntityClassChooser::onOK, this); + + switch (purpose) + { + case EntityClassChooser::Purpose::AddEntity: + confirmButton->SetBitmap(wxArtProvider::GetBitmap(wxART_PLUS)); + break; + case EntityClassChooser::Purpose::ConvertEntity: + confirmButton->SetLabelText(_("Convert")); + break; + case EntityClassChooser::Purpose::SelectClassname: + confirmButton->SetLabelText(_("Select")); + break; + default: + throw std::logic_error("Unknown entity class chooser purpose"); + } findNamedObject(this, "EntityClassChooserCancelButton")->Bind( wxEVT_BUTTON, &EntityClassChooser::onCancel, this); @@ -208,9 +236,9 @@ EntityClassChooser::~EntityClassChooser() } // Display the singleton instance -std::string EntityClassChooser::chooseEntityClass(const std::string& eclassToSelect) +std::string EntityClassChooser::ChooseEntityClass(Purpose purpose, const std::string& eclassToSelect) { - EntityClassChooser instance; + EntityClassChooser instance{ purpose }; // Fall back to the value we saved in the registry if we didn't get any other instructions auto preselectEclass = !eclassToSelect.empty() ? eclassToSelect : diff --git a/libs/wxutil/EntityClassChooser.h b/libs/wxutil/EntityClassChooser.h index 10cd08ad50..65bd3af2a0 100644 --- a/libs/wxutil/EntityClassChooser.h +++ b/libs/wxutil/EntityClassChooser.h @@ -28,6 +28,16 @@ class EntityClassChooser final : public DialogBase, private XmlResourceBasedWidget { +public: + // Enumeration of possible modes of this dialog + // Influences the dialog title and button labels + enum class Purpose + { + AddEntity, + ConvertEntity, + SelectClassname, + }; + private: ResourceTreeView::Columns _columns; ResourceTreeView* _treeView; @@ -45,7 +55,7 @@ class EntityClassChooser final : sigc::connection _defsReloaded; private: - EntityClassChooser(); + EntityClassChooser(Purpose purpose); ~EntityClassChooser(); void loadEntityClasses(); @@ -81,12 +91,15 @@ class EntityClassChooser final : /** * \brief Construct and show the dialog to choose an entity class, * returning the result. + * + * \param purpose + * The scenario this dialog has been requested for * * \param preselectEclass * Optional initial class to locate and highlight in the tree after the * dialog is shown. */ - static std::string chooseEntityClass(const std::string& preselectEclass = {}); + static std::string ChooseEntityClass(Purpose purpose, const std::string& preselectEclass = {}); }; } // namespace diff --git a/plugins/dm.difficulty/DifficultyEditor.cpp b/plugins/dm.difficulty/DifficultyEditor.cpp index a4375621a8..443e7c5e6c 100644 --- a/plugins/dm.difficulty/DifficultyEditor.cpp +++ b/plugins/dm.difficulty/DifficultyEditor.cpp @@ -98,11 +98,14 @@ void DifficultyEditor::populateWindow() void DifficultyEditor::chooseEntityClass() { // Show dialog and set the entry box text with the chosen entity class - std::string chosenEntity = wxutil::EntityClassChooser::chooseEntityClass( - _classEntry->GetValue().ToStdString() + auto chosenEntity = wxutil::EntityClassChooser::ChooseEntityClass( + wxutil::EntityClassChooser::Purpose::SelectClassname, _classEntry->GetValue().ToStdString() ); + if (!chosenEntity.empty()) + { _classEntry->SetValue(chosenEntity); + } } int DifficultyEditor::getSelectedSettingId() diff --git a/radiant/ui/einspector/ClassnamePropertyEditor.cpp b/radiant/ui/einspector/ClassnamePropertyEditor.cpp index 9e0481aefb..0efe03e49e 100644 --- a/radiant/ui/einspector/ClassnamePropertyEditor.cpp +++ b/radiant/ui/einspector/ClassnamePropertyEditor.cpp @@ -23,7 +23,7 @@ ClassnamePropertyEditor::ClassnamePropertyEditor(wxWindow* parent, IEntitySelect : PropertyEditor(entities), _key(name) { - constructBrowseButtonPanel(parent, _("Choose entity class..."), + constructBrowseButtonPanel(parent, _("Choose Entity Class..."), PropertyEditorFactory::getBitmapFor("classname")); } @@ -32,7 +32,8 @@ void ClassnamePropertyEditor::onBrowseButtonClick() std::string currentEclass = _entities.getSharedKeyValue(_key, false); // Use the EntityClassChooser dialog to get a selection from the user - std::string selection = wxutil::EntityClassChooser::chooseEntityClass(currentEclass); + std::string selection = wxutil::EntityClassChooser::ChooseEntityClass( + wxutil::EntityClassChooser::Purpose::SelectClassname, currentEclass); // Only apply if the classname has actually changed if (!selection.empty() && selection != currentEclass) diff --git a/radiant/ui/materials/editor/MaterialEditor.cpp b/radiant/ui/materials/editor/MaterialEditor.cpp index f426535bb9..06806b40d0 100644 --- a/radiant/ui/materials/editor/MaterialEditor.cpp +++ b/radiant/ui/materials/editor/MaterialEditor.cpp @@ -309,7 +309,8 @@ void MaterialEditor::setupPreviewLightProperties(wxWindow* previewPanel) getControl("MaterialPreviewLightChooseClassnameButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev) { auto textCtrl = getControl("MaterialPreviewLightClassname"); - auto newClassName = wxutil::EntityClassChooser::chooseEntityClass(textCtrl->GetValue().ToStdString()); + auto newClassName = wxutil::EntityClassChooser::ChooseEntityClass( + wxutil::EntityClassChooser::Purpose::SelectClassname, textCtrl->GetValue().ToStdString()); textCtrl->SetValue(newClassName); }); diff --git a/radiant/ui/ortho/OrthoContextMenu.cpp b/radiant/ui/ortho/OrthoContextMenu.cpp index fdc68b1257..b559e115af 100644 --- a/radiant/ui/ortho/OrthoContextMenu.cpp +++ b/radiant/ui/ortho/OrthoContextMenu.cpp @@ -249,22 +249,25 @@ std::string OrthoContextMenu::getRegistryKeyWithDefault( void OrthoContextMenu::addEntity() { // Display the chooser to select an entity classname - std::string cName = wxutil::EntityClassChooser::chooseEntityClass(); + auto purpose = _selectionInfo.anythingSelected ? + wxutil::EntityClassChooser::Purpose::ConvertEntity : + wxutil::EntityClassChooser::Purpose::AddEntity; - if (!cName.empty()) - { - UndoableCommand command("createEntity"); + auto className = wxutil::EntityClassChooser::ChooseEntityClass(purpose); - // Create the entity. We might get an EntityCreationException if the - // wrong number of brushes is selected. - try - { - GlobalEntityModule().createEntityFromSelection(cName, _lastPoint); - } - catch (cmd::ExecutionFailure& e) - { - wxutil::Messagebox::ShowError(e.what()); - } + if (className.empty()) return; + + UndoableCommand command(_selectionInfo.anythingSelected ? "convertToEntity" : "createEntity"); + + // Create the entity. We might get an EntityCreationException if the + // wrong number of brushes is selected. + try + { + GlobalEntityModule().createEntityFromSelection(className, _lastPoint); + } + catch (cmd::ExecutionFailure& e) + { + wxutil::Messagebox::ShowError(e.what()); } }