Skip to content

Commit

Permalink
#6335: Add "Show in Def Tree" button to ClassnamePropertyEditor and I…
Browse files Browse the repository at this point in the history
…nheritPropertyEditor.

Move common code to shared Algorithm source file
  • Loading branch information
codereader committed Jan 14, 2024
1 parent 1fd16d7 commit dea567e
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 34 deletions.
1 change: 1 addition & 0 deletions radiant/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/UserInterfaceModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------

Expand Down
27 changes: 18 additions & 9 deletions radiant/ui/eclasstree/EClassTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@

#include <wx/sizer.h>
#include <wx/splitter.h>
#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() :
Expand All @@ -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();
Expand Down Expand Up @@ -86,6 +85,11 @@ void EClassTree::populateWindow()
splitter->SetSashPosition(static_cast<int>(GetSize().GetWidth() * 0.25f));
}

void EClassTree::setClassNameToPreselect(const std::string& className)
{
_eclassToPreselect = className;
}

wxWindow* EClassTree::createEClassTreeView(wxWindow* parent)
{
auto panel = new wxPanel(parent);
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions radiant/ui/eclasstree/EClassTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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

Expand Down
36 changes: 36 additions & 0 deletions radiant/ui/einspector/Algorithm.cpp
Original file line number Diff line number Diff line change
@@ -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() });
}
}

}

}
19 changes: 19 additions & 0 deletions radiant/ui/einspector/Algorithm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <string>

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);

}

}
27 changes: 15 additions & 12 deletions radiant/ui/einspector/ClassnamePropertyEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@

#include "i18n.h"
#include "ientity.h"
#include "ieclass.h"
#include "icommandsystem.h"

#include <wx/panel.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include "wxutil/EntityClassChooser.h"
#include "wxutil/sourceview/DeclarationSourceView.h"

#include "wxutil/Bitmap.h"
#include "Algorithm.h"

namespace ui
{
Expand All @@ -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)
Expand All @@ -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
3 changes: 1 addition & 2 deletions radiant/ui/einspector/ClassnamePropertyEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 12 additions & 10 deletions radiant/ui/einspector/InheritPropertyEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

#include "i18n.h"
#include "ientity.h"
#include "ieclass.h"

#include <wx/panel.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include "wxutil/sourceview/DeclarationSourceView.h"

#include "wxutil/Bitmap.h"
#include "Algorithm.h"

namespace ui
{
Expand All @@ -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
1 change: 1 addition & 0 deletions radiant/ui/einspector/InheritPropertyEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
<ClCompile Include="..\..\radiant\ui\Documentation.cpp" />
<ClCompile Include="..\..\radiant\ui\eclasstree\EClassTree.cpp" />
<ClCompile Include="..\..\radiant\ui\eclasstree\EClassTreeBuilder.cpp" />
<ClCompile Include="..\..\radiant\ui\einspector\Algorithm.cpp" />
<ClCompile Include="..\..\radiant\ui\einspector\EntityInspectorModule.cpp" />
<ClCompile Include="..\..\radiant\ui\einspector\FxPropertyEditor.cpp" />
<ClCompile Include="..\..\radiant\ui\einspector\InheritPropertyEditor.cpp" />
Expand Down Expand Up @@ -440,6 +441,7 @@
<ClInclude Include="..\..\radiant\ui\Documentation.h" />
<ClInclude Include="..\..\radiant\ui\eclasstree\EClassTree.h" />
<ClInclude Include="..\..\radiant\ui\eclasstree\EClassTreeBuilder.h" />
<ClInclude Include="..\..\radiant\ui\einspector\Algorithm.h" />
<ClInclude Include="..\..\radiant\ui\einspector\EntityInspectorModule.h" />
<ClInclude Include="..\..\radiant\ui\einspector\FxPropertyEditor.h" />
<ClInclude Include="..\..\radiant\ui\einspector\InheritPropertyEditor.h" />
Expand Down
6 changes: 6 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,9 @@
<ClCompile Include="..\..\radiant\ui\einspector\InheritPropertyEditor.cpp">
<Filter>src\ui\einspector</Filter>
</ClCompile>
<ClCompile Include="..\..\radiant\ui\einspector\Algorithm.cpp">
<Filter>src\ui\einspector</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiant\camera\CameraSettings.h">
Expand Down Expand Up @@ -1449,6 +1452,9 @@
<ClInclude Include="..\..\radiant\ui\einspector\InheritPropertyEditor.h">
<Filter>src\ui\einspector</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\ui\einspector\Algorithm.h">
<Filter>src\ui\einspector</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\radiant\darkradiant.rc" />
Expand Down

0 comments on commit dea567e

Please sign in to comment.