Skip to content

Commit

Permalink
#5176: Let DR remember the shader in ShaderClipboard after closing, i…
Browse files Browse the repository at this point in the history
…t's saved in each map's root node properties
  • Loading branch information
codereader committed Apr 20, 2020
1 parent 19142ca commit b2abd53
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions radiant/selection/shaderclipboard/ShaderClipboard.cpp
@@ -1,6 +1,7 @@
#include "ShaderClipboard.h"

#include "i18n.h"
#include "imap.h"
#include "iselectiontest.h"
#include "iscenegraph.h"
#include "iuimanager.h"
Expand All @@ -15,6 +16,11 @@
namespace selection
{

namespace
{
const char* const LAST_USED_MATERIAL_KEY = "LastShaderClipboardMaterial";
}

ShaderClipboard::ShaderClipboard() :
_updatesDisabled(false)
{
Expand Down Expand Up @@ -165,11 +171,36 @@ sigc::signal<void> ShaderClipboard::signal_sourceChanged() const

void ShaderClipboard::onMapEvent(IMap::MapEvent ev)
{
if (ev == IMap::MapUnloading || ev == IMap::MapLoaded)
switch (ev)
{
case IMap::MapUnloading:
// Clear the shaderclipboard, the references are most probably invalid now
clear();
}
break;

case IMap::MapSaving:
// Write the current value to the map properties on save
if (!_source.empty() && GlobalMapModule().getRoot())
{
GlobalMapModule().getRoot()->setProperty(LAST_USED_MATERIAL_KEY, _source.getShader());
}
break;

case IMap::MapLoaded:
// Try to load the last used material name from the properties
if (GlobalMapModule().getRoot())
{
auto shader = GlobalMapModule().getRoot()->getProperty(LAST_USED_MATERIAL_KEY);

if (!shader.empty())
{
setSource(shader);
break;
}
}
clear();
break;
};
}

} // namespace selection
Expand Down

0 comments on commit b2abd53

Please sign in to comment.