Skip to content

Commit

Permalink
#5537: Add a generic Get/SetSelectedDeclName method to DeclarationSel…
Browse files Browse the repository at this point in the history
…ector, replacing the ShaderSelector methods
  • Loading branch information
codereader committed Sep 16, 2022
1 parent c29693b commit 038a1d9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 40 deletions.
10 changes: 10 additions & 0 deletions radiant/ui/common/DeclarationSelector.cpp
Expand Up @@ -37,6 +37,16 @@ wxutil::DeclarationTreeView* DeclarationSelector::GetTreeView()
return _treeView;
}

std::string DeclarationSelector::GetSelectedDeclName()
{
return _treeView->GetSelectedDeclName();
}

void DeclarationSelector::SetSelectedDeclName(const std::string& declName)
{
_treeView->SetSelectedDeclName(declName);
}

void DeclarationSelector::PopulateTreeView(const wxutil::IResourceTreePopulator::Ptr& populator)
{
_treeView->Populate(populator);
Expand Down
16 changes: 16 additions & 0 deletions radiant/ui/common/DeclarationSelector.h
Expand Up @@ -23,6 +23,22 @@ class DeclarationSelector :
public:
DeclarationSelector(wxWindow* parent, decl::Type declType, const wxutil::DeclarationTreeView::Columns& columns);

/**
* Return the declaration selected by the user, or an empty string if there
* was no selection.
*/
virtual std::string GetSelectedDeclName();

/**
* Set the given declaration name as the current selection, highlighting it
* in the tree view.
*
* @param declName
* The fullname of the declaration to select, or the empty string if there
* should be no selection.
*/
virtual void SetSelectedDeclName(const std::string& declName);

protected:
wxutil::DeclarationTreeView* GetTreeView();
void PopulateTreeView(const wxutil::IResourceTreePopulator::Ptr& populator);
Expand Down
14 changes: 7 additions & 7 deletions radiant/ui/common/ShaderChooser.cpp
Expand Up @@ -38,7 +38,7 @@ ShaderChooser::ShaderChooser(wxWindow* parent, ShaderSelector::TextureFilter fil
_initialShader = _targetEntry->GetValue();

// Set the cursor of the tree view to the currently selected shader
_selector->setSelection(_initialShader);
_selector->SetSelectedDeclName(_initialShader);
}

_selector->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, &ShaderChooser::_onItemActivated, this);
Expand All @@ -57,12 +57,12 @@ ShaderChooser::ShaderChooser(wxWindow* parent, ShaderSelector::TextureFilter fil

std::string ShaderChooser::getSelectedTexture()
{
return _selector->getSelection();
return _selector->GetSelectedDeclName();
}

void ShaderChooser::setSelectedTexture(const std::string& textureName)
{
_selector->setSelection(textureName);
_selector->SetSelectedDeclName(textureName);
}

void ShaderChooser::shutdown()
Expand All @@ -73,11 +73,11 @@ void ShaderChooser::shutdown()

void ShaderChooser::_onItemActivated(wxDataViewEvent& ev)
{
if (!_selector->getSelection().empty())
if (!_selector->GetSelectedDeclName().empty())
{
if (_targetEntry)
{
_targetEntry->SetValue(_selector->getSelection());
_targetEntry->SetValue(_selector->GetSelectedDeclName());
}

shutdown();
Expand Down Expand Up @@ -106,7 +106,7 @@ void ShaderChooser::shaderSelectionChanged()
{
if (_targetEntry)
{
_targetEntry->SetValue(_selector->getSelection());
_targetEntry->SetValue(_selector->GetSelectedDeclName());
}

// Propagate the call up to the client (e.g. SurfaceInspector)
Expand Down Expand Up @@ -138,7 +138,7 @@ void ShaderChooser::callbackOK(wxCommandEvent& ev)
{
if (_targetEntry)
{
_targetEntry->SetValue(_selector->getSelection());
_targetEntry->SetValue(_selector->GetSelectedDeclName());
}

shutdown();
Expand Down
16 changes: 2 additions & 14 deletions radiant/ui/common/ShaderSelector.cpp
Expand Up @@ -3,14 +3,12 @@
#include <vector>
#include <string>

#include "i18n.h"
#include "ishaders.h"

#include <wx/sizer.h>

#include "texturelib.h"
#include "gamelib.h"
#include "string/split.h"
#include "string/predicate.h"

#include "wxutil/dataview/VFSTreePopulator.h"
Expand Down Expand Up @@ -96,16 +94,6 @@ const wxutil::DeclarationTreeView::Columns& ShaderSelector::Columns()
return _shaderColumns;
}

std::string ShaderSelector::getSelection()
{
return GetTreeView()->GetSelectedDeclName();
}

void ShaderSelector::setSelection(const std::string& sel)
{
GetTreeView()->SetSelectedDeclName(sel);
}

void ShaderSelector::createPreview()
{
_previewCombo = new TexturePreviewCombo(this);
Expand All @@ -114,12 +102,12 @@ void ShaderSelector::createPreview()

MaterialPtr ShaderSelector::getSelectedShader()
{
return GlobalMaterialManager().getMaterial(getSelection());
return GlobalMaterialManager().getMaterial(GetSelectedDeclName());
}

void ShaderSelector::_onSelChange(wxDataViewEvent& ev)
{
_previewCombo->SetTexture(getSelection());
_previewCombo->SetTexture(GetSelectedDeclName());

if (_selectionChanged)
{
Expand Down
17 changes: 1 addition & 16 deletions radiant/ui/common/ShaderSelector.h
Expand Up @@ -51,30 +51,15 @@ class ShaderSelector :
/** Constructor.
*
* @selectionChanged: Functor invoked when the tree view selection changes.
* @prefixes: A comma-separated list of shader prefixes.
* @filter: which texture set to show in the selector
*/
ShaderSelector(wxWindow* parent, const std::function<void()>& selectionChanged, TextureFilter filter);

/** Return the shader selected by the user, or an empty string if there
* was no selection.
*/
std::string getSelection();

/** Set the given shader name as the current selection, highlighting it
* in the tree view.
*
* @param selection
* The fullname of the shader to select, or the empty string if there
* should be no selection.
*/
void setSelection(const std::string& selection);

// Get the selected Material
MaterialPtr getSelectedShader();

private:
// Create GUI elements
void createTreeView();
void createPreview();

void _onSelChange(wxDataViewEvent& ev);
Expand Down
6 changes: 3 additions & 3 deletions radiant/ui/lightinspector/LightInspector.cpp
Expand Up @@ -87,11 +87,11 @@ void LightInspector::shaderSelectionChanged()
if (_updateActive) return;

std::string commandStr("setLightTexture: ");
commandStr += _texSelector->getSelection();
commandStr += _texSelector->GetSelectedDeclName();
UndoableCommand command(commandStr);

// Write the texture key
setKeyValueAllLights("texture", _texSelector->getSelection());
setKeyValueAllLights("texture", _texSelector->GetSelectedDeclName());
}

// Set up the point/projected light options
Expand Down Expand Up @@ -476,7 +476,7 @@ void LightInspector::getValuesFromEntity()
updateColourWidgets();

// Set the texture selection from the "texture" key
_texSelector->setSelection(entity->getKeyValue("texture"));
_texSelector->SetSelectedDeclName(entity->getKeyValue("texture"));

// Determine whether this is a projected light, and set the toggles
// appropriately
Expand Down

0 comments on commit 038a1d9

Please sign in to comment.