From 9323c7a73f2c20c5c04d26c1cf1ba44fd8253a0d Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 3 Nov 2011 06:36:50 +0000
Subject: [PATCH] better interaction with Mac Finder

---
 Common/Gmsh.cpp     | 16 +++++++++-------
 Common/OpenFile.cpp | 10 ++--------
 Fltk/FlGui.cpp      |  2 +-
 Fltk/FlGui.h        |  4 ++++
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/Common/Gmsh.cpp b/Common/Gmsh.cpp
index 71e2e678d5..c5d3892fdb 100644
--- a/Common/Gmsh.cpp
+++ b/Common/Gmsh.cpp
@@ -210,14 +210,16 @@ int GmshFLTK(int argc, char **argv)
   FlGui::instance()->check();
 
   // open project file and merge all other input files
-  OpenProject(GModel::current()->getFileName());
-  for(unsigned int i = 1; i < CTX::instance()->files.size(); i++){
-    if(CTX::instance()->files[i] == "-new"){
-      GModel::current()->setVisibility(0);
-      new GModel();
+  if(!FlGui::instance()->getOpenedThroughMacFinder()){
+    OpenProject(GModel::current()->getFileName());
+    for(unsigned int i = 1; i < CTX::instance()->files.size(); i++){
+      if(CTX::instance()->files[i] == "-new"){
+        GModel::current()->setVisibility(0);
+        new GModel();
+      }
+      else
+        MergeFile(CTX::instance()->files[i]);
     }
-    else
-      MergeFile(CTX::instance()->files[i]);
   }
 
   if(CTX::instance()->post.combineTime){
diff --git a/Common/OpenFile.cpp b/Common/OpenFile.cpp
index 5301cfa503..e2106ec106 100644
--- a/Common/OpenFile.cpp
+++ b/Common/OpenFile.cpp
@@ -504,14 +504,8 @@ void OpenProject(std::string fileName)
 void OpenProjectMacFinder(const char *fileName)
 {
 #if defined(HAVE_FLTK)
-  static int first = 1;
-  if(first || !FlGui::available()){
-    // just copy the filename: it will be opened when the GUI is ready
-    // in main()
-    GModel::current()->setFileName(fileName);
-    first = 0;
-  }
-  else{
+  if(FlGui::available()){
+    FlGui::instance()->setOpenedThroughMacFinder(true);
     OpenProject(fileName);
     drawContext::global()->draw();
   }
diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp
index 07f23b16de..abd35b0f0b 100644
--- a/Fltk/FlGui.cpp
+++ b/Fltk/FlGui.cpp
@@ -174,7 +174,7 @@ static int globalShortcut(int event)
   return FlGui::instance()->testGlobalShortcuts(event);
 }
 
-FlGui::FlGui(int argc, char **argv)
+FlGui::FlGui(int argc, char **argv) : _openedThroughMacFinder(false)
 {
   // set X display
   if(CTX::instance()->display.size())
diff --git a/Fltk/FlGui.h b/Fltk/FlGui.h
index 693329bdd7..b793307563 100644
--- a/Fltk/FlGui.h
+++ b/Fltk/FlGui.h
@@ -43,6 +43,7 @@ class MElement;
 class FlGui{
  private:
   static FlGui *_instance;
+  bool _openedThroughMacFinder;
  public:
   std::vector<GVertex*> selectedVertices;
   std::vector<GEdge*> selectedEdges;
@@ -80,6 +81,9 @@ class FlGui{
   static void wait(){ Fl::wait(); }
   // wait (at most time seconds) for any events, then process them
   static void wait(double time){ Fl::wait(time); }
+  // is a file opened through the Mac Finder?
+  void setOpenedThroughMacFinder(bool val){ _openedThroughMacFinder = val; }
+  bool getOpenedThroughMacFinder(){ return _openedThroughMacFinder; }
   // test application-level keyboard shortcuts
   int testGlobalShortcuts(int event);
   // test the arrow shortcuts (not in the application-level shortcuts)
-- 
GitLab