From 98081d9243fba9bf01dd827b9036efedfb842cb8 Mon Sep 17 00:00:00 2001 From: mfranz Date: Wed, 14 Dec 2005 07:45:47 +0000 Subject: [PATCH] don't check for subsequent indices (n), but for child positions; This way it's also possible to enable/disable menu/item entries with higher numbers. This can be useful for adding entries from other config files (aircraft specific or local). I'd say aircraft files can use indices starting with [100] and local files starting with [1000]. Such high number will never collide with an entry in menubar.xml, even if entries are added/removed there. --- src/GUI/menubar.cxx | 20 +++++++++++--------- src/GUI/menubar.hxx | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/GUI/menubar.cxx b/src/GUI/menubar.cxx index 285fc5eb4..db26c919d 100644 --- a/src/GUI/menubar.cxx +++ b/src/GUI/menubar.cxx @@ -302,7 +302,7 @@ FGMenuBar::make_menubar(SGPropertyNode * props) make_menu(menu_nodes[i]); _menuBar->close(); - make_map(props); + make_object_map(props); if (_visible) _menuBar->reveal(); @@ -352,9 +352,10 @@ FGMenuBar::destroy_menubar () } void -FGMenuBar::make_map(SGPropertyNode * node) +FGMenuBar::make_object_map(SGPropertyNode * node) { - int menu_index = 0; + unsigned int menu_index = 0; + vector menus = node->getChildren("menu"); for (puObject *obj = ((puGroup *)_menuBar)->getFirstChild(); obj; obj = obj->getNextObject()) { @@ -363,13 +364,13 @@ FGMenuBar::make_map(SGPropertyNode * node) if (!(obj->getType() & PUCLASS_ONESHOT)) continue; - SGPropertyNode *menu = node->getNode("menu", menu_index, false); - if (!menu) { + if (menu_index >= menus.size()) { SG_LOG(SG_GENERAL, SG_WARN, "'menu' object without node: " << node->getPath() << "/menu[" << menu_index << ']'); - continue; + return; } + SGPropertyNode *menu = menus.at(menu_index); _objects[menu->getPath()] = obj; add_enabled_listener(menu); @@ -383,13 +384,14 @@ FGMenuBar::make_map(SGPropertyNode * node) for (puObject *me = popup->getFirstChild(); me; me = me->getNextObject()) e.push_back(me); + vector items = menu->getChildren("item"); for (unsigned int i = 0; i < e.size(); i++) { - SGPropertyNode *item = menu->getNode("item", e.size() - i - 1, false); - if (!item) { + if (i >= items.size()) { SG_LOG(SG_GENERAL, SG_WARN, "'item' object without node: " << menu->getPath() << "/item[" << i << ']'); - continue; + break; } + SGPropertyNode *item = items.at(e.size() - i - 1); _objects[item->getPath()] = e[i]; add_enabled_listener(item); } diff --git a/src/GUI/menubar.hxx b/src/GUI/menubar.hxx index f50222b4f..4d21903a5 100644 --- a/src/GUI/menubar.hxx +++ b/src/GUI/menubar.hxx @@ -111,7 +111,7 @@ private: void make_menubar (); // Create a property-path -> puObject map for menu node - void make_map(SGPropertyNode * node); + void make_object_map(SGPropertyNode * node); // Add listener that enables/disables menu entries. void add_enabled_listener(SGPropertyNode * node);