Skip to content

Commit

Permalink
#5108: Add second option to browse for a specific PK4 and list its co…
Browse files Browse the repository at this point in the history
…ntents (not implemented yet)
  • Loading branch information
codereader committed Nov 17, 2020
1 parent 3908cce commit 6df3f91
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
48 changes: 48 additions & 0 deletions radiant/ui/mapselector/MapSelector.cpp
Expand Up @@ -28,6 +28,8 @@ MapSelector::MapSelector() :
wxBoxSizer* vbox = new wxBoxSizer(wxVERTICAL);
GetSizer()->Add(vbox, 1, wxEXPAND | wxALL, 12);

setupPathSelector(vbox);

setupTreeView(this);
vbox->Add(_treeView, 1, wxEXPAND);

Expand Down Expand Up @@ -107,8 +109,54 @@ void MapSelector::setupTreeView(wxWindow* parent)
_treeView->SetFileExtensions(fileExtensions);
}

void MapSelector::setupPathSelector(wxSizer* parentSizer)
{
// Path selection box
wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);

_useModPath = new wxRadioButton(this, wxID_ANY, _("Browse mod resources"),
wxDefaultPosition, wxDefaultSize, wxRB_GROUP);

_useCustomPath = new wxRadioButton(this, wxID_ANY, _("Browse custom PAK:"));
_customPath = new wxutil::PathEntry(this, filetype::TYPE_PAK, true);

// Connect to the changed event
_customPath->Bind(wxutil::EV_PATH_ENTRY_CHANGED, [&](wxCommandEvent& ev)
{
_useCustomPath->SetValue(true);
onPathSelectionChanged();
});

hbox->Add(_useModPath, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 6);
hbox->Add(_useCustomPath, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 6);
hbox->Add(_customPath, 1, wxLEFT, 6);

parentSizer->Add(hbox, 0, wxBOTTOM | wxEXPAND, 12);

// Wire up the signals
_useModPath->Bind(wxEVT_RADIOBUTTON, [&](wxCommandEvent& ev)
{
onPathSelectionChanged();
});

_useCustomPath->Bind(wxEVT_RADIOBUTTON, [&](wxCommandEvent& ev)
{
onPathSelectionChanged();
});
}

void MapSelector::onPathSelectionChanged()
{
populateTree();
}

std::string MapSelector::getBaseFolder()
{
if (_useCustomPath->GetValue() && !_customPath->getValue().empty())
{
return _customPath->getValue();
}

return ""; // use an empty path which resembles the VFS root
}

Expand Down
7 changes: 7 additions & 0 deletions radiant/ui/mapselector/MapSelector.h
Expand Up @@ -5,6 +5,7 @@
#include "wxutil/dialog/DialogBase.h"
#include "wxutil/fsview/FileSystemView.h"
#include "wxutil/WindowPosition.h"
#include "wxutil/PathEntry.h"

class wxStdDialogButtonSizer;

Expand All @@ -22,6 +23,10 @@ class MapSelector :
// Main tree view with the folder hierarchy
wxutil::FileSystemView* _treeView;

wxRadioButton* _useModPath;
wxRadioButton* _useCustomPath;
wxutil::PathEntry* _customPath;

// The window position tracker
wxutil::WindowPosition _position;

Expand All @@ -34,6 +39,7 @@ class MapSelector :

// Helper functions to configure GUI components
void setupTreeView(wxWindow* parent);
void setupPathSelector(wxSizer* parentSizer);

// Populate the tree view with files
void populateTree();
Expand All @@ -48,6 +54,7 @@ class MapSelector :
void onRescanPath(wxCommandEvent& ev);
void onSelectionChanged(wxutil::FileSystemView::SelectionChangedEvent& ev);
void updateButtonSensitivity();
void onPathSelectionChanged();

public:
int ShowModal() override;
Expand Down

0 comments on commit 6df3f91

Please sign in to comment.