1
0
Fork 0

add support for <nasal> blocks <open> and <close> in XML dialogs:

<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".
This commit is contained in:
mfranz 2006-03-08 10:44:46 +00:00
parent 77de0c8e09
commit 2de4fd5d8e
2 changed files with 28 additions and 0 deletions

View 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));

View 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