Navigation Menu

Skip to content

Commit

Permalink
#6021: Remove SkinChooser singleton, instantiate a new instance every…
Browse files Browse the repository at this point in the history
… time a skin is requested
  • Loading branch information
codereader committed Jul 24, 2022
1 parent 767f360 commit c7cba89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 51 deletions.
54 changes: 11 additions & 43 deletions radiant/ui/common/SkinChooser.cpp
@@ -1,8 +1,6 @@
#include "SkinChooser.h"

#include "i18n.h"
#include "ui/imainframe.h"
#include "itextstream.h"
#include "modelskin.h"

#include "wxutil/Bitmap.h"
Expand All @@ -19,10 +17,10 @@ namespace ui

namespace
{
const char* FOLDER_ICON = "folder16.png";
const char* SKIN_ICON = "skin16.png";
constexpr const char* FOLDER_ICON = "folder16.png";
constexpr const char* SKIN_ICON = "skin16.png";

const char* const WINDOW_TITLE = N_("Choose Skin");
constexpr const char* const WINDOW_TITLE = N_("Choose Skin");
}

// Constructor
Expand All @@ -39,30 +37,6 @@ SkinChooser::SkinChooser() :
populateWindow();
}

SkinChooser& SkinChooser::Instance()
{
SkinChooserPtr& instancePtr = InstancePtr();

if (!instancePtr)
{
// Not yet instantiated, do it now
instancePtr.reset(new SkinChooser);

// Pre-destruction cleanup
GlobalMainFrame().signal_MainFrameShuttingDown().connect(
sigc::mem_fun(*instancePtr, &SkinChooser::onMainFrameShuttingDown)
);
}

return *instancePtr;
}

SkinChooserPtr& SkinChooser::InstancePtr()
{
static SkinChooserPtr _instancePtr;
return _instancePtr;
}

void SkinChooser::populateWindow()
{
SetSizer(new wxBoxSizer(wxVERTICAL));
Expand Down Expand Up @@ -285,24 +259,18 @@ void SkinChooser::setSelectedSkin(const std::string& skin)
std::string SkinChooser::chooseSkin(const std::string& model,
const std::string& prev)
{
Instance()._model = model;
Instance()._prevSkin = prev;
auto dialog = new SkinChooser();

Instance().ShowModal();
Instance().Hide();

return Instance()._lastSkin;
}
dialog->_model = model;
dialog->_prevSkin = prev;

void SkinChooser::onMainFrameShuttingDown()
{
rMessage() << "SkinChooser shutting down." << std::endl;
dialog->ShowModal();

auto selectedSkin = dialog->_lastSkin;

_preview.reset();
dialog->Destroy();

// Destroy the window
SendDestroyEvent();
InstancePtr().reset();
return selectedSkin;
}

void SkinChooser::handleSelectionChange()
Expand Down
8 changes: 0 additions & 8 deletions radiant/ui/common/SkinChooser.h
Expand Up @@ -4,8 +4,6 @@
#include "imodel.h"
#include "modelskin.h"

#include "iradiant.h"

#include "wxutil/dialog/DialogBase.h"
#include "wxutil/preview/ModelPreview.h"
#include "wxutil/DeclFileInfo.h"
Expand Down Expand Up @@ -83,12 +81,6 @@ class SkinChooser :
// callbacks
void _onSelChanged(wxDataViewEvent& ev);

// Contains the static instance
static SkinChooser& Instance();

// This is where the static shared_ptr of the singleton instance is held.
static SkinChooserPtr& InstancePtr();

// Retrieve the currently selected skin
std::string getSelectedSkin();
void setSelectedSkin(const std::string& skin);
Expand Down

0 comments on commit c7cba89

Please sign in to comment.