Skip to content

Commit

Permalink
#5108: Properly calculate the VFS path of tree items when traversing …
Browse files Browse the repository at this point in the history
…external PK4 files.

Don't repopulate the tree if the base path is not changing.
  • Loading branch information
codereader committed Nov 20, 2020
1 parent 1492339 commit 07aa55a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
6 changes: 3 additions & 3 deletions libs/wxutil/fsview/FileSystemView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ void FileSystemView::SelectPath(const std::string& path)
SelectItem(_treeStore->FindString(path, Columns().vfspath));
}

void FileSystemView::ExpandPath(const std::string& path)
void FileSystemView::ExpandPath(const std::string& relativePath)
{
if (path.empty()) return;
if (relativePath.empty()) return;

Expand(_treeStore->FindString(path, Columns().vfspath));
Expand(_treeStore->FindString(relativePath, Columns().vfspath));
}

std::string FileSystemView::GetSelectedPath()
Expand Down
3 changes: 2 additions & 1 deletion libs/wxutil/fsview/FileSystemView.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class FileSystemView :
std::string GetSelectedPath();
bool GetIsFolderSelected();

void ExpandPath(const std::string& path);
// Expands the given path, which is relative to the base path (e.g. "maps/")
void ExpandPath(const std::string& relativePath);

sigc::signal<void>& signal_TreePopulated();

Expand Down
15 changes: 10 additions & 5 deletions libs/wxutil/fsview/Populator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ void Populator::visitFile(const vfs::FileInfo& fileInfo)
{
// The population callback will be called multiple times for deeper files,
// but only one of them will be have isFolder == false, which is our actual file
std::string fullPath = os::standardPathWithSlash(_basePath) + path;
std::string vfsPath = _rootPath + path;

// Get the display path, everything after rightmost slash
row[_columns.filename] = wxVariant(wxDataViewIconText(leafName,
isFolder ? _folderIcon : GetIconForFile(leafName)));
row[_columns.vfspath] = isFolder ? os::standardPathWithSlash(fullPath) : fullPath;
row[_columns.vfspath] = isFolder ? os::standardPathWithSlash(vfsPath) : vfsPath;
row[_columns.isFolder] = isFolder;

if (!isFolder)
Expand All @@ -94,21 +93,27 @@ void Populator::SearchForFilesMatchingExtension(const std::string& extension)
{
if (os::isDirectory(_basePath))
{
_rootPath = os::standardPathWithSlash(_basePath);

// Traverse a folder somewhere in the filesystem
GlobalFileSystem().forEachFileInAbsolutePath(os::standardPathWithSlash(_basePath), extension,
std::bind(&Populator::visitFile, this, std::placeholders::_1), 0);
}
else
{
_rootPath = "";

// Try to open this file as archive
GlobalFileSystem().forEachFileInArchive(_basePath, extension,
std::bind(&Populator::visitFile, this, std::placeholders::_1), 0);
}
}
else
{
// Traverse the VFS
GlobalFileSystem().forEachFile(os::standardPathWithSlash(_basePath), extension,
_rootPath = os::standardPathWithSlash(_basePath);

// Traverse the VFS using that root path
GlobalFileSystem().forEachFile(_rootPath, extension,
std::bind(&Populator::visitFile, this, std::placeholders::_1), 0);
}
}
Expand Down
8 changes: 8 additions & 0 deletions libs/wxutil/fsview/Populator.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ class Populator :
private:
const TreeColumns& _columns;

// The path to inspect, which can be either a VFS-relative path
// (or even an empty string for the VFS root) or an absolute path
// that points to a physical directory or a PAK file.
std::string _basePath;

// Will be preprended to each item's VFS path
// When inspecting physical PK4s, this will be an empty string
// such that the VFS path of each item shows up as relative path
std::string _rootPath;

// The tree store to populate
wxutil::TreeModel::Ptr _treeStore;

Expand Down
12 changes: 9 additions & 3 deletions radiant/ui/mapselector/MapSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,16 @@ void MapSelector::setupPathSelector(wxSizer* parentSizer)

void MapSelector::onPathSelectionChanged()
{
populateTree();
// Re-populate the tree if the base path is different
auto basePath = getBasePath();

if (_treeView->GetBasePath() != basePath)
{
populateTree();
}
}

std::string MapSelector::getBaseFolder()
std::string MapSelector::getBasePath()
{
if (_useCustomPath->GetValue() && !_customPath->getValue().empty())
{
Expand All @@ -171,7 +177,7 @@ std::string MapSelector::getBaseFolder()

void MapSelector::populateTree()
{
_treeView->SetBasePath(getBaseFolder());
_treeView->SetBasePath(getBasePath());
_treeView->Populate();
}

Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/mapselector/MapSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MapSelector :

// Get the path that should be used for map population
// This reflects the settings made by the user on the top of the selector window
std::string getBaseFolder();
std::string getBasePath();

// Return the selected map path
std::string getSelectedPath();
Expand Down

0 comments on commit 07aa55a

Please sign in to comment.