Skip to content

Commit

Permalink
#5108: Show the containing PK4 archive of non-physical files.
Browse files Browse the repository at this point in the history
Handle double-clicking PK4s that are located in external directories.
  • Loading branch information
codereader committed Nov 20, 2020
1 parent c2d6487 commit 5715411
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
3 changes: 2 additions & 1 deletion libs/wxutil/fsview/FileSystemView.cpp
Expand Up @@ -49,7 +49,8 @@ FileSystemView::FileSystemView(wxWindow* parent, const TreeModel::Ptr& model, lo
// 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);

AppendTextColumn(_("Location"), Columns().archiveDisplay.getColumnIndex(),
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_RIGHT, wxDATAVIEW_COL_SORTABLE);
AppendTextColumn(_("Size"), Columns().size.getColumnIndex(),
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_RIGHT, wxDATAVIEW_COL_SORTABLE);

Expand Down
12 changes: 11 additions & 1 deletion libs/wxutil/fsview/Populator.cpp
@@ -1,5 +1,6 @@
#include "Populator.h"

#include "i18n.h"
#include "iuimanager.h"
#include "ifiletypes.h"
#include "iarchive.h"
Expand Down Expand Up @@ -81,8 +82,17 @@ void Populator::visitFile(const vfs::FileInfo& fileInfo)
if (!isFolder)
{
// Get the file size if possible
bool isPhysical = fileInfo.getIsPhysicalFile();
auto archivePath = fileInfo.getArchivePath();

row[_columns.size] = os::getFormattedFileSize(fileInfo.getSize());
row[_columns.isPhysical] = fileInfo.getIsPhysicalFile();
row[_columns.isPhysical] = isPhysical;
row[_columns.archivePath] = archivePath;

if (!isPhysical)
{
row[_columns.archiveDisplay] = fmt::format(_("[in {0}]"), os::getFilename(archivePath));
}
}
});
}
Expand Down
6 changes: 5 additions & 1 deletion libs/wxutil/fsview/Populator.h
Expand Up @@ -19,14 +19,18 @@ struct TreeColumns :
vfspath(add(TreeModel::Column::String)),
isFolder(add(TreeModel::Column::Boolean)),
size(add(TreeModel::Column::String)),
isPhysical(add(TreeModel::Column::Boolean))
isPhysical(add(TreeModel::Column::Boolean)),
archivePath(add(TreeModel::Column::String)),
archiveDisplay(add(TreeModel::Column::String))
{}

TreeModel::Column filename; // e.g. "chair1.pfb"
TreeModel::Column vfspath; // e.g. "prefabs/chair1.pfb"
TreeModel::Column isFolder; // whether this is a folder
TreeModel::Column size; // file size string
TreeModel::Column isPhysical; // file size string
TreeModel::Column archivePath; // path to containing archive
TreeModel::Column archiveDisplay; // string to display the parent container
};

class Populator :
Expand Down
14 changes: 10 additions & 4 deletions radiant/ui/mapselector/MapSelector.cpp
Expand Up @@ -207,12 +207,18 @@ void MapSelector::onItemActivated(wxDataViewEvent& ev)
// Check if this is a physical file
auto rootPath = GlobalFileSystem().findFile(selectedPath);

if (!rootPath.empty() && GlobalFileSystem().getArchiveExtensions().count(extension) > 0)
if (GlobalFileSystem().getArchiveExtensions().count(extension) == 0)
{
_useCustomPath->SetValue(true);
_customPath->setValue(os::standardPathWithSlash(rootPath) + selectedPath);
onPathSelectionChanged();
return; // not an archive
}

auto pathToPak = !rootPath.empty() ?
os::standardPathWithSlash(rootPath) + selectedPath :
selectedPath;

_useCustomPath->SetValue(true);
_customPath->setValue(pathToPak);
onPathSelectionChanged();
}

void MapSelector::onFileViewTreePopulated()
Expand Down

0 comments on commit 5715411

Please sign in to comment.