]> git.mxchange.org Git - flightgear.git/commitdiff
add support for <nasal> blocks <open> and <close> in XML dialogs:
authormfranz <mfranz>
Wed, 8 Mar 2006 10:44:46 +0000 (10:44 +0000)
committermfranz <mfranz>
Wed, 8 Mar 2006 10:44:46 +0000 (10:44 +0000)
  <nasal>
      <open>print("I'm called on dialog open")</open>
      <close>print("I'm called on dialog close")</close>
  </nasal>

All Nasal runs in a dialog namespace, so that variables and functions
defined in the <open> block can be used in <binding>s, etc. This is
especially useful for <radio> button handling. See "location-in-air.xml".

src/GUI/dialog.cxx
src/GUI/dialog.hxx

index ff10e691f9ad7b4d569ec085ba6646719eee831f..0ec2b9e4e334724125c744262c7388e046af379a 100644 (file)
@@ -7,6 +7,7 @@
 #include <stdlib.h>            // atof()
 
 #include <Input/input.hxx>
+#include <Scripting/NasalSys.hxx>
 
 #include "dialog.hxx"
 #include "new_gui.hxx"
@@ -324,6 +325,17 @@ FGDialog::FGDialog (SGPropertyNode * props)
       _gui((NewGUI *)globals->get_subsystem("gui")),
       _props(props)
 {
+    _module = string("__dlg:") + props->getStringValue("name", "[unnamed]");
+    SGPropertyNode *nasal = props->getNode("nasal");
+    if (nasal) {
+        _nasal_close = nasal->getNode("close");
+        SGPropertyNode *open = nasal->getNode("open");
+        if (open) {
+            const char *s = open->getStringValue();
+            FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
+            nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s));
+        }
+    }
     display(props);
 }
 
@@ -333,6 +345,14 @@ FGDialog::~FGDialog ()
     _object->getAbsolutePosition(&x, &y);
     _props->setIntValue("lastx", x);
     _props->setIntValue("lasty", y);
+
+    FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
+    if (_nasal_close) {
+        const char *s = _nasal_close->getStringValue();
+        nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s));
+    }
+    nas->deleteModule(_module.c_str());
+
     puDeleteObject(_object);
 
     unsigned int i;
@@ -727,6 +747,10 @@ FGDialog::setupObject (puObject * object, SGPropertyNode * props)
             while (dest->getChild("binding", j))
                 j++;
 
+            const char *cmd = bindings[i]->getStringValue("command");
+            if (!strcmp(cmd, "nasal") && _module[0])
+                bindings[i]->setStringValue("module", _module.c_str());
+
             binding = dest->getChild("binding", j, true);
             copyProperties(bindings[i], binding);
             info->bindings.push_back(new FGBinding(binding));
index 6e2ad42bc916dc88a6aeae7d31080d3eb9584754..0bad5ad18c60c778045dc7b12bd99d8b463d0600 100644 (file)
@@ -150,6 +150,10 @@ private:
     // last position.
     SGPropertyNode_ptr _props;
 
+    // Nasal module.
+    string _module;
+    SGPropertyNode_ptr _nasal_close;
+
     // PUI provides no way for userdata to be deleted automatically
     // with a GUI object, so we have to keep track of all the special
     // data we allocated and then free it manually when the dialog