Skip to content

Commit

Permalink
Append METAR information to clipboard file clip.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
fboes committed Jul 26, 2019
1 parent 0bc8bc6 commit f0802a2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Change log
1.2.10
------

* 🎁 Append METAR information to clipboard file `clip.txt`
* 💊 Limit variable wind bearing impact relative to wind force

1.2.9
Expand Down
43 changes: 43 additions & 0 deletions src/WettergeraetDesktop/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Frame::Frame(const wxString& title, int argc, char * argv[]) : wxFrame(nullptr,
wxMenu* file = new wxMenu;
file->Append(wxID_OPEN, wxT("&Open METAR File...\tCTRL+O"));
file->Append(wxID_SAVEAS, wxT("&Save METAR File As..."));
file->Append(Frame::EL_MENU_SAVECLIP, wxT("Save &Clipboard File..."));
file->AppendSeparator();
file->Append(EL_MENU_LOAD, wxT("Open &Aerofly Configuration File..."));
file->Append(EL_MENU_RELOAD, wxT("&Reload Aerofly Configuration File\tCTRL+R"));
Expand Down Expand Up @@ -477,6 +478,47 @@ void Frame::actionSaveMetarFile(wxCommandEvent& WXUNUSED(event))
tfile.Close();
}

void Frame::actionSaveClipFile(wxCommandEvent& WXUNUSED(event))
{
wxString defaultFilename = "clip.txt";

wxFileDialog saveFileDialog(this, _("Save Clipboard File"), "", defaultFilename, "Text files (*.txt)|*.txt", wxFD_SAVE);
if (saveFileDialog.ShowModal() == wxID_CANCEL) {
return;
}

wxString header = "METAR: ";
auto headerLength = header.length();
auto metarInput = header + this->metarInput->GetValue();
bool replace = false;

wxTextFile tfile(saveFileDialog.GetPath());
if (!tfile.Exists()) {
tfile.Create();
tfile.AddLine(metarInput);
}
else {
tfile.Open();

for (size_t n = 0; n < tfile.GetLineCount(); ++n)
{
wxString line = tfile.GetLine(n);
if (line.Left(headerLength) == header) {
tfile.RemoveLine(n);
tfile.InsertLine(metarInput, n);
replace = true;
}
}
if (!replace) {
tfile.AddLine("");
tfile.AddLine(metarInput);
}
}

tfile.Write();
tfile.Close();
}

void Frame::actionLoadMainMcf(wxCommandEvent& WXUNUSED(event))
{
wxFileName dingdong = wxFileName(this->currentMcfFilename);
Expand Down Expand Up @@ -555,6 +597,7 @@ EVT_MENU(wxID_ABOUT, Frame::actionAbout)
EVT_MENU(wxID_EXIT, Frame::actionExit)
EVT_MENU(wxID_OPEN, Frame::actionOpenMetarFile)
EVT_MENU(wxID_SAVEAS, Frame::actionSaveMetarFile)
EVT_MENU(Frame::EL_MENU_SAVECLIP, Frame::actionSaveClipFile)
EVT_MENU(Frame::EL_MENU_LOAD, Frame::actionLoadMainMcf)
EVT_MENU(Frame::EL_MENU_RELOAD, Frame::actionReloadMainMcf)
EVT_MENU(wxID_SAVE, Frame::actionSave)
Expand Down
6 changes: 5 additions & 1 deletion src/WettergeraetDesktop/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Frame : public wxFrame
static const unsigned short EL_MENU_LOAD = 10;
static const unsigned short EL_MENU_GET_PLATES = 11;
static const unsigned short EL_MENU_OPEN_WORLDCLOCK = 12;
static const unsigned short EL_MENU_SAVECLIP = 13;

Frame(const wxString& title, int argc, char * argv[]);
virtual ~Frame();
Expand Down Expand Up @@ -97,9 +98,12 @@ class Frame : public wxFrame
// Show file dialogue, copy METAR information from file to METAR input field
virtual void actionOpenMetarFile(wxCommandEvent&);

// Show file dialogue, copy METAR informtation from METAR input field to file
// Show file dialogue, copy METAR information from METAR input field to file
virtual void actionSaveMetarFile(wxCommandEvent&);

// Show file dialogue, _append_ METAR information to from METAR input field to file
virtual void actionSaveClipFile(wxCommandEvent&);

// Change main.mcf file location
virtual void actionLoadMainMcf(wxCommandEvent&);

Expand Down

0 comments on commit f0802a2

Please sign in to comment.