Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial dialog for choosing pointfiles
Dialog is shown by File->Pointfile if (and only if) there is more than one pointfile available. The dialog shows the correct list of files but is rather useless at the moment since the selection does not have any influence over the pointfile which is actually loaded.
- Loading branch information
Matthew Mott
committed
May 25, 2021
1 parent
dfc0ae4
commit 01cd735
Showing
5 changed files
with
105 additions
and
13 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,60 @@ | ||
#include "PointFileChooser.h" | ||
|
||
#include "imainframe.h" | ||
#include "imap.h" | ||
#include "icommandsystem.h" | ||
#include "os/fs.h" | ||
#include "command/ExecutionFailure.h" | ||
|
||
#include <wx/frame.h> | ||
#include <wx/sizer.h> | ||
#include <wx/choice.h> | ||
#include <list> | ||
|
||
namespace ui | ||
{ | ||
|
||
PointFileChooser::PointFileChooser(const wxArrayString& files) | ||
: wxDialog(GlobalMainFrame().getWxTopLevelWindow(), wxID_ANY, | ||
"Choose pointfile") | ||
{ | ||
SetSizer(new wxBoxSizer(wxVERTICAL)); | ||
|
||
// Construct and populate the dropdown list | ||
auto list = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, | ||
files); | ||
list->SetSelection(0); | ||
GetSizer()->Add(list, 0, wxEXPAND | wxALL, 12); | ||
|
||
// Add dialog buttons | ||
auto btnSizer = CreateStdDialogButtonSizer(wxOK | wxCANCEL); | ||
GetSizer()->Add(btnSizer, 0, wxALIGN_RIGHT | wxALIGN_BOTTOM, 0); | ||
} | ||
|
||
void PointFileChooser::chooseAndToggle() | ||
{ | ||
// Determine the list of pointfiles | ||
std::list<fs::path> pointfiles; | ||
GlobalMapModule().forEachPointfile([&](const fs::path& p) | ||
{ pointfiles.push_back(p); }); | ||
if (pointfiles.empty()) | ||
throw cmd::ExecutionFailure("No pointfiles found for current map."); | ||
|
||
// If there is a choice to make, show the dialog | ||
if (pointfiles.size() > 1) | ||
{ | ||
// Construct list of wxString filenames | ||
wxArrayString filenames; | ||
for (const fs::path& p: pointfiles) | ||
filenames.Add(static_cast<std::string>(p.filename())); | ||
|
||
// Show dialog with list of pointfiles | ||
PointFileChooser chooser(filenames); | ||
chooser.ShowModal(); | ||
} | ||
|
||
// Hand over to the actual pointfile renderer to toggle visibility | ||
GlobalCommandSystem().executeCommand("TogglePointfile"); | ||
} | ||
|
||
} |
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,27 @@ | ||
#pragma once | ||
|
||
#include <wx/dialog.h> | ||
|
||
namespace ui | ||
{ | ||
|
||
/// Selector dialog for pointfiles associated with the current map | ||
class PointFileChooser: public wxDialog | ||
{ | ||
// Dialog constructor | ||
PointFileChooser(const wxArrayString& files); | ||
|
||
public: | ||
|
||
/** | ||
* \brief Toggle pointfile visibility, showing the chooser if necessary. | ||
* | ||
* If there is only a single pointfile available, this method acts as a | ||
* simple visibility toggle. If there is more than one pointfile, the | ||
* chooser dialog will be shown before toggling visibility on. If there are | ||
* no pointfiles available, an error dialog will be shown. | ||
*/ | ||
static void chooseAndToggle(); | ||
}; | ||
|
||
} |
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