Menubar component

hi everyone

i know how to work with this componente, create menus and menuitems , but i’d like to know how can we see in what index are we gonna add a menuitem?

I 'll explain

I’m building a menubar that i want to be able to update on the fly , without having to modify any xml file , but i can’t seem to figure out aou to find the index of the menu i want .

for instance if i have a menu with this options

File ->New->text file
pdf file

how do i know wich is the index of option “pdf file” ?