I'm tryin to generate the complete list of all the main menu items, complete with their paths (File/Open).

I'm able to loop through all the items, but I cannot get the complete paths to all the items to work correctly.
Many of the items are coming up without as not having a parent that is a popup group. Is there an easier way to generate this or is my method the correct way but I have just messed something up?

Thanks.

Code to loop through all items
CODE

service_enum_t<mainmenu_commands> e;
service_ptr_t<mainmenu_commands> ptr;

g_mm_names.remove_all();
g_mm_guids.remove_all();
while(e.next(ptr))
{
unsigned count = ptr->get_command_count();

for ( unsigned n = 0; n < count; n++ )
{
pfc::string8 path;
pfc::string8 name;
GUID guid;

ptr->get_name( n, name );
guid = ptr->get_command( n );
find_menu_path( ptr->get_parent(), path );

g_mm_names.add_item( name );
g_mm_guids.add_item( guid );
g_mm_paths.add_item( path );
}

total += count;
}


code to find complete paths:
CODE

bool find_menu_path( GUID & parent, pfc::string8 & out )
{
if ( parent == pfc::guid_null )
{
out.set_string( "main menu" );
return true;
}
else
{
service_enum_t<mainmenu_group> e;
service_ptr_t<mainmenu_group> ptr;

while ( e.next( ptr ) )
{
if ( ptr->get_guid() == parent )
{
pfc::string8 tmp;

service_ptr_t<mainmenu_group_popup> popup;

if ( ptr->service_query_t( popup ) )
{
popup->get_display_string( tmp );
find_menu_path( ptr->get_parent(), out );
out.add_string( "/" );
out.add_string( tmp );
return true;
}
else
{
out.add_string( "main menu/not popup/" );
return false;
}
}
}
}

out.set_string( "main menu" );
return false;
}