From dea567eae068b5675dc4d1c6f6b6e13b168a6b2d Mon Sep 17 00:00:00 2001 From: codereader Date: Sun, 14 Jan 2024 05:42:13 +0100 Subject: [PATCH] #6335: Add "Show in Def Tree" button to ClassnamePropertyEditor and InheritPropertyEditor. Move common code to shared Algorithm source file --- radiant/CMakeLists.txt | 1 + radiant/ui/UserInterfaceModule.cpp | 2 +- radiant/ui/eclasstree/EClassTree.cpp | 27 +++++++++----- radiant/ui/eclasstree/EClassTree.h | 3 ++ radiant/ui/einspector/Algorithm.cpp | 36 +++++++++++++++++++ radiant/ui/einspector/Algorithm.h | 19 ++++++++++ .../ui/einspector/ClassnamePropertyEditor.cpp | 27 +++++++------- .../ui/einspector/ClassnamePropertyEditor.h | 3 +- .../ui/einspector/InheritPropertyEditor.cpp | 22 ++++++------ radiant/ui/einspector/InheritPropertyEditor.h | 1 + tools/msvc/DarkRadiant.vcxproj | 2 ++ tools/msvc/DarkRadiant.vcxproj.filters | 6 ++++ 12 files changed, 115 insertions(+), 34 deletions(-) create mode 100644 radiant/ui/einspector/Algorithm.cpp create mode 100644 radiant/ui/einspector/Algorithm.h diff --git a/radiant/CMakeLists.txt b/radiant/CMakeLists.txt index ceab0f3fa4..5ef959837f 100644 --- a/radiant/CMakeLists.txt +++ b/radiant/CMakeLists.txt @@ -46,6 +46,7 @@ add_executable(darkradiant ui/eclasstree/EClassTreeBuilder.cpp ui/eclasstree/EClassTree.cpp ui/einspector/AddPropertyDialog.cpp + ui/einspector/Algorithm.cpp ui/einspector/AnglePropertyEditor.cpp ui/einspector/BooleanPropertyEditor.cpp ui/einspector/ClassnamePropertyEditor.cpp diff --git a/radiant/ui/UserInterfaceModule.cpp b/radiant/ui/UserInterfaceModule.cpp index ab1ea948b5..7a01e77143 100644 --- a/radiant/ui/UserInterfaceModule.cpp +++ b/radiant/ui/UserInterfaceModule.cpp @@ -485,7 +485,7 @@ void UserInterfaceModule::registerUICommands() GlobalCommandSystem().addCommand("ExportSelectedAsModelDialog", ExportAsModelDialog::ShowDialog); GlobalCommandSystem().addCommand("ConvertModelDialog", ConvertModelDialog::ShowDialog); - GlobalCommandSystem().addCommand("EntityClassTree", EClassTree::ShowDialog); + GlobalCommandSystem().addCommand("EntityClassTree", EClassTree::ShowDialog, { cmd::ARGTYPE_STRING | cmd::ARGTYPE_OPTIONAL }); // ----------------------- Bind Events --------------------------------------- diff --git a/radiant/ui/eclasstree/EClassTree.cpp b/radiant/ui/eclasstree/EClassTree.cpp index 4346ff734c..364a316323 100644 --- a/radiant/ui/eclasstree/EClassTree.cpp +++ b/radiant/ui/eclasstree/EClassTree.cpp @@ -11,14 +11,13 @@ #include #include -#include "wxutil/Bitmap.h" namespace ui { namespace { - constexpr const char* const ECLASSTREE_TITLE = N_("Entity Class Tree"); + constexpr const char* const ECLASSTREE_TITLE = N_("EntityDef Tree"); } EClassTree::EClassTree() : @@ -35,10 +34,10 @@ EClassTree::EClassTree() : void EClassTree::onTreeViewPopulationFinished(wxutil::ResourceTreeView::PopulationFinishedEvent& ev) { - std::string className; + auto className = _eclassToPreselect; // Do we have anything selected - if (GlobalSelectionSystem().countSelected() > 0) + if (className.empty() && GlobalSelectionSystem().countSelected() > 0) { // Get the last selected node and check if it's an entity auto lastSelected = GlobalSelectionSystem().ultimateSelected(); @@ -86,6 +85,11 @@ void EClassTree::populateWindow() splitter->SetSashPosition(static_cast(GetSize().GetWidth() * 0.25f)); } +void EClassTree::setClassNameToPreselect(const std::string& className) +{ + _eclassToPreselect = className; +} + wxWindow* EClassTree::createEClassTreeView(wxWindow* parent) { auto panel = new wxPanel(parent); @@ -163,14 +167,19 @@ void EClassTree::updatePropertyView(const std::string& eclassName) }, true); } -// Static command target void EClassTree::ShowDialog(const cmd::ArgumentList& args) { - // Construct a new instance, this enters the main loop - auto* tree = new EClassTree(); + // Construct a new instance, this enters the main loop + auto tree = new EClassTree(); + + // Accept a classname to preselect from the argument list + if (args.size() == 1) + { + tree->setClassNameToPreselect(args[0].getString()); + } - tree->ShowModal(); - tree->Destroy(); + tree->ShowModal(); + tree->Destroy(); } void EClassTree::handleSelectionChange() diff --git a/radiant/ui/eclasstree/EClassTree.h b/radiant/ui/eclasstree/EClassTree.h index 788ebd6a86..5ecb402e37 100644 --- a/radiant/ui/eclasstree/EClassTree.h +++ b/radiant/ui/eclasstree/EClassTree.h @@ -37,6 +37,7 @@ class EClassTree : PropertyListColumns _propertyColumns; wxutil::TreeModel::Ptr _propertyStore; wxutil::TreeView* _propertyView; + std::string _eclassToPreselect; // Private constructor, traverses the entity classes EClassTree(); @@ -49,6 +50,8 @@ class EClassTree : // Constructs and adds all the dialog widgets void populateWindow(); + void setClassNameToPreselect(const std::string& className); + wxWindow* createEClassTreeView(wxWindow* parent); // EClass Tree void createPropertyTreeView(wxWindow* parent); // Property Tree diff --git a/radiant/ui/einspector/Algorithm.cpp b/radiant/ui/einspector/Algorithm.cpp new file mode 100644 index 0000000000..48c7b5207d --- /dev/null +++ b/radiant/ui/einspector/Algorithm.cpp @@ -0,0 +1,36 @@ +#include "Algorithm.h" + +#include "ieclass.h" +#include "icommandsystem.h" + +#include "wxutil/sourceview/DeclarationSourceView.h" + +namespace ui +{ + +namespace algorithm +{ + +void showEntityClassDefinition(wxWindow* parent, const std::string& entityClassName) +{ + if (auto eclass = GlobalEntityClassManager().findClass(entityClassName); eclass) + { + auto view = new wxutil::DeclarationSourceView(parent); + view->setDeclaration(eclass); + + view->ShowModal(); + view->Destroy(); + } +} + +void showEntityClassInTree(const std::string& entityClassName) +{ + if (auto eclass = GlobalEntityClassManager().findClass(entityClassName); eclass) + { + GlobalCommandSystem().executeCommand("EntityClassTree", cmd::ArgumentList{ eclass->getDeclName() }); + } +} + +} + +} diff --git a/radiant/ui/einspector/Algorithm.h b/radiant/ui/einspector/Algorithm.h new file mode 100644 index 0000000000..105f860cd1 --- /dev/null +++ b/radiant/ui/einspector/Algorithm.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +namespace ui +{ + +namespace algorithm +{ + +// If the given entity class exists, this shows a DeclarationSourceView dialog with its definition +void showEntityClassDefinition(wxWindow* parent, const std::string& eclass); + +// If the given entity class exists, the entity class tree dialog is shown with the given class pre-selected +void showEntityClassInTree(const std::string& eclass); + +} + +} diff --git a/radiant/ui/einspector/ClassnamePropertyEditor.cpp b/radiant/ui/einspector/ClassnamePropertyEditor.cpp index 748c3f757e..191f7de3cd 100644 --- a/radiant/ui/einspector/ClassnamePropertyEditor.cpp +++ b/radiant/ui/einspector/ClassnamePropertyEditor.cpp @@ -3,16 +3,15 @@ #include "i18n.h" #include "ientity.h" -#include "ieclass.h" #include "icommandsystem.h" #include #include #include #include "wxutil/EntityClassChooser.h" -#include "wxutil/sourceview/DeclarationSourceView.h" #include "wxutil/Bitmap.h" +#include "Algorithm.h" namespace ui { @@ -28,16 +27,21 @@ ClassnamePropertyEditor::ClassnamePropertyEditor(wxWindow* parent, IEntitySelect // Register the main widget in the base class setMainWidget(mainVBox); - wxButton* browseButton = new wxButton(mainVBox, wxID_ANY, _("Choose Entity Class...")); + auto browseButton = new wxButton(mainVBox, wxID_ANY, _("Choose Entity Class...")); browseButton->SetBitmap(PropertyEditorFactory::getBitmapFor("classname")); browseButton->Bind(wxEVT_BUTTON, &ClassnamePropertyEditor::_onBrowseButton, this); - wxButton* showDefinition = new wxButton(mainVBox, wxID_ANY, _("Show Definition...")); + auto showDefinition = new wxButton(mainVBox, wxID_ANY, _("Show Definition...")); showDefinition->SetBitmap(wxutil::GetLocalBitmap("decl.png")); showDefinition->Bind(wxEVT_BUTTON, &ClassnamePropertyEditor::_onShowDefinition, this); + auto showInDefTree = new wxButton(mainVBox, wxID_ANY, _("Show in Def Tree...")); + showInDefTree->SetBitmap(PropertyEditorFactory::getBitmapFor("classname")); + showInDefTree->Bind(wxEVT_BUTTON, &ClassnamePropertyEditor::_onShowInDefTree, this); + mainVBox->GetSizer()->Add(browseButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 6); mainVBox->GetSizer()->Add(showDefinition, 0, wxALIGN_CENTER_VERTICAL | wxALL, 6); + mainVBox->GetSizer()->Add(showInDefTree, 0, wxALIGN_CENTER_VERTICAL | wxALL, 6); } void ClassnamePropertyEditor::_onBrowseButton(wxCommandEvent& ev) @@ -61,16 +65,15 @@ void ClassnamePropertyEditor::_onBrowseButton(wxCommandEvent& ev) void ClassnamePropertyEditor::_onShowDefinition(wxCommandEvent& ev) { auto currentEclass = _entities.getSharedKeyValue(_key->getFullKey(), true); - auto eclass = GlobalEntityClassManager().findClass(currentEclass); - if (eclass) - { - auto view = new wxutil::DeclarationSourceView(getWidget()); - view->setDeclaration(eclass); + algorithm::showEntityClassDefinition(getWidget(), currentEclass); +} + +void ClassnamePropertyEditor::_onShowInDefTree(wxCommandEvent& ev) +{ + auto currentEclass = _entities.getSharedKeyValue(_key->getFullKey(), true); - view->ShowModal(); - view->Destroy(); - } + algorithm::showEntityClassInTree(currentEclass); } } // namespace ui diff --git a/radiant/ui/einspector/ClassnamePropertyEditor.h b/radiant/ui/einspector/ClassnamePropertyEditor.h index c8a31e4755..a9c5e3d347 100644 --- a/radiant/ui/einspector/ClassnamePropertyEditor.h +++ b/radiant/ui/einspector/ClassnamePropertyEditor.h @@ -23,10 +23,9 @@ class ClassnamePropertyEditor : void _onBrowseButton(wxCommandEvent& ev); void _onShowDefinition(wxCommandEvent& ev); + void _onShowInDefTree(wxCommandEvent& ev); public: - - // Main constructor ClassnamePropertyEditor(wxWindow* parent, IEntitySelection& entities, const ITargetKey::Ptr& key); static Ptr CreateNew(wxWindow* parent, IEntitySelection& entities, const ITargetKey::Ptr& key) diff --git a/radiant/ui/einspector/InheritPropertyEditor.cpp b/radiant/ui/einspector/InheritPropertyEditor.cpp index 52cd7983f4..826adb53bd 100644 --- a/radiant/ui/einspector/InheritPropertyEditor.cpp +++ b/radiant/ui/einspector/InheritPropertyEditor.cpp @@ -3,14 +3,13 @@ #include "i18n.h" #include "ientity.h" -#include "ieclass.h" #include #include #include -#include "wxutil/sourceview/DeclarationSourceView.h" #include "wxutil/Bitmap.h" +#include "Algorithm.h" namespace ui { @@ -30,22 +29,25 @@ InheritPropertyEditor::InheritPropertyEditor(wxWindow* parent, IEntitySelection& showDefinition->SetBitmap(wxutil::GetLocalBitmap("decl.png")); showDefinition->Bind(wxEVT_BUTTON, &InheritPropertyEditor::_onShowDefinition, this); + auto showInDefTree = new wxButton(mainVBox, wxID_ANY, _("Show in Def Tree...")); + showInDefTree->SetBitmap(PropertyEditorFactory::getBitmapFor("classname")); + showInDefTree->Bind(wxEVT_BUTTON, &InheritPropertyEditor::_onShowInDefTree, this); + mainVBox->GetSizer()->Add(showDefinition, 0, wxALIGN_CENTER_VERTICAL | wxALL, 6); + mainVBox->GetSizer()->Add(showInDefTree, 0, wxALIGN_CENTER_VERTICAL | wxALL, 6); } void InheritPropertyEditor::_onShowDefinition(wxCommandEvent& ev) { auto parentClass = _entities.getSharedKeyValue(_key->getFullKey(), true); - auto eclass = GlobalEntityClassManager().findClass(parentClass); + algorithm::showEntityClassDefinition(getWidget(), parentClass); +} - if (eclass) - { - auto view = new wxutil::DeclarationSourceView(getWidget()); - view->setDeclaration(eclass); +void InheritPropertyEditor::_onShowInDefTree(wxCommandEvent& ev) +{ + auto currentEclass = _entities.getSharedKeyValue(_key->getFullKey(), true); - view->ShowModal(); - view->Destroy(); - } + algorithm::showEntityClassInTree(currentEclass); } } // namespace ui diff --git a/radiant/ui/einspector/InheritPropertyEditor.h b/radiant/ui/einspector/InheritPropertyEditor.h index 9fa3d916fe..ed851c6228 100644 --- a/radiant/ui/einspector/InheritPropertyEditor.h +++ b/radiant/ui/einspector/InheritPropertyEditor.h @@ -21,6 +21,7 @@ class InheritPropertyEditor : private: void _onShowDefinition(wxCommandEvent& ev); + void _onShowInDefTree(wxCommandEvent& ev); public: InheritPropertyEditor(wxWindow* parent, IEntitySelection& entities, const ITargetKey::Ptr& key); diff --git a/tools/msvc/DarkRadiant.vcxproj b/tools/msvc/DarkRadiant.vcxproj index 1a517d9f23..7bf205fb92 100644 --- a/tools/msvc/DarkRadiant.vcxproj +++ b/tools/msvc/DarkRadiant.vcxproj @@ -241,6 +241,7 @@ + @@ -440,6 +441,7 @@ + diff --git a/tools/msvc/DarkRadiant.vcxproj.filters b/tools/msvc/DarkRadiant.vcxproj.filters index cc6c76255c..28be2aa6f9 100644 --- a/tools/msvc/DarkRadiant.vcxproj.filters +++ b/tools/msvc/DarkRadiant.vcxproj.filters @@ -721,6 +721,9 @@ src\ui\einspector + + src\ui\einspector + @@ -1449,6 +1452,9 @@ src\ui\einspector + + src\ui\einspector +