Skip to content

Commit

Permalink
#6021: Add syntax highlighting for modelDefs. Move DeclarationSourceV…
Browse files Browse the repository at this point in the history
…iew implementation to .cpp file
  • Loading branch information
codereader committed Jul 30, 2022
1 parent 8352d67 commit 5ecaebe
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 87 deletions.
1 change: 1 addition & 0 deletions libs/wxutil/CMakeLists.txt
Expand Up @@ -31,6 +31,7 @@ add_library(wxutil
preview/ParticlePreview.cpp
preview/RenderPreview.cpp
SerialisableWidgets.cpp
sourceview/DeclarationSourceView.cpp
sourceview/DefinitionView.cpp
sourceview/SourceView.cpp
Splitter.cpp
Expand Down
104 changes: 104 additions & 0 deletions libs/wxutil/sourceview/DeclarationSourceView.cpp
@@ -0,0 +1,104 @@
#include "DeclarationSourceView.h"

#include "i18n.h"
#include "fmt/format.h"

#include "SourceView.h"

// Some X11 headers are defining this
#ifdef None
#undef None
#endif

namespace wxutil
{

DeclarationSourceView::DeclarationSourceView(wxWindow* parent) :
DefinitionView("", parent),
_activeSourceViewType(decl::Type::Undetermined)
{
updateSourceView();
}

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

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

_decl = decl;

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

updateSourceView();
update();
updateTitle();
}

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

bool DeclarationSourceView::isEmpty() const
{
return !_decl;
}

std::string DeclarationSourceView::getDeclName()
{
return _decl ? _decl->getDeclName() : "";
}

std::string DeclarationSourceView::getDeclFileName()
{
return _decl ? _decl->getDeclFilePath() : "";
}

std::string DeclarationSourceView::getDefinition()
{
return _decl ? _decl->getBlockSyntax().contents : "";
}

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

void DeclarationSourceView::updateSourceView()
{
auto newType = _decl ? _decl->getDeclType() : decl::Type::None;

if (newType == _activeSourceViewType) return;

_activeSourceViewType = newType;

// Pick the correct source view control based on the active type
switch (newType)
{
case decl::Type::SoundShader:
setSourceView(new D3SoundShaderSourceViewCtrl(getMainPanel()));
break;
case decl::Type::Material:
setSourceView(new D3MaterialSourceViewCtrl(getMainPanel()));
break;
case decl::Type::Particle:
setSourceView(new D3ParticleSourceViewCtrl(getMainPanel()));
break;
case decl::Type::ModelDef:
setSourceView(new D3ModelDefSourceViewCtrl(getMainPanel()));
break;
default:
setSourceView(new D3DeclarationViewCtrl(getMainPanel()));
}
}

}
97 changes: 10 additions & 87 deletions libs/wxutil/sourceview/DeclarationSourceView.h
Expand Up @@ -2,15 +2,7 @@

#include <sigc++/connection.h>
#include "ideclmanager.h"
#include "i18n.h"
#include "fmt/format.h"
#include "DefinitionView.h"
#include "SourceView.h"

// Some X11 headers are defining this
#ifdef None
#undef None
#endif

namespace wxutil
{
Expand All @@ -28,92 +20,23 @@ class DeclarationSourceView :
sigc::connection _declChangedConn;

public:
DeclarationSourceView(wxWindow* parent) :
DefinitionView("", parent),
_activeSourceViewType(decl::Type::Undetermined)
{
updateSourceView();
}

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

void setDeclaration(const decl::IDeclaration::Ptr& decl)
{
_declChangedConn.disconnect();
DeclarationSourceView(wxWindow* parent);

_decl = decl;
~DeclarationSourceView() override;

if (_decl)
{
_declChangedConn = _decl->signal_DeclarationChanged().connect(
sigc::mem_fun(*this, &DeclarationSourceView::update)
);
}
void setDeclaration(const decl::IDeclaration::Ptr& decl);

updateSourceView();
update();
updateTitle();
}

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

protected:
bool isEmpty() const override
{
return !_decl;
}

std::string getDeclName() override
{
return _decl ? _decl->getDeclName() : "";
}

std::string getDeclFileName() override
{
return _decl ? _decl->getDeclFilePath() : "";
}

std::string getDefinition() override
{
return _decl ? _decl->getBlockSyntax().contents : "";
}
bool isEmpty() const override;
std::string getDeclName() override;
std::string getDeclFileName() override;
std::string getDefinition() override;

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

void updateSourceView()
{
auto newType = _decl ? _decl->getDeclType() : decl::Type::None;

if (newType == _activeSourceViewType) return;

_activeSourceViewType = newType;

// Pick the correct source view control based on the active type
switch (newType)
{
case decl::Type::SoundShader:
setSourceView(new D3SoundShaderSourceViewCtrl(getMainPanel()));
break;
case decl::Type::Material:
setSourceView(new D3MaterialSourceViewCtrl(getMainPanel()));
break;
case decl::Type::Particle:
setSourceView(new D3ParticleSourceViewCtrl(getMainPanel()));
break;
default:
setSourceView(new D3DeclarationViewCtrl(getMainPanel()));
}
}
void updateTitle();
void updateSourceView();
};

}
10 changes: 10 additions & 0 deletions libs/wxutil/sourceview/SourceView.cpp
Expand Up @@ -178,4 +178,14 @@ D3ParticleSourceViewCtrl::D3ParticleSourceViewCtrl(wxWindow* parent) :
"flies orbit drip to");
};

// D3 ModelDefs

D3ModelDefSourceViewCtrl::D3ModelDefSourceViewCtrl(wxWindow* parent) :
D3DeclarationViewCtrl(parent)
{
SetKeyWords(0, "mesh anim channel frame inherit ");

SetKeyWords(1, "torso legs eyelids sound sound_voice no_random_headturning footstep ");
};

} // namespace
11 changes: 11 additions & 0 deletions libs/wxutil/sourceview/SourceView.h
Expand Up @@ -158,4 +158,15 @@ class D3ParticleSourceViewCtrl :
D3ParticleSourceViewCtrl(wxWindow* parent);
};

/**
* A special class providing highlighting for the Doom 3
* modelDef syntax.
*/
class D3ModelDefSourceViewCtrl :
public D3DeclarationViewCtrl
{
public:
D3ModelDefSourceViewCtrl(wxWindow* parent);
};

} // namespace
1 change: 1 addition & 0 deletions tools/msvc/wxutillib.vcxproj
Expand Up @@ -233,6 +233,7 @@
<ClCompile Include="..\..\libs\wxutil\preview\ParticlePreview.cpp" />
<ClCompile Include="..\..\libs\wxutil\preview\RenderPreview.cpp" />
<ClCompile Include="..\..\libs\wxutil\SerialisableWidgets.cpp" />
<ClCompile Include="..\..\libs\wxutil\sourceview\DeclarationSourceView.cpp" />
<ClCompile Include="..\..\libs\wxutil\sourceview\DefinitionView.cpp" />
<ClCompile Include="..\..\libs\wxutil\sourceview\SourceView.cpp" />
<ClCompile Include="..\..\libs\wxutil\Splitter.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/wxutillib.vcxproj.filters
Expand Up @@ -256,5 +256,8 @@
<ClCompile Include="..\..\libs\wxutil\sourceview\SourceView.cpp">
<Filter>sourceview</Filter>
</ClCompile>
<ClCompile Include="..\..\libs\wxutil\sourceview\DeclarationSourceView.cpp">
<Filter>sourceview</Filter>
</ClCompile>
</ItemGroup>
</Project>

0 comments on commit 5ecaebe

Please sign in to comment.