Adding menu items dynamically possible?
Posted: Thu Aug 11, 2022 11:27 am
I tried to add menu items programmatically to the main menu but it does not work, the item seems to be added because numberOfItems returns the new item count but it is not shown in the menu bar, any hints? Also MenuID() returns a __NSArrayM which I is the items array?, instead of NSMenu
Code: Select all
EnableExplicit
Procedure main()
Protected.i win, menu, hmenuPB, hmenuApp, menItem
Protected.l ev
win = OpenWindow(#PB_Any, 10, 10, 400, 300, "test", #PB_Window_SystemMenu | #PB_Window_SizeGadget |
#PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget)
menu = CreateMenu(#PB_Any, WindowID(win))
hmenuPB = MenuID(menu) ; __NSArrayM ?
hmenuApp = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "mainMenu") ; NSMenu
MenuTitle("Title1")
Debug "items " + CocoaMessage(0, hmenuApp, "numberOfItems")
menItem = CocoaMessage(0, hmenuApp, "addItemWithTitle:$", @"Title 2", "action:", 0, "keyEquivalent:$", @"")
; Debug CocoaMessage(0, hmenuPB, "addObject:", menItem)
Debug "items " + CocoaMessage(0, hmenuApp, "numberOfItems")
Repeat
ev = WaitWindowEvent()
Until ev = #PB_Event_CloseWindow
EndProcedure
main()