How to create a submenu in the menu bar with MBS?

I’m making a drop-down menu that shows up in Apple’s menubar. For this I use MBS plugins, and I left. from the “Name in menu bar” example (in the /Example/MacCocoa/NSStatusItem folder) but I can’t figure out how to create a submenu of an item.
I did not find a simple example of sub-menus (except those of dynamic creation, on the fly)

var f as FolderItem
var period as integer
var d as NSMenuItemMBS

s=new NSStatusItemMBS

// Create statusitem
call s.CreateMenu

// create a menu to attach to the statusitem
m=new NSMenuMBS

// Create menu items
AboutMyAppMenu=new MyCocoamenuitem
AboutMyAppMenu.CreateMenuItem "About my App"
m.AddItem AboutMyAppMenu

//Add submenus ???

Well, you create menu items and then you assign them to submenu property of the menu item:

dim f as NSMenuItemMBS
dim a,b,c,d as MyCocoaMenuItemMBS
dim m,mm as NSMenuMBS
m=new NSMenuMBS
a=new MyCocoaMenuItemMBS
a.CreateMenuItem "Top submenu entry",""
items.Append a
m.AddItem a
b=new MyCocoaMenuItemMBS
items.Append b
m.AddItem b
c=new MyCocoaMenuItemMBS
c.CreateMenuItem "Middle submenu entry",""
items.Append c
m.AddItem c
d=new MyCocoaMenuItemMBS
d.CreateMenuItem "Bottom submenu entry",""
items.Append d
m.AddItem d
  • Sorry Christian, the line “AboutMyAppMenu.Submenu=m”
    causes a project crash (I have to activate the “Force to quit” menu !)
    (In addition, the MBS “StatusItem” examples with creation of dynamic submenus also generate an exception for me, on the “f=mm.Item(2)” line, when pressing the button to Create a submenu)
  • What does the variable items correspond to (it is not declared in your post)

Could you please send me a crash report as email?

And also make sure you keep the objects in an array to avoid them being destroyed too early.

Well, not a crash here and an exception. Just an endless loop.

You set a menu to be the submenu for itself. There is a recursion inside your menu construction!

So m is the menu for the status item and you can’t make it also submenu for Menu2 entry.