From dddbeb27dfc9811d77209e487289af5c62472859 Mon Sep 17 00:00:00 2001 From: codereader Date: Tue, 17 Nov 2020 09:30:28 +0100 Subject: [PATCH] #5108: Add second option to browse for a specific PK4 and list its contents (not implemented yet) --- radiant/ui/mapselector/MapSelector.cpp | 48 ++++++++++++++++++++++++++ radiant/ui/mapselector/MapSelector.h | 7 ++++ 2 files changed, 55 insertions(+) diff --git a/radiant/ui/mapselector/MapSelector.cpp b/radiant/ui/mapselector/MapSelector.cpp index 9dc7f41716..f45426362b 100644 --- a/radiant/ui/mapselector/MapSelector.cpp +++ b/radiant/ui/mapselector/MapSelector.cpp @@ -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); @@ -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 } diff --git a/radiant/ui/mapselector/MapSelector.h b/radiant/ui/mapselector/MapSelector.h index 091d780726..d9bde1d9bf 100644 --- a/radiant/ui/mapselector/MapSelector.h +++ b/radiant/ui/mapselector/MapSelector.h @@ -5,6 +5,7 @@ #include "wxutil/dialog/DialogBase.h" #include "wxutil/fsview/FileSystemView.h" #include "wxutil/WindowPosition.h" +#include "wxutil/PathEntry.h" class wxStdDialogButtonSizer; @@ -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; @@ -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(); @@ -48,6 +54,7 @@ class MapSelector : void onRescanPath(wxCommandEvent& ev); void onSelectionChanged(wxutil::FileSystemView::SelectionChangedEvent& ev); void updateButtonSensitivity(); + void onPathSelectionChanged(); public: int ShowModal() override;