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

Hi,
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)
Thanks

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

s=new NSStatusItemMBS

// Create statusitem
call s.CreateMenu
s.HighlightMode=true
s.Title="MyApp"

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

// Create menu items
AboutMyAppMenu=new MyCocoamenuitem
AboutMyAppMenu.CreateMenuItem "About my App"
AboutMyAppMenu.ID=2
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",""
a.Enabled=true
a.tag=10
items.Append a
m.AddItem a
				
b=new MyCocoaMenuItemMBS
b.CreateSeparator
items.Append b
m.AddItem b
				
c=new MyCocoaMenuItemMBS
c.CreateMenuItem "Middle submenu entry",""
c.Enabled=true
c.tag=11
items.Append c
m.AddItem c
				
d=new MyCocoaMenuItemMBS
d.CreateMenuItem "Bottom submenu entry",""
d.Enabled=false
d.tag=12
items.Append d
m.AddItem d
				
AboutMyAppMenu.Submenu=m
  • 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)
    Thanks.

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.