|
14 | 14 | #include <wx/sstream.h> |
15 | 15 | #include <wx/statline.h> |
16 | 16 | #include <wx/stattext.h> |
| 17 | +#include <wx/translation.h> |
17 | 18 | #include <wx/wrapsizer.h> |
18 | 19 |
|
19 | 20 | #ifndef ocpnUSE_wxBitmapBundle |
|
24 | 25 | #include "androidUTIL.h" |
25 | 26 | #endif |
26 | 27 |
|
27 | | -#include "tty_scroll.h" |
| 28 | +#include "model/navmsg_filter.h" |
| 29 | +#include "model/nmea_log.h" |
| 30 | +#include "model/gui.h" |
| 31 | + |
28 | 32 | #include "data_monitor_src.h" |
29 | 33 | #include "svg_icons.h" |
| 34 | +#include "tty_scroll.h" |
| 35 | + |
30 | 36 | #include "std_filesystem.h" |
31 | | -#include "model/nmea_log.h" |
32 | | -#include "model/gui.h" |
33 | 37 |
|
34 | 38 | #pragma clang diagnostic push |
35 | 39 | #pragma ide diagnostic ignored "UnreachableCode" |
36 | 40 |
|
| 41 | +// Make _() return std::string instead of wxString; |
| 42 | +#undef _ |
| 43 | +#if wxCHECK_VERSION(3, 2, 0) |
| 44 | +#define _(s) wxGetTranslation(wxASCII_STR(s)).ToStdString() |
| 45 | +#else |
| 46 | +#define _(s) wxGetTranslation((s)).ToStdString() |
| 47 | +#endif |
| 48 | + |
37 | 49 | using SetLogFunc = std::function<void(int)>; |
38 | 50 |
|
39 | 51 | /** Main window, a rolling log of messages. */ |
@@ -121,17 +133,36 @@ class LogButton : public wxButton { |
121 | 133 | /** Offer user to select current filter. */ |
122 | 134 | class FilterChoice : public wxChoice { |
123 | 135 | public: |
124 | | - FilterChoice(wxWindow* parent) : wxChoice() { |
125 | | - wxArrayString choices; |
126 | | - choices.Add(_("All data")); |
127 | | - choices.Add(_("All NMEA data")); |
128 | | - choices.Add(_("Incoming NMEA data")); |
129 | | - choices.Add(_("Outgoing NMEA data")); |
130 | | - choices.Add(_("Malformed data only")); |
131 | | - choices.Add(_("Plugin data")); |
132 | | - Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices); |
133 | | - SetSelection(0); |
| 136 | + FilterChoice(wxWindow* parent) : wxChoice(parent, wxID_ANY) { |
| 137 | + m_filters = NavmsgFilter::GetSystemFilters(); |
| 138 | + OnFilterListChange(); |
| 139 | + } |
| 140 | + |
| 141 | + void OnFilterListChange() { |
| 142 | + Clear(); |
| 143 | + for (auto& filter : m_filters) { |
| 144 | + try { |
| 145 | + Append(kLabels.at(filter.m_name)); |
| 146 | + } catch (std::out_of_range&) { |
| 147 | + Append(filter.m_description); |
| 148 | + } |
| 149 | + } |
| 150 | + if (!m_filters.empty()) SetSelection(0); |
134 | 151 | } |
| 152 | + |
| 153 | +private: |
| 154 | + // Translated labels for system filters by filter name. If not |
| 155 | + // found the untranslated json description is used. |
| 156 | + const std::unordered_map<std::string, std::string> kLabels = { |
| 157 | + {"all-data", _("All data")}, |
| 158 | + {"all-nmea", _("All NMEA data")}, |
| 159 | + {"malformed", _("Malformed messages")}, |
| 160 | + {"nmea-input", _("NMEA input data")}, |
| 161 | + {"nmea-output", _("NMEA output data")}, |
| 162 | + {"plugins", _("Messages to plugins")}, |
| 163 | + }; |
| 164 | + |
| 165 | + std::vector<NavmsgFilter> m_filters; |
135 | 166 | }; |
136 | 167 |
|
137 | 168 | /** Button to stop/resume messages in main log window. */ |
|
0 commit comments