Skip to content

Commit

Permalink
#5743: Add "Show Definition..." context menu option to ModelTreeView …
Browse files Browse the repository at this point in the history
…that is active when a valid modelDef is selected
  • Loading branch information
codereader committed Jul 30, 2022
1 parent b089c5f commit b821096
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
34 changes: 34 additions & 0 deletions radiant/ui/modelselector/ModelTreeView.cpp
@@ -1,6 +1,9 @@
#include "ModelTreeView.h"

#include "ideclmanager.h"
#include "ModelPopulator.h"
#include "wxutil/menu/IconTextMenuItem.h"
#include "wxutil/sourceview/DeclarationSourceView.h"

namespace ui
{
Expand All @@ -19,6 +22,11 @@ ModelTreeView::ModelTreeView(wxWindow* parent) :
// Use the TreeModel's full string search function
AddSearchColumn(Columns().iconAndName);
EnableFavouriteManagement("model");

AddCustomMenuItem(std::make_shared<wxutil::MenuItem>(
new wxutil::IconTextMenuItem(_("Show Definition"), "decl.png"),
std::bind(&ModelTreeView::showModelDefinition, this),
std::bind(&ModelTreeView::testShowModelDefinition, this)));
}

const ModelTreeView::TreeColumns& ModelTreeView::Columns() const
Expand Down Expand Up @@ -110,4 +118,30 @@ std::string ModelTreeView::GetColumnValue(const wxutil::TreeModel::Column& colum
return row[column];
}

void ModelTreeView::showModelDefinition()
{
auto selectedModelPath = GetColumnValue(Columns().modelPath);
auto modelDef = GlobalDeclarationManager().findDeclaration(decl::Type::ModelDef, selectedModelPath);

if (modelDef)
{
auto view = new wxutil::DeclarationSourceView(this);
view->setDeclaration(modelDef);

view->ShowModal();
view->Destroy();
}
}

bool ModelTreeView::testShowModelDefinition()
{
if (IsDirectorySelected()) return false;

auto selectedModelPath = GetColumnValue(Columns().modelPath);

auto modelDef = GlobalDeclarationManager().findDeclaration(decl::Type::ModelDef, selectedModelPath);

return modelDef != nullptr;
}

}
2 changes: 2 additions & 0 deletions radiant/ui/modelselector/ModelTreeView.h
Expand Up @@ -58,6 +58,8 @@ class ModelTreeView final :

private:
std::string GetColumnValue(const wxutil::TreeModel::Column& column);
void showModelDefinition();
bool testShowModelDefinition();
};

}

0 comments on commit b821096

Please sign in to comment.