From d94d8c8c7d7e77c45069bb97922c94297c40af56 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Tue, 23 Aug 2016 08:50:58 +0000 Subject: [PATCH] add way to remove last command in script generated interactively --- Fltk/graphicWindow.cpp | 30 ++++++++++++++++++++++++------ Geo/GeoStringInterface.cpp | 6 +++--- doc/VERSIONS.txt | 3 +++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp index 15f8edf9cc..8e7556bce2 100644 --- a/Fltk/graphicWindow.cpp +++ b/Fltk/graphicWindow.cpp @@ -618,7 +618,27 @@ void geometry_reload_cb(Fl_Widget *w, void *data) void geometry_remove_last_command_cb(Fl_Widget *w, void *data) { std::string fileName = GModel::current()->getFileName(); - // TODO! + // FIXME: make this work with compressed files + std::ifstream t(fileName); + std::stringstream buffer; + buffer << t.rdbuf(); + std::string s(buffer.str()); + int found = s.rfind("//+"); + if(found != std::string::npos){ + s.erase(found); + } + else{ + Msg::Warning("Could not find last command in script `%s'", fileName.c_str()); + return; + } + FILE *fp = Fopen(fileName.c_str(), "w"); + if(fp){ + fprintf(fp, "%s", s.c_str()); + fclose(fp); + } + else{ + Msg::Error("Could not open file `%s'", fileName.c_str()); + } OpenProject(fileName); drawContext::global()->draw(); } @@ -3746,13 +3766,11 @@ static menuItem static_modules[] = { (Fl_Callback *)geometry_physical_remove_cb, (void*)"Volume" } , {"0Modules/Geometry/Coherence", (Fl_Callback *)geometry_elementary_coherence_cb} , - {"0Modules/Geometry/Reload", + {"0Modules/Geometry/Reload script", (Fl_Callback *)geometry_reload_cb} , - /* FIXME: toto - {"0Modules/Geometry/Remove last command in file", + {"0Modules/Geometry/Remove last script command", (Fl_Callback *)geometry_remove_last_command_cb} , - */ - {"0Modules/Geometry/Edit file", + {"0Modules/Geometry/Edit script", (Fl_Callback *)geometry_edit_cb} , {"0Modules/Mesh/Define/Size fields", (Fl_Callback *)field_cb}, diff --git a/Geo/GeoStringInterface.cpp b/Geo/GeoStringInterface.cpp index 885079b694..004c53acfb 100644 --- a/Geo/GeoStringInterface.cpp +++ b/Geo/GeoStringInterface.cpp @@ -113,7 +113,7 @@ void add_infile(const std::string &text, const std::string &fileName, bool force Msg::Error("Unable to open file '%s'", fileName.c_str()); return; } - gmshprintf(fp, "%s\n", text.c_str()); + gmshprintf(fp, "//+\n%s\n", text.c_str()); gmshclose(fp); } else{ @@ -122,7 +122,7 @@ void add_infile(const std::string &text, const std::string &fileName, bool force Msg::Error("Unable to open file '%s'", fileName.c_str()); return; } - fprintf(fp, "%s\n", text.c_str()); + fprintf(fp, "//+\n%s\n", text.c_str()); fclose(fp); } #else @@ -131,7 +131,7 @@ void add_infile(const std::string &text, const std::string &fileName, bool force Msg::Error("Unable to open file '%s'", fileName.c_str()); return; } - fprintf(fp, "%s\n", text.c_str()); + fprintf(fp, "//+\n%s\n", text.c_str()); fclose(fp); #endif diff --git a/doc/VERSIONS.txt b/doc/VERSIONS.txt index 8ed30eac51..c9c52ca789 100644 --- a/doc/VERSIONS.txt +++ b/doc/VERSIONS.txt @@ -1,3 +1,6 @@ +2.13.3: new Tochnog file format export; added ability to remove last command in +scripts generated interactively. + 2.13.2 (August 18, 2016)): small improvements (scale labels, periodic and high-order meshes) and bug fixes. -- GitLab