- I have some submenu inserted as Window item submenu of Main Menu
- I have an instance of my object (let's assume its class name is MenuController) inherited from NSObject and supports 2 from NSMenuDelegate methods: – numberOfItemsInMenu: – menu:updateItem:atIndex:shouldCancel:
- This instance added as Blue-Object into NIB for awaking at runtime
- Object from steps 2-3 configured as delegate for submenu (step 1)
Now, I can provide submenu content in runtime.
Next, I do following: I can add new items or remove old from an array (inside MenuController which contains menu titles) that mapped to real submenu via protocol and delegate. All works just fine. Except one thing: I like assign shortcuts to my dynamic menu items. CMD-1, CMD-2, CMD-3, etc
Window / MySubmenu / MyItem1 CMD-1, MyItem2 CMD-2, ...
So, for call some items I don't wanna go to Window / MySubmenu / MyItem to click it by mouse, I wanna press just one shortcut, like CMD-3 to call the item.
Ok, periodically it works as expected. But, generally, I have no way to inform Main Menu about my nested submenu changes, except open the Window / MySubmenu to reload its content. One stable way to reproduce the issue - just try to remove some item and press its old shortcut assigned to it, after you create new item as replace for deleted - bingo - shortcut wont work before you navigate to Window / MySubmenu to see current submenu content.
I don't know a way to force main menu to rebuild its submenus... I tried: [[NSApp mainMenu] update] and games with NSNotificationCenter for send NSMenuDidAddItemNotification, NSMenuDidRemoveItemNotification, NSMenuDidChangeItemNotification
I tried outlet to my submenu and call to update method explicitly - there is no way... Some times AppKit calls my delegate methods - and I see that, sometimes it doesn't want to call anything. Looks like a random strategy.
How can I make sure that after "some call" my submenu will be in actual state after internal array modifications?