From 55a713d87697ddf56dec9358358a8d8f045e5528 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Wed, 30 Jan 2013 13:41:04 +0000
Subject: [PATCH] use fl_open_uri to open urls (instead of our own half-baked
 solution)

fixes Ticket #161
---
 Common/Context.h        |  4 +--
 Common/DefaultOptions.h | 10 -------
 Common/Options.cpp      | 12 --------
 Common/Options.h        |  1 -
 Fltk/graphicWindow.cpp  |  3 +-
 Fltk/helpWindow.cpp     |  3 +-
 Fltk/optionWindow.cpp   | 61 ++++++++++++++++++-----------------------
 7 files changed, 31 insertions(+), 63 deletions(-)

diff --git a/Common/Context.h b/Common/Context.h
index 9528aaed6d..fbfccbfee9 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -96,8 +96,8 @@ class CTX {
   int terminal;
   // number of graphical windows/tiles
   int numWindows, numTiles;
-  // text editor and web browser command (with included '%s')
-  std::string editor, webBrowser;
+  // text editor command (with included '%s')
+  std::string editor;
   // pattern of files to watch out for
   std::string watchFilePattern;
   // show tootips in the GUI?
diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index 23e71f2c09..2dce56137d 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -109,16 +109,6 @@ StringXString GeneralOptions_String[] = {
 #endif
     "Temporary file used by the geometry module" },
 
-  { F|O, "WebBrowser" , opt_general_web_browser ,
-#if defined(WIN32)
-    "explorer.exe %s" ,
-#elif defined(__APPLE__)
-    "open %s" ,
-#else
-    "sensible-browser %s" ,
-#endif
-    "System command to launch a web browser" },
-
   { F, "WatchFilePattern", opt_general_watch_file_pattern , "" ,
      "Pattern of files to merge as they become available"},
 
diff --git a/Common/Options.cpp b/Common/Options.cpp
index 20ae7a5516..5d2b22ecb9 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1183,18 +1183,6 @@ std::string opt_general_editor(OPT_ARGS_STR)
   return CTX::instance()->editor;
 }
 
-std::string opt_general_web_browser(OPT_ARGS_STR)
-{
-  if(action & GMSH_SET)
-    CTX::instance()->webBrowser = val;
-#if defined(HAVE_FLTK)
-  if(FlGui::available() && (action & GMSH_GUI))
-    FlGui::instance()->options->general.input[2]->value
-      (CTX::instance()->webBrowser.c_str());
-#endif
-  return CTX::instance()->webBrowser;
-}
-
 std::string opt_general_watch_file_pattern(OPT_ARGS_STR)
 {
   if(action & GMSH_SET)
diff --git a/Common/Options.h b/Common/Options.h
index ee1006cf68..8446614eef 100644
--- a/Common/Options.h
+++ b/Common/Options.h
@@ -47,7 +47,6 @@ std::string opt_general_recent_file2(OPT_ARGS_STR);
 std::string opt_general_recent_file3(OPT_ARGS_STR);
 std::string opt_general_recent_file4(OPT_ARGS_STR);
 std::string opt_general_editor(OPT_ARGS_STR);
-std::string opt_general_web_browser(OPT_ARGS_STR);
 std::string opt_general_watch_file_pattern(OPT_ARGS_STR);
 std::string opt_general_gui_theme(OPT_ARGS_STR);
 std::string opt_general_graphics_font(OPT_ARGS_STR);
diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp
index 19c1ab3d8c..f4ff9c4df5 100644
--- a/Fltk/graphicWindow.cpp
+++ b/Fltk/graphicWindow.cpp
@@ -525,8 +525,7 @@ void file_watch_cb(Fl_Widget *w, void *data)
 
 static void help_online_cb(Fl_Widget *w, void *data)
 {
-  std::string prog = FixWindowsPath(CTX::instance()->webBrowser);
-  SystemCall(ReplaceSubString("%s", "http://geuz.org/gmsh/doc/texinfo/", prog));
+  fl_open_uri("http://geuz.org/gmsh/doc/texinfo/");
 }
 
 static void help_basic_cb(Fl_Widget *w, void *data)
diff --git a/Fltk/helpWindow.cpp b/Fltk/helpWindow.cpp
index 93a52c6e01..2d83de40a8 100644
--- a/Fltk/helpWindow.cpp
+++ b/Fltk/helpWindow.cpp
@@ -22,8 +22,7 @@
 
 static const char *help_link(Fl_Widget *w, const char *uri)
 {
-  std::string prog = FixWindowsPath(CTX::instance()->webBrowser);
-  SystemCall(ReplaceSubString("%s", uri, prog));
+  fl_open_uri(uri);
   return 0;
 }
 
diff --git a/Fltk/optionWindow.cpp b/Fltk/optionWindow.cpp
index add6bf1d3e..578336e766 100644
--- a/Fltk/optionWindow.cpp
+++ b/Fltk/optionWindow.cpp
@@ -330,7 +330,6 @@ static void general_options_ok_cb(Fl_Widget *w, void *data)
 
   opt_general_default_filename(0, GMSH_SET, o->general.input[0]->value());
   opt_general_editor(0, GMSH_SET, o->general.input[1]->value());
-  opt_general_web_browser(0, GMSH_SET, o->general.input[2]->value());
   opt_general_axes_format0(0, GMSH_SET, o->general.input[3]->value());
   opt_general_axes_format1(0, GMSH_SET, o->general.input[4]->value());
   opt_general_axes_format2(0, GMSH_SET, o->general.input[5]->value());
@@ -1400,60 +1399,54 @@ optionWindow::optionWindow(int deltaFontSize)
       Fl_Group *o = new Fl_Group
         (L + WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Advanced");
 
+      general.butt[7] = new Fl_Check_Button
+        (L + 2 * WB, 2 * WB + 1 * BH, BW, BH, "Print messages on terminal");
+      general.butt[7]->type(FL_TOGGLE_BUTTON);
+      general.butt[7]->callback(general_options_ok_cb);
+
+      general.value[5] = new Fl_Value_Input
+        (L + 2 * WB, 2 * WB + 2 * BH, IW, BH, "Message verbosity");
+      general.value[5]->minimum(0);
+      general.value[5]->maximum(10);
+      general.value[5]->step(1);
+      general.value[5]->align(FL_ALIGN_RIGHT);
+      general.value[5]->callback(general_options_ok_cb);
+
       general.input[1] = new Fl_Input
-        (L + 2 * WB, 2 * WB + 1 * BH, IW, BH, "Text editor command");
+        (L + 2 * WB, 2 * WB + 3 * BH, IW, BH, "Text editor command");
       general.input[1]->align(FL_ALIGN_RIGHT);
       general.input[1]->callback(general_options_ok_cb);
 
-      general.input[2] = new Fl_Input
-        (L + 2 * WB, 2 * WB + 2 * BH, IW, BH, "Web browser command");
-      general.input[2]->align(FL_ALIGN_RIGHT);
-      general.input[2]->callback(general_options_ok_cb);
+      general.input[0] = new Fl_Input
+        (L + 2 * WB, 2 * WB + 4 * BH, IW, BH, "Default file name");
+      general.input[0]->align(FL_ALIGN_RIGHT);
+      general.input[0]->callback(general_options_ok_cb);
 
-      general.butt[7] = new Fl_Check_Button
-        (L + 2 * WB, 2 * WB + 3 * BH, BW, BH, "Print messages on terminal");
-      general.butt[7]->type(FL_TOGGLE_BUTTON);
-      general.butt[7]->callback(general_options_ok_cb);
+      general.butt[14] = new Fl_Check_Button
+        (L + 2 * WB, 2 * WB + 5 * BH, BW, BH, "Ask confirmation before overwriting files");
+      general.butt[14]->type(FL_TOGGLE_BUTTON);
+      general.butt[14]->callback(general_options_ok_cb);
 
       general.butt[8] = new Fl_Check_Button
-        (L + 2 * WB, 2 * WB + 4 * BH, BW, BH, "Save session information on exit");
+        (L + 2 * WB, 2 * WB + 6 * BH, BW, BH, "Save session information on exit");
       general.butt[8]->type(FL_TOGGLE_BUTTON);
       general.butt[8]->callback(general_options_ok_cb);
 
       Fl_Button *b0 = new Fl_Button
-        (L + width - 2 * WB - BW/3, 2 * WB + 4 * BH, BW/3, BH, "Show file path");
+        (L + width - 2 * WB - BW/3, 2 * WB + 6 * BH, BW/3, BH, "Show file path");
       b0->callback(options_show_file_cb, (void*)"session");
 
       general.butt[9] = new Fl_Check_Button
-        (L + 2 * WB, 2 * WB + 5 * BH, BW/2-WB, BH, "Save options on exit");
+        (L + 2 * WB, 2 * WB + 7 * BH, BW/2-WB, BH, "Save options on exit");
       general.butt[9]->type(FL_TOGGLE_BUTTON);
       general.butt[9]->callback(general_options_ok_cb);
 
       Fl_Button *b1 = new Fl_Button
-        (L + width - 2 * WB - BW/3, 2 * WB + 5 * BH, BW/3, BH, "Show file path");
+        (L + width - 2 * WB - BW/3, 2 * WB + 7 * BH, BW/3, BH, "Show file path");
       b1->callback(options_show_file_cb, (void*)"option");
 
-      general.butt[14] = new Fl_Check_Button
-        (L + 2 * WB, 2 * WB + 6 * BH, BW, BH,
-         "Ask confirmation before overwriting files");
-      general.butt[14]->type(FL_TOGGLE_BUTTON);
-      general.butt[14]->callback(general_options_ok_cb);
-
-      general.value[5] = new Fl_Value_Input
-        (L + 2 * WB, 2 * WB + 7 * BH, IW, BH, "Message verbosity");
-      general.value[5]->minimum(0);
-      general.value[5]->maximum(10);
-      general.value[5]->step(1);
-      general.value[5]->align(FL_ALIGN_RIGHT);
-      general.value[5]->callback(general_options_ok_cb);
-
-      general.input[0] = new Fl_Input
-        (L + 2 * WB, 2 * WB + 8 * BH, IW, BH, "Default file name");
-      general.input[0]->align(FL_ALIGN_RIGHT);
-      general.input[0]->callback(general_options_ok_cb);
-
       Fl_Button *b2 = new Fl_Button
-        (L + 2 * WB, 2 * WB + 10 * BH, BW, BH, "Restore all options to default values");
+        (L + 2 * WB, 2 * WB + 9 * BH, BW, BH, "Restore all options to default values");
       b2->callback(options_restore_defaults_cb);
       b2->labelcolor(FL_DARK_RED);
 
-- 
GitLab