From c911586930538db17a22e2d156bcad7aa768fadc Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 2 Nov 2009 19:52:22 +0000
Subject: [PATCH] for view index for plugin script (not perfect when there are
 several views, but better than leaving -1)

---
 Fltk/pluginWindow.cpp | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/Fltk/pluginWindow.cpp b/Fltk/pluginWindow.cpp
index b35c559174..cc2d757554 100644
--- a/Fltk/pluginWindow.cpp
+++ b/Fltk/pluginWindow.cpp
@@ -109,8 +109,16 @@ static void add_scripting(GMSH_PostPlugin *p, PView *view)
   if(!FlGui::instance()->plugins->record->value()) return;
 
   std::string fileName;
-  if(view)
+  int oldIndex = -1;
+  if(view){
+    for(int i = 0; i < p->getNbOptions(); i++){
+      if(p->getOption(i)->str == "iView") {
+        oldIndex = p->getOption(i)->def;
+        p->getOption(i)->def = view->getIndex();
+      }
+    }
     fileName = view->getData()->getFileName();
+  }
   else
     fileName = GModel::current()->getFileName();
 
@@ -123,6 +131,14 @@ static void add_scripting(GMSH_PostPlugin *p, PView *view)
     fprintf(fp, "%s", p->serialize().c_str());
     fclose(fp);
   }
+
+  if(view && oldIndex != -1){
+    for(int i = 0; i < p->getNbOptions(); i++){
+      if(p->getOption(i)->str == "iView"){
+        p->getOption(i)->def = oldIndex;
+      }
+    }
+  }
 }
 
 static void plugin_run_cb(Fl_Widget *w, void *data)
-- 
GitLab