1
0
Fork 0

Fix property-inspector Nasal module hookup

We need to clone the binding nodes so that we
can set / override the module on each binding,
when opening a dialog multiple times.
This commit is contained in:
James Turner 2018-07-03 00:34:33 +01:00
parent 68a2e80cb1
commit 5c3c4a6733

View file

@ -1172,11 +1172,25 @@ FGPUIDialog::setupObject (puObject *object, SGPropertyNode *props)
if (props->hasValue("key")) if (props->hasValue("key"))
info->key = getKeyCode(props->getStringValue("key", "")); info->key = getKeyCode(props->getStringValue("key", ""));
for (auto bindingNode : bindings) { for (auto bindingNode : bindings) {
const char *cmd = bindingNode->getStringValue("command"); const char *cmd = bindingNode->getStringValue("command");
if (!strcmp(cmd, "nasal")) if (!strcmp(cmd, "nasal")) {
bindingNode->setStringValue("module", _module.c_str()); // we need to clone the binding node, so we can unique the
// Nasal module. Otherwise we always modify the global dialog
// definition, and cloned dialogs use the same Nasal module for
// <nasal> bindings, which goes wrong. (Especially, the property
// inspector)
// memory ownership works because SGBinding has a ref to its
// argument node and holds onto it.
SGPropertyNode_ptr copiedBinding = new SGPropertyNode;
copyProperties(bindingNode, copiedBinding);
copiedBinding->setStringValue("module", _module.c_str());
bindingNode = copiedBinding;
}
info->bindings.push_back(new SGBinding(bindingNode, globals->get_props())); info->bindings.push_back(new SGBinding(bindingNode, globals->get_props()));
} }
object->setCallback(action_callback); object->setCallback(action_callback);