From ee7b882dd9b0f563627e66570a5da05415ccf8f0 Mon Sep 17 00:00:00 2001 From: mfranz Date: Mon, 20 Jun 2005 18:52:54 +0000 Subject: [PATCH] - delete bindings in the *destructor* (must have been an editing accident) - create copies of bindings in /sim/bindings/, because FGBindings doesn't do that any more (is there a better way to find the first free child?) --- src/Cockpit/panel.cxx | 8 ++++---- src/Cockpit/panel_io.cxx | 29 ++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/Cockpit/panel.cxx b/src/Cockpit/panel.cxx index 4134c196c..cc0785c93 100644 --- a/src/Cockpit/panel.cxx +++ b/src/Cockpit/panel.cxx @@ -598,14 +598,14 @@ FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h, bool repeatable) : _button(button), _x(x), _y(y), _w(w), _h(h), _repeatable(repeatable) { - for (unsigned int i = 0; i < 2; i++) { - for (unsigned int j = 0; j < _bindings[i].size(); j++) - delete _bindings[i][j]; - } } FGPanelAction::~FGPanelAction () { + for (unsigned int i = 0; i < 2; i++) { + for (unsigned int j = 0; j < _bindings[i].size(); j++) + delete _bindings[i][j]; + } } void diff --git a/src/Cockpit/panel_io.cxx b/src/Cockpit/panel_io.cxx index 64641b5f7..b4185ddbb 100644 --- a/src/Cockpit/panel_io.cxx +++ b/src/Cockpit/panel_io.cxx @@ -182,19 +182,34 @@ readAction (const SGPropertyNode * node, float w_scale, float h_scale) FGPanelAction * action = new FGPanelAction(button, x, y, w, h, repeatable); vectorbindings = node->getChildren("binding"); + SGPropertyNode * dest = fgGetNode("/sim/bindings", true); - unsigned int i; + SGPropertyNode *binding; + unsigned int i, j; for (i = 0; i < bindings.size(); i++) { SG_LOG(SG_INPUT, SG_INFO, "Reading binding " - << bindings[i]->getStringValue("command")); - action->addBinding(new FGBinding(bindings[i]), 0); + << bindings[i]->getStringValue("command")); + + j = 0; + while (dest->getChild("binding", j)) + j++; + + binding = dest->getChild("binding", j, true); + copyProperties(bindings[i], binding); + action->addBinding(new FGBinding(binding), 0); } if (node->hasChild("mod-up")) { - bindings = node->getChild("mod-up")->getChildren("binding"); - for (i = 0; i < bindings.size(); i++) { - action->addBinding(new FGBinding(bindings[i]), 1); - } + bindings = node->getChild("mod-up")->getChildren("binding"); + for (i = 0; i < bindings.size(); i++) { + j = 0; + while (dest->getChild("binding", j)) + j++; + + binding = dest->getChild("binding", j, true); + copyProperties(bindings[i], binding); + action->addBinding(new FGBinding(binding), 1); + } } readConditions(action, node);