diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ba4ece..e0be822 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Change log * 🎁 Add sample ICAO airport codes to combobox * 🎁 Interpret date `YYYY/MM/DD` prepended to METAR string +* 🎁 Read METAR information from file 1.2.2 ----- diff --git a/src/WettergeraetDesktop/Frame.cpp b/src/WettergeraetDesktop/Frame.cpp index 72728a9..a4c28f8 100644 --- a/src/WettergeraetDesktop/Frame.cpp +++ b/src/WettergeraetDesktop/Frame.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #include #include "Frame.h" @@ -35,7 +37,8 @@ Frame::Frame(const wxString& title, int argc, char * argv[]) : wxFrame(nullptr, wxMenuBar *menubar = new wxMenuBar; { wxMenu *file = new wxMenu; - file->Append(wxID_OPEN, wxT("&Load 'main.mcf'")); + file->Append(wxID_OPEN, wxT("&Open METAR file...")); + file->Append(EL_MENU_RELOAD, wxT("&Load 'main.mcf'")); file->AppendSeparator(); file->Append(wxID_EXIT, wxT("&Exit")); menubar->Append(file, wxT("&File")); @@ -397,6 +400,25 @@ void Frame::actionAbout(wxCommandEvent& WXUNUSED(event)) wxAboutBox(aboutInfo); } +void Frame::actionOpenMetarFile(wxCommandEvent& WXUNUSED(event)) +{ + wxFileDialog openFileDialog(this, _("Open METAR file"), "", "", "Text files (*.txt, *.rwx)|*.txt;*.rwx", wxFD_OPEN | wxFD_FILE_MUST_EXIST); + if (openFileDialog.ShowModal() == wxID_CANCEL) { + return; + } + + wxTextFile tfile; + tfile.Open(openFileDialog.GetPath()); + + auto metarString = tfile.GetFirstLine(); + if (!tfile.Eof()) { + metarString += "\n" + tfile.GetNextLine(); + } + this->metarInput->SetValue(metarString); + this->saveButton->SetFocus(); + this->markAsDirty(); +} + void Frame::actionLoadMainMcf(wxCommandEvent& WXUNUSED(event)) { this->loadMainMcf(); @@ -430,7 +452,8 @@ EVT_MENU(Frame::EL_MENU_UPDATE, Frame::actionUpdate) EVT_MENU(Frame::EL_MENU_FIND_ICAO, Frame::actionFindIcao) EVT_MENU(wxID_ABOUT, Frame::actionAbout) EVT_MENU(wxID_EXIT, Frame::actionExit) -EVT_MENU(wxID_OPEN, Frame::actionLoadMainMcf) +EVT_MENU(wxID_OPEN, Frame::actionOpenMetarFile) +EVT_MENU(Frame::EL_MENU_RELOAD, Frame::actionLoadMainMcf) EVT_TEXT(Frame::EL_CTRL_METAR, Frame::actionParse) EVT_SLIDER(Frame::EL_CTRL_SLIDER, Frame::actionMarkAsDirty) //EVT_DATE_CHANGED(Frame::EL_CTRL_DATETIME, Frame::actionMarkAsDirty) diff --git a/src/WettergeraetDesktop/Frame.h b/src/WettergeraetDesktop/Frame.h index 5286cb2..f2b8b4d 100644 --- a/src/WettergeraetDesktop/Frame.h +++ b/src/WettergeraetDesktop/Frame.h @@ -55,6 +55,7 @@ class Frame : public wxFrame static const unsigned short EL_CTRL_SLIDER = 6; static const unsigned short EL_MENU_UPDATE = 7; static const unsigned short EL_MENU_FIND_ICAO = 8; + static const unsigned short EL_MENU_RELOAD = 9; Frame(const wxString& title, int argc, char * argv[]); virtual ~Frame(); @@ -86,6 +87,10 @@ class Frame : public wxFrame virtual void actionAbout(wxCommandEvent&); + // Show file dialogue, copy METAR information from file to METAR input field + virtual void actionOpenMetarFile(wxCommandEvent&); + + // Reload main.mcf and copy values to main windows virtual void actionLoadMainMcf(wxCommandEvent&); virtual void actionUpdate(wxCommandEvent&);