/
PointFileChooser.cpp
78 lines (65 loc) · 2.23 KB
/
PointFileChooser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "PointFileChooser.h"
#include "ui/imainframe.h"
#include "imap.h"
#include "i18n.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
_pfChoice.reset(
new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, files)
);
_pfChoice->SetSelection(0);
GetSizer()->Add(_pfChoice.get(), 0, wxEXPAND | wxALL, 12);
// Add dialog buttons
auto btnSizer = CreateStdDialogButtonSizer(wxOK | wxCANCEL);
GetSizer()->Add(btnSizer, 0, wxALIGN_RIGHT | wxBOTTOM, 12);
Fit();
}
void PointFileChooser::chooseAndToggle()
{
// If the point trace is currently visible, toggle it to invisible and we're
// done.
if (GlobalMapModule().isPointTraceVisible())
{
GlobalMapModule().showPointFile({});
return;
}
// Determine the list of pointfiles
std::vector<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
std::size_t chosenPointfile = 0;
if (pointfiles.size() > 1)
{
// Construct list of wxString filenames
wxArrayString filenames;
for (const fs::path& p: pointfiles)
filenames.Add(p.filename().string());
// Show dialog with list of pointfiles
PointFileChooser chooser(filenames);
if (chooser.ShowModal() == wxID_OK)
chosenPointfile = chooser._pfChoice->GetSelection();
else
// Dialog cancelled, don't proceed to showing point trace
return;
}
// Show the chosen (or only) pointfile
if (chosenPointfile >= 0 && chosenPointfile < pointfiles.size())
GlobalMapModule().showPointFile(pointfiles[chosenPointfile]);
}
}