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.
This commit is contained in:
parent
7c0cf9dff9
commit
98081d9243
2 changed files with 12 additions and 10 deletions
|
@ -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<SGPropertyNode_ptr> 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<SGPropertyNode_ptr> 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);
|
||||
}
|
||||
|
|
|
@ -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 <enabled> listener that enables/disables menu entries.
|
||||
void add_enabled_listener(SGPropertyNode * node);
|
||||
|
|
Loading…
Reference in a new issue