Skip to content

Commit

Permalink
#6021: Add ability to switch the shown declaration at a later point. …
Browse files Browse the repository at this point in the history
…Monitor the declaration for changes
  • Loading branch information
codereader committed Jul 29, 2022
1 parent bd51b60 commit 103f87b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
49 changes: 45 additions & 4 deletions libs/wxutil/DeclarationSourceView.h
@@ -1,5 +1,6 @@
#pragma once

#include <sigc++/connection.h>
#include "ideclmanager.h"
#include "i18n.h"
#include "fmt/format.h"
Expand All @@ -9,28 +10,62 @@
namespace wxutil
{

/**
* DefinitionView implementation specialising on Declarations
*/
class DeclarationSourceView :
public DefinitionView
{
private:
decl::IDeclaration::Ptr _decl;

sigc::connection _declChangedConn;

public:
DeclarationSourceView(const decl::IDeclaration::Ptr& decl, wxWindow* parent) :
DefinitionView(fmt::format(_("Declaration Source: {0}"), decl->getDeclName()), parent),
_decl(decl)
DeclarationSourceView(const decl::Type& type, wxWindow* parent) :
DefinitionView("", parent)
{
// Pick the correct source view control based on the given type
switch (_decl->getDeclType())
switch (type)
{
case decl::Type::SoundShader:
addSourceView(new D3SoundShaderSourceViewCtrl(getMainPanel()));
break;
case decl::Type::Material:
addSourceView(new D3MaterialSourceViewCtrl(getMainPanel()));
break;
default:
addSourceView(new D3DeclarationViewCtrl(getMainPanel()));
}
}

~DeclarationSourceView()
{
_declChangedConn.disconnect();
}

void setDeclaration(const decl::IDeclaration::Ptr& decl)
{
_declChangedConn.disconnect();

_decl = decl;

if (_decl)
{
_declChangedConn = _decl->signal_DeclarationChanged().connect(
sigc::mem_fun(*this, &DeclarationSourceView::update)
);
}

update();
updateTitle();
}

void setDeclaration(decl::Type type, const std::string& declName)
{
setDeclaration(GlobalDeclarationManager().findDeclaration(type, declName));
}

protected:
bool isEmpty() const override
{
Expand All @@ -51,6 +86,12 @@ class DeclarationSourceView :
{
return _decl ? _decl->getBlockSyntax().contents : "";
}

private:
void updateTitle()
{
SetTitle(fmt::format(_("Declaration Source: {0}"), !isEmpty() ? _decl->getDeclName() : ""));
}
};

}
5 changes: 4 additions & 1 deletion libs/wxutil/dataview/DeclarationTreeView.cpp
Expand Up @@ -45,7 +45,10 @@ void DeclarationTreeView::PopulateContextMenu(wxutil::PopupMenu& popupMenu)

DeclarationSourceView* DeclarationTreeView::CreateDeclarationView(const decl::IDeclaration::Ptr& decl)
{
return new DeclarationSourceView(decl, this);
auto view = new DeclarationSourceView(decl->getDeclType(), this);
view->setDeclaration(decl);

return view;
}

void DeclarationTreeView::_onShowDefinition()
Expand Down

0 comments on commit 103f87b

Please sign in to comment.