Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5108: Add dialog and menu option to pick a file from the current pro…
…ject (incl. PK4s)
- Loading branch information
1 parent
85f8cc0
commit df6d956
Showing
7 changed files
with
204 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include "MapSelector.h" | ||
|
||
#include "i18n.h" | ||
|
||
#include <wx/sizer.h> | ||
#include <wx/button.h> | ||
|
||
namespace ui | ||
{ | ||
|
||
// CONSTANTS | ||
namespace | ||
{ | ||
const char* const MAPSELECTOR_TITLE = N_("Choose Map File"); | ||
} | ||
|
||
MapSelector::MapSelector() : | ||
DialogBase(_(MAPSELECTOR_TITLE)), | ||
_treeView(nullptr), | ||
_handlingSelectionChange(false) | ||
{ | ||
SetSizer(new wxBoxSizer(wxVERTICAL)); | ||
|
||
wxBoxSizer* vbox = new wxBoxSizer(wxVERTICAL); | ||
GetSizer()->Add(vbox, 1, wxEXPAND | wxALL, 12); | ||
|
||
setupTreeView(this); | ||
vbox->Add(_treeView, 1, wxEXPAND); | ||
|
||
wxStdDialogButtonSizer* buttonSizer = CreateStdDialogButtonSizer(wxOK | wxCANCEL); | ||
wxButton* reloadButton = new wxButton(this, wxID_ANY, _("Rescan")); | ||
reloadButton->Bind(wxEVT_BUTTON, &MapSelector::onRescanPath, this); | ||
|
||
buttonSizer->Prepend(reloadButton, 0, wxRIGHT, 32); | ||
|
||
vbox->Add(buttonSizer, 0, wxALIGN_RIGHT | wxTOP, 12); | ||
|
||
// Set the default size of the window | ||
_position.connect(this); | ||
_position.readPosition(); | ||
|
||
FitToScreen(0.5f, 0.6f); | ||
} | ||
|
||
int MapSelector::ShowModal() | ||
{ | ||
// Populate the tree | ||
populateTree(); | ||
|
||
// Enter the main loop | ||
return DialogBase::ShowModal(); | ||
} | ||
|
||
std::string MapSelector::ChooseMapFile() | ||
{ | ||
auto* dialog = new MapSelector(); | ||
std::string returnValue = ""; | ||
|
||
if (dialog->ShowModal() == wxID_OK) | ||
{ | ||
returnValue = dialog->getSelectedPath(); | ||
} | ||
|
||
// Use the instance to select a model. | ||
return returnValue; | ||
} | ||
|
||
void MapSelector::OpenMapFromProject(const cmd::ArgumentList& args) | ||
{ | ||
auto mapPath = ChooseMapFile(); | ||
|
||
if (!mapPath.empty()) | ||
{ | ||
GlobalCommandSystem().executeCommand("OpenMap", mapPath); | ||
} | ||
} | ||
|
||
// Helper function to create the TreeView | ||
void MapSelector::setupTreeView(wxWindow* parent) | ||
{ | ||
_treeView = wxutil::FileSystemView::Create(parent, wxBORDER_STATIC | wxDV_NO_HEADER); | ||
|
||
// Get the extensions from all possible patterns (e.g. *.map or *.mapx) | ||
FileTypePatterns patterns = GlobalFiletypes().getPatternsForType(filetype::TYPE_MAP); | ||
|
||
std::set<std::string> fileExtensions; | ||
|
||
for (const auto& pattern : patterns) | ||
{ | ||
fileExtensions.insert(pattern.extension); | ||
} | ||
|
||
_treeView->SetFileExtensions(fileExtensions); | ||
} | ||
|
||
std::string MapSelector::getBaseFolder() | ||
{ | ||
return ""; // use an empty path which resembles the VFS root | ||
} | ||
|
||
void MapSelector::populateTree() | ||
{ | ||
_treeView->SetBasePath(getBaseFolder()); | ||
_treeView->Populate(); | ||
} | ||
|
||
void MapSelector::onRescanPath(wxCommandEvent& ev) | ||
{ | ||
populateTree(); | ||
} | ||
|
||
std::string MapSelector::getSelectedPath() | ||
{ | ||
return _treeView->GetSelectedPath(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#pragma once | ||
|
||
#include "icommandsystem.h" | ||
|
||
#include "wxutil/dialog/DialogBase.h" | ||
#include "wxutil/fsview/FileSystemView.h" | ||
#include "wxutil/WindowPosition.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
/// Dialog for browsing and selecting a map from (V)FS | ||
class MapSelector : | ||
public wxutil::DialogBase | ||
{ | ||
private: | ||
wxPanel* _dialogPanel; | ||
|
||
// Main tree view with the folder hierarchy | ||
wxutil::FileSystemView* _treeView; | ||
|
||
// The window position tracker | ||
wxutil::WindowPosition _position; | ||
|
||
bool _handlingSelectionChange; | ||
|
||
private: | ||
// Private constructor, creates widgets | ||
MapSelector(); | ||
|
||
// Helper functions to configure GUI components | ||
void setupTreeView(wxWindow* parent); | ||
|
||
// Populate the tree view with files | ||
void populateTree(); | ||
|
||
// 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(); | ||
|
||
// Return the selected map path | ||
std::string getSelectedPath(); | ||
|
||
void onRescanPath(wxCommandEvent& ev); | ||
|
||
public: | ||
int ShowModal() override; | ||
|
||
/** | ||
* Display the Selector return the path of the file selected by the user. | ||
*/ | ||
static std::string ChooseMapFile(); | ||
|
||
static void OpenMapFromProject(const cmd::ArgumentList& args); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters