Skip to content

Commit

Permalink
#5108: Remove now unused PrefabPopulator. Add some default file icon …
Browse files Browse the repository at this point in the history
…handling code.
  • Loading branch information
codereader committed Nov 19, 2020
1 parent dbcb3ff commit f47cb2c
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 224 deletions.
Binary file added install/bitmaps/file.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion libs/wxutil/fsview/FileSystemView.cpp
Expand Up @@ -7,6 +7,11 @@
namespace wxutil
{

namespace
{
const char* const DEFAULT_FILE_ICON = "file.png";
}

wxDEFINE_EVENT(EV_FSVIEW_SELECTION_CHANGED, FileSystemView::SelectionChangedEvent);

FileSystemView::SelectionChangedEvent::SelectionChangedEvent(int id) :
Expand Down Expand Up @@ -36,7 +41,8 @@ bool FileSystemView::SelectionChangedEvent::SelectionIsFolder()

FileSystemView::FileSystemView(wxWindow* parent, const TreeModel::Ptr& model, long style) :
TreeView(parent, model, style),
_treeStore(model)
_treeStore(model),
_fileIcon(DEFAULT_FILE_ICON)
{
// Single visible column, containing the directory/shader name and the icon
AppendIconTextColumn(_("File"), Columns().filename.getColumnIndex(),
Expand Down Expand Up @@ -72,9 +78,15 @@ void FileSystemView::SetBasePath(const std::string& basePath)
_basePath = basePath;
}

void FileSystemView::SetDefaultFileIcon(const std::string& fileIcon)
{
_fileIcon = fileIcon;
}

void FileSystemView::Populate(const std::string& preselectPath)
{
_populated = true;
_preselectPath = preselectPath;

if (_populator && _populator->GetBasePath() == GetBasePath())
{
Expand All @@ -100,6 +112,7 @@ void FileSystemView::Populate(const std::string& preselectPath)
row.SendItemAdded();

_populator.reset(new fsview::Populator(Columns(), this, GetBasePath()));
_populator->SetDefaultFileIcon(_fileIcon);

// Start the thread, will send an event when finished
_populator->Populate();
Expand Down
4 changes: 4 additions & 0 deletions libs/wxutil/fsview/FileSystemView.h
Expand Up @@ -15,6 +15,7 @@ class FileSystemView :
TreeModel::Ptr _treeStore;

std::string _basePath;
std::string _fileIcon;

// TRUE if the treeview has been populated
bool _populated;
Expand Down Expand Up @@ -52,6 +53,9 @@ class FileSystemView :
// Sets the base path of this view. This can be either an absolute filesystem path or a VFS path
void SetBasePath(const std::string& basePath);

// Set the default icon used for files (e.g. "cmenu_add_prefab.png", relative to the bitmaps/ folder)
void SetDefaultFileIcon(const std::string& fileIcon);

// (Re-)populates the tree view, looking for files in the defined paths
// If the preselectPath argument is not empty, the item will be selected after population
void Populate(const std::string& preselectPath = std::string());
Expand Down
7 changes: 6 additions & 1 deletion libs/wxutil/fsview/Populator.cpp
Expand Up @@ -15,7 +15,7 @@ namespace fsview
namespace
{
const char* const FOLDER_ICON = "folder.png";
const char* const FILE_ICON = "cmenu_add_prefab.png";
const char* const FILE_ICON = "file.png";
}

Populator::Populator(const TreeColumns& columns,
Expand All @@ -42,6 +42,11 @@ Populator::~Populator()
}
}

void Populator::SetDefaultFileIcon(const std::string& fileIcon)
{
_fileIcon.CopyFromBitmap(wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + fileIcon));
}

void Populator::visitFile(const vfs::FileInfo& fileInfo)
{
if (TestDestroy())
Expand Down
2 changes: 2 additions & 0 deletions libs/wxutil/fsview/Populator.h
Expand Up @@ -61,6 +61,8 @@ class Populator :
void visit(wxutil::TreeModel& store, wxutil::TreeModel::Row& row,
const std::string& path, bool isExplicit);

void SetDefaultFileIcon(const std::string& fileIcon);

protected:
// Thread entry point
ExitCode Entry();
Expand Down
1 change: 0 additions & 1 deletion radiant/Makefile.am
Expand Up @@ -53,7 +53,6 @@ darkradiant_SOURCES = main.cpp \
ui/eclasstree/EClassTreeBuilder.cpp \
ui/entitylist/EntityList.cpp \
ui/entitylist/GraphTreeModel.cpp \
ui/prefabselector/PrefabPopulator.cpp \
ui/prefabselector/PrefabSelector.cpp \
ui/texturebrowser/TextureBrowser.cpp \
ui/texturebrowser/TextureBrowserManager.cpp \
Expand Down
124 changes: 0 additions & 124 deletions radiant/ui/prefabselector/PrefabPopulator.cpp

This file was deleted.

55 changes: 0 additions & 55 deletions radiant/ui/prefabselector/PrefabPopulator.h

This file was deleted.

14 changes: 2 additions & 12 deletions radiant/ui/prefabselector/PrefabSelector.cpp
Expand Up @@ -24,7 +24,6 @@
#include <wx/textctrl.h>
#include <wx/radiobut.h>

#include "PrefabPopulator.h"
#include "entitylib.h"

#include "string/trim.h"
Expand Down Expand Up @@ -56,7 +55,6 @@ PrefabSelector::PrefabSelector() :
DialogBase(_(PREFABSELECTOR_TITLE)),
_treeView(nullptr),
_lastPrefab(""),
_populated(false),
_description(nullptr),
_useModPath(nullptr),
_useCustomPath(nullptr),
Expand Down Expand Up @@ -226,16 +224,8 @@ void PrefabSelector::addCustomPathToRecentList()

int PrefabSelector::ShowModal()
{
if (!_populated)
{
// Populate the tree
populatePrefabs();
}
else if (!_lastPrefab.empty())
{
// Preselect the item, tree is already loaded
_treeView->SelectPath(_lastPrefab);
}
// Populate the tree
populatePrefabs();

// Enter the main loop
int returnCode = DialogBase::ShowModal();
Expand Down
22 changes: 0 additions & 22 deletions radiant/ui/prefabselector/PrefabSelector.h
Expand Up @@ -32,21 +32,6 @@ class PrefabSelector :
public wxutil::DialogBase
{
public:
// Treemodel definition
struct TreeColumns :
public wxutil::TreeModel::ColumnRecord
{
TreeColumns() :
filename(add(wxutil::TreeModel::Column::IconText)),
vfspath(add(wxutil::TreeModel::Column::String)),
isFolder(add(wxutil::TreeModel::Column::Boolean))
{}

wxutil::TreeModel::Column filename; // e.g. "chair1.pfb"
wxutil::TreeModel::Column vfspath; // e.g. "prefabs/chair1.pfb"
wxutil::TreeModel::Column isFolder; // whether this is a folder
};

struct Result
{
std::string prefabPath; // VFS path of the prefab
Expand All @@ -56,8 +41,6 @@ class PrefabSelector :
private:
wxPanel* _dialogPanel;

TreeColumns _columns;

// Model preview widget
std::unique_ptr<ui::MapPreview> _preview;

Expand All @@ -71,10 +54,6 @@ class PrefabSelector :
// Last selected prefab,
std::string _lastPrefab;

// TRUE if the treeview has been populated
bool _populated;
std::unique_ptr<PrefabPopulator> _populator;

IMapResourcePtr _mapResource;

wxTextCtrl* _description;
Expand Down Expand Up @@ -117,7 +96,6 @@ class PrefabSelector :
std::string getSelectedPath();
bool getInsertAsGroup();

void handleSelectionChange();
void updateUsageInfo();
void addCustomPathToRecentList();

Expand Down
2 changes: 0 additions & 2 deletions tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -329,7 +329,6 @@
<ClCompile Include="..\..\radiant\ui\patch\PatchCreateDialog.cpp" />
<ClCompile Include="..\..\radiant\ui\patch\PatchInspector.cpp" />
<ClCompile Include="..\..\radiant\ui\patch\PatchThickenDialog.cpp" />
<ClCompile Include="..\..\radiant\ui\prefabselector\PrefabPopulator.cpp" />
<ClCompile Include="..\..\radiant\ui\prefabselector\PrefabSelector.cpp" />
<ClCompile Include="..\..\radiant\ui\prefdialog\GameSetupDialog.cpp" />
<ClCompile Include="..\..\radiant\ui\prefdialog\GameSetupPage.cpp" />
Expand Down Expand Up @@ -527,7 +526,6 @@
<ClInclude Include="..\..\radiant\ui\patch\PatchCreateDialog.h" />
<ClInclude Include="..\..\radiant\ui\patch\PatchInspector.h" />
<ClInclude Include="..\..\radiant\ui\patch\PatchThickenDialog.h" />
<ClInclude Include="..\..\radiant\ui\prefabselector\PrefabPopulator.h" />
<ClInclude Include="..\..\radiant\ui\prefabselector\PrefabSelector.h" />
<ClInclude Include="..\..\radiant\ui\prefdialog\GameSetupDialog.h" />
<ClInclude Include="..\..\radiant\ui\prefdialog\GameSetupPage.h" />
Expand Down

0 comments on commit f47cb2c

Please sign in to comment.