Skip to content

Commit

Permalink
#5108: Make listed file extensions configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Nov 19, 2020
1 parent f47cb2c commit ab5307a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
9 changes: 8 additions & 1 deletion libs/wxutil/fsview/FileSystemView.cpp
Expand Up @@ -44,6 +44,8 @@ FileSystemView::FileSystemView(wxWindow* parent, const TreeModel::Ptr& model, lo
_treeStore(model),
_fileIcon(DEFAULT_FILE_ICON)
{
_fileExtensions.insert("*"); // list all files by default

// Single visible column, containing the directory/shader name and the icon
AppendIconTextColumn(_("File"), Columns().filename.getColumnIndex(),
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE);
Expand Down Expand Up @@ -78,6 +80,11 @@ void FileSystemView::SetBasePath(const std::string& basePath)
_basePath = basePath;
}

void FileSystemView::SetFileExtensions(const std::set<std::string>& fileExtensions)
{
_fileExtensions = fileExtensions;
}

void FileSystemView::SetDefaultFileIcon(const std::string& fileIcon)
{
_fileIcon = fileIcon;
Expand Down Expand Up @@ -111,7 +118,7 @@ void FileSystemView::Populate(const std::string& preselectPath)
row[Columns().vfspath] = "__loadingnode__"; // to prevent that item from being found
row.SendItemAdded();

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

// Start the thread, will send an event when finished
Expand Down
6 changes: 6 additions & 0 deletions libs/wxutil/fsview/FileSystemView.h
Expand Up @@ -22,6 +22,8 @@ class FileSystemView :
std::unique_ptr<fsview::Populator> _populator;
std::string _preselectPath;

std::set<std::string> _fileExtensions;

public:
class SelectionChangedEvent :
public wxEvent
Expand Down Expand Up @@ -53,6 +55,10 @@ 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);

// Define the set of file extensions to list in the tree (e.g. "map" or "pfbx")
// Use a single "*" extension to list all files.
void SetFileExtensions(const std::set<std::string>& fileExtensions);

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

Expand Down
14 changes: 6 additions & 8 deletions libs/wxutil/fsview/Populator.cpp
@@ -1,7 +1,6 @@
#include "Populator.h"

#include "iuimanager.h"
#include "ifiletypes.h"
#include "os/path.h"

#include <wx/artprov.h>
Expand All @@ -19,13 +18,15 @@ namespace
}

Populator::Populator(const TreeColumns& columns,
wxEvtHandler* finishedHandler, const std::string& basePath) :
wxEvtHandler* finishedHandler, const std::string& basePath,
const std::set<std::string>& fileExtensions) :
wxThread(wxTHREAD_JOINABLE),
_columns(columns),
_treeStore(new wxutil::TreeModel(_columns)),
_finishedHandler(finishedHandler),
_treePopulator(_treeStore),
_basePath(os::standardPathWithSlash(basePath))
_basePath(os::standardPathWithSlash(basePath)),
_fileExtensions(fileExtensions)
{
_fileIcon.CopyFromBitmap(
wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + FILE_ICON));
Expand Down Expand Up @@ -76,12 +77,9 @@ void Populator::SearchForFilesMatchingExtension(const std::string& extension)

wxThread::ExitCode Populator::Entry()
{
// Get the first extension from the list of possible patterns (e.g. *.pfb or *.map)
FileTypePatterns patterns = GlobalFiletypes().getPatternsForType(filetype::TYPE_PREFAB);

for (const auto& pattern : patterns)
for (const auto& extension : _fileExtensions)
{
SearchForFilesMatchingExtension(pattern.extension);
SearchForFilesMatchingExtension(extension);

if (TestDestroy()) return static_cast<wxThread::ExitCode>(0);
}
Expand Down
5 changes: 4 additions & 1 deletion libs/wxutil/fsview/Populator.h
Expand Up @@ -46,10 +46,13 @@ class Populator :

std::string _basePath;

std::set<std::string> _fileExtensions;

public:
Populator(const TreeColumns& columns,
wxEvtHandler* finishedHandler,
const std::string& basePath);
const std::string& basePath,
const std::set<std::string>& fileExtensions);

~Populator(); // waits for thread to finish

Expand Down
13 changes: 13 additions & 0 deletions radiant/ui/prefabselector/PrefabSelector.cpp
@@ -1,6 +1,7 @@
#include "PrefabSelector.h"

#include "ifilesystem.h"
#include "ifiletypes.h"
#include "itextstream.h"
#include "i18n.h"
#include "iradiant.h"
Expand Down Expand Up @@ -316,6 +317,18 @@ void PrefabSelector::setupTreeView(wxWindow* parent)
{
_treeView = wxutil::FileSystemView::Create(parent, wxBORDER_STATIC | wxDV_NO_HEADER);
_treeView->Bind(wxutil::EV_FSVIEW_SELECTION_CHANGED, &PrefabSelector::onSelectionChanged, this);

// Get the extensions from all possible patterns (e.g. *.pfb or *.pfbx)
FileTypePatterns patterns = GlobalFiletypes().getPatternsForType(filetype::TYPE_PREFAB);

std::set<std::string> fileExtensions;

for (const auto & pattern : patterns)
{
fileExtensions.insert(pattern.extension);
}

_treeView->SetFileExtensions(fileExtensions);
}

std::string PrefabSelector::getPrefabFolder()
Expand Down

0 comments on commit ab5307a

Please sign in to comment.