From fa8dc94fd8530ac1074fab2bfaaf7d8818530076 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Sat, 13 Feb 2016 12:21:59 +0000
Subject: [PATCH] better window title

---
 Common/GmshMessage.cpp |  9 +++++++++
 Common/GmshMessage.h   |  1 +
 Common/OpenFile.cpp    | 20 ++++++--------------
 Common/OpenFile.h      |  4 ++--
 Common/onelabUtils.cpp | 12 +++++++++---
 Fltk/graphicWindow.cpp |  8 +++-----
 Fltk/graphicWindow.h   |  1 -
 Geo/GModel.cpp         |  1 +
 8 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp
index 8ba2171ee7..fca1fd8bd6 100644
--- a/Common/GmshMessage.cpp
+++ b/Common/GmshMessage.cpp
@@ -509,6 +509,15 @@ void Msg::StatusGl(const char *fmt, ...)
 #endif
 }
 
+void Msg::SetWindowTitle(const std::string &title)
+{
+#if defined(HAVE_FLTK)
+  if(FlGui::available()){
+    FlGui::instance()->setGraphicTitle(title);
+  }
+#endif
+}
+
 void Msg::Debug(const char *fmt, ...)
 {
   if(_verbosity < 99) return;
diff --git a/Common/GmshMessage.h b/Common/GmshMessage.h
index 84b962ef27..7a453d17d2 100644
--- a/Common/GmshMessage.h
+++ b/Common/GmshMessage.h
@@ -88,6 +88,7 @@ class Msg {
   static void Direct(const char *fmt, ...);
   static void StatusBar(bool log, const char *fmt, ...);
   static void StatusGl(const char *fmt, ...);
+  static void SetWindowTitle(const std::string &title);
   static void Debug(const char *fmt, ...);
   static void ProgressMeter(int n, int N, bool log, const char *fmt, ...);
   static void SetProgressMeterStep(int step){ _progressMeterStep = step; }
diff --git a/Common/OpenFile.cpp b/Common/OpenFile.cpp
index 678d42eaed..a247574ea0 100644
--- a/Common/OpenFile.cpp
+++ b/Common/OpenFile.cpp
@@ -291,14 +291,8 @@ static int defineSolver(const std::string &name)
   return NUM_SOLVERS - 1;
 }
 
-int MergeFile(const std::string &fileName, bool warnIfMissing, bool setWindowTitle,
-              bool setBoundingBox)
+int MergeFile(const std::string &fileName, bool warnIfMissing, bool setBoundingBox)
 {
-#if defined(HAVE_FLTK)
-  if(FlGui::available() && setWindowTitle)
-    FlGui::instance()->setGraphicTitle(fileName);
-#endif
-
   // added 'b' for pure Windows programs, since some of these files
   // contain binary data
   gmshFILE fp = gmshopen(fileName.c_str(), "rb");
@@ -324,11 +318,11 @@ int MergeFile(const std::string &fileName, bool warnIfMissing, bool setWindowTit
     if(ext != ".geo" && ext != ".GEO" &&
        ext != ".unv" && ext != ".UNV"){
       if(doSystemUncompress(fileName, noExt))
-        return MergeFile(noExt, false, setWindowTitle);
+        return MergeFile(noExt, false);
     }
 #else
     if(doSystemUncompress(fileName, noExt))
-      return MergeFile(noExt, false, setWindowTitle);
+      return MergeFile(noExt, false);
 #endif
   }
 
@@ -581,8 +575,7 @@ int MergePostProcessingFile(const std::string &fileName, int showViews,
     GModel *m = new GModel();
     GModel::setCurrent(m);
   }
-  int ret = MergeFile(fileName, warnIfMissing, true,
-                      old->bounds().empty() ? true : false);
+  int ret = MergeFile(fileName, warnIfMissing, old->bounds().empty() ? true : false);
   GModel::setCurrent(old);
   old->setVisibility(1);
 
@@ -645,7 +638,6 @@ void ClearProject()
   GModel::current()->setName("");
 #if defined(HAVE_FLTK)
   if(FlGui::available()){
-    FlGui::instance()->setGraphicTitle(GModel::current()->getFileName());
     FlGui::instance()->resetVisibility();
     FlGui::instance()->updateViews(true, true);
     FlGui::instance()->updateFields();
@@ -655,7 +647,7 @@ void ClearProject()
   Msg::ResetErrorCounter();
 }
 
-void OpenProject(const std::string &fileName, bool setWindowTitle)
+void OpenProject(const std::string &fileName)
 {
   if(CTX::instance()->lock) {
     Msg::Info("I'm busy! Ask me that later...");
@@ -695,7 +687,7 @@ void OpenProject(const std::string &fileName, bool setWindowTitle)
   ResetTemporaryBoundingBox();
 
   // merge the file
-  MergeFile(fileName, false, setWindowTitle);
+  MergeFile(fileName, false);
 
   // fill recent opened file list
   std::vector<std::string> tmp = CTX::instance()->recentFiles;
diff --git a/Common/OpenFile.h b/Common/OpenFile.h
index cea05a87bb..4a4ada8979 100644
--- a/Common/OpenFile.h
+++ b/Common/OpenFile.h
@@ -10,10 +10,10 @@
 
 int ParseFile(const std::string &fileName, bool close, bool warnIfMissing=false);
 void ParseString(const std::string &str, bool inCurrentModelDir=false);
-void OpenProject(const std::string &filename, bool setWindowTitle=true);
+void OpenProject(const std::string &filename);
 void OpenProjectMacFinder(const char *fileName);
 int MergeFile(const std::string &fileName, bool warnIfMissing=false,
-              bool setWindowTitle=true, bool setBoundingBox=true);
+              bool setBoundingBox=true);
 int MergePostProcessingFile(const std::string &fileName, int showViews=2,
                             bool showLastStep=false, bool warnIfMissing=false);
 void ClearProject();
diff --git a/Common/onelabUtils.cpp b/Common/onelabUtils.cpp
index d0607fbeef..7b5b5f40c0 100644
--- a/Common/onelabUtils.cpp
+++ b/Common/onelabUtils.cpp
@@ -107,13 +107,14 @@ namespace onelabUtils {
 
   void guessModelName(onelab::client *c)
   {
+    std::string geo = GModel::current()->getFileName();
     std::vector<onelab::number> n;
     c->get(n, c->getName() + "/Guess model name");
     if(n.size() && n[0].getValue()){
       std::vector<onelab::string> ps;
       c->get(ps, c->getName() + "/Model name");
       if(ps.empty()){
-        std::vector<std::string> split = SplitFileName(GModel::current()->getFileName());
+        std::vector<std::string> split = SplitFileName(geo);
         std::string ext = "";
         onelab::server::instance()->get(ps, c->getName() + "/File extension");
         if(ps.size()) ext = ps[0].getValue();
@@ -122,8 +123,13 @@ namespace onelabUtils {
         o.setKind("file");
         o.setAttribute("Persistent", "1");
         c->set(o);
+        geo += std::string(" - ") + name;
+      }
+      else{
+        geo += std::string(" - ") + ps[0].getValue();
       }
     }
+    Msg::SetWindowTitle(geo);
   }
 
   void initializeLoop(const std::string &level)
@@ -349,7 +355,7 @@ namespace onelabUtils {
         // if the model name has changed
         modelName = GModel::current()->getName();
         redraw = true;
-        OpenProject(GModel::current()->getFileName(), false);
+        OpenProject(GModel::current()->getFileName());
       }
     }
     else if(action == "compute"){
@@ -359,7 +365,7 @@ namespace onelabUtils {
         // have been modified or if the model name has changed
         modelName = GModel::current()->getName();
         redraw = true;
-        OpenProject(GModel::current()->getFileName(), false);
+        OpenProject(GModel::current()->getFileName());
         if(getFirstComputationFlag() && !StatFile(mshFileName) && meshAuto != 2){
           Msg::Info("Skipping mesh generation: assuming '%s' is up-to-date "
                     "(use Solver.AutoMesh=2 to force mesh generation)",
diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp
index 85aad3c9ae..941934f6d6 100644
--- a/Fltk/graphicWindow.cpp
+++ b/Fltk/graphicWindow.cpp
@@ -232,7 +232,6 @@ static void file_window_cb(Fl_Widget *w, void *data)
     graphicWindow *g1 = FlGui::instance()->graph.back();
     graphicWindow *g2 = new graphicWindow(false, CTX::instance()->numTiles);
     FlGui::instance()->graph.push_back(g2);
-    FlGui::instance()->setGraphicTitle(GModel::current()->getFileName());
     g2->getWindow()->resize(g1->getWindow()->x() + 10,
                             g1->getWindow()->y() + 10,
                             g1->getWindow()->w(),
@@ -494,7 +493,6 @@ static void file_rename_cb(Fl_Widget *w, void *data)
     rename(GModel::current()->getFileName().c_str(), name.c_str());
     GModel::current()->setFileName(name);
     GModel::current()->setName(SplitFileName(name)[1]);
-    FlGui::instance()->setGraphicTitle(GModel::current()->getFileName());
     drawContext::global()->draw();
   }
 }
@@ -2465,7 +2463,7 @@ static void model_switch_cb(Fl_Widget* w, void *data)
     GModel::list[i]->setVisibility(0);
   GModel::current()->setVisibility(1);
   CTX::instance()->mesh.changed = ENT_ALL;
-  FlGui::instance()->setGraphicTitle(GModel::current()->getFileName());
+  Msg::SetWindowTitle(GModel::current()->getFileName());
   FlGui::instance()->resetVisibility();
   drawContext::global()->draw();
 }
@@ -3105,6 +3103,7 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu)
   if(CTX::instance()->menuSize[0] < minw) CTX::instance()->menuSize[0] = minw;
   _tile->position(twidth, 0, CTX::instance()->menuSize[0], 0);
 
+  _win->copy_label(GModel::current()->getFileName().c_str());
   _win->position(CTX::instance()->glPosition[0], CTX::instance()->glPosition[1]);
   _win->end();
 
@@ -3141,8 +3140,7 @@ graphicWindow::~graphicWindow()
 
 void graphicWindow::setTitle(std::string str)
 {
-  _title = str;
-  _win->label(_title.c_str());
+  _win->copy_label(str.c_str());
 }
 
 void graphicWindow::detachMenu()
diff --git a/Fltk/graphicWindow.h b/Fltk/graphicWindow.h
index 52859e118f..5a6559396c 100644
--- a/Fltk/graphicWindow.h
+++ b/Fltk/graphicWindow.h
@@ -23,7 +23,6 @@
 
 class graphicWindow{
  private:
-  std::string _title;
   bool _autoScrollMessages;
 #if defined(__APPLE__)
   Fl_Sys_Menu_Bar *_sysbar;
diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp
index 33df446c3e..3046c1817e 100644
--- a/Geo/GModel.cpp
+++ b/Geo/GModel.cpp
@@ -123,6 +123,7 @@ void GModel::setFileName(std::string fileName)
   _fileName = fileName;
   _fileNames.insert(fileName);
   Msg::SetOnelabString("Gmsh/Model name", fileName, false, false, true);
+  Msg::SetWindowTitle(fileName);
 }
 
 GModel *GModel::current(int index)
-- 
GitLab