From 2de4fd5d8ee6a44b83479253625c2ccf767bb577 Mon Sep 17 00:00:00 2001 From: mfranz Date: Wed, 8 Mar 2006 10:44:46 +0000 Subject: [PATCH] add support for blocks and in XML dialogs: print("I'm called on dialog open") print("I'm called on dialog close") All Nasal runs in a dialog namespace, so that variables and functions defined in the block can be used in s, etc. This is especially useful for button handling. See "location-in-air.xml". --- src/GUI/dialog.cxx | 24 ++++++++++++++++++++++++ src/GUI/dialog.hxx | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/src/GUI/dialog.cxx b/src/GUI/dialog.cxx index ff10e691f..0ec2b9e4e 100644 --- a/src/GUI/dialog.cxx +++ b/src/GUI/dialog.cxx @@ -7,6 +7,7 @@ #include // atof() #include +#include #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)); diff --git a/src/GUI/dialog.hxx b/src/GUI/dialog.hxx index 6e2ad42bc..0bad5ad18 100644 --- a/src/GUI/dialog.hxx +++ b/src/GUI/dialog.hxx @@ -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