Platforms to show: All Mac Windows Linux Cross-Platform
Back to NSMenuMBS class.
NSMenuMBS.addItem(m as NSMenuItemMBS)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 7.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
If the menuitem is nil, nothing happens.
The menuitem can only be in one menu.
The menu doesn't references to the RB classes behind, so it's up to you to keep those references if you want to get the events and avoid crashes.
The StatusItem example keeps an array with all those menu item objects it needs so RB will not destroy them.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 9.6 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
Available in Mac OS X v10.5 and later.
NSMenuMBS.cancelTrackingWithoutAnimation
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 9.6 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
Available in Mac OS X v10.6 and later.
NSMenuMBS.Constructor(Handle as Integer)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 15.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
Useful if you get a NSMenu reference from a declare.
The object is retained.
See also:
NSMenuMBS.Constructor(title as string="")
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 7.4 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
Title is optional.
See also:
NSMenuMBS.indexOfItem(item as NSMenuItemMBS) as Integer
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 9.6 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
Returns the integer index of the menu item or, if no such menu item is in the menu, –1.
NSMenuMBS.indexOfItemWithSelector(selector as string) as Integer
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 13.1 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
Returns -1 if not found.
You can use this to find menu items by their selector. Which is often more save than by index or title.
NSMenuMBS.indexOfItemWithSubmenu(item as NSMenuMBS) as Integer
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 9.6 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
item: A menu object that is a menu item of the receiver (that is, a submenu).
The integer index of the menu item or, if no such menu item is in the menu, –1.
NSMenuMBS.indexOfItemWithTag(tag as Integer) as Integer
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 9.6 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
Returns the integer index of the menu item or, if no such menu item is in the menu, –1.
NSMenuMBS.indexOfItemWithTitle(title as string) as Integer
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 9.6 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
The integer index of the menu item or, if no such menu item is in the menu, –1.
NSMenuMBS.insertItem(m as NSMenuItemMBS, index as Integer)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 7.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
If the menuitem is nil, nothing happens. A menuitem can only be part of one menu.
index: An integer index identifying the location of the menu item in the menu. Zero based.
NSMenuMBS.Item(index as Integer) as NSMenuItemMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 7.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
Index is from 0 to numberOfItems-1.
Remember: The objects returned are not the same Xojo objects used with additem or insertitem.
NSMenuMBS.itemWithSelector(selector as string) as NSMenuItemMBS
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 13.1 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
You can use this to find menu items by their selector. Which is often more save than by index or title.
NSMenuMBS.performActionForItemAtIndex(index as Integer)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 9.6 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
If a target is not specified, the message is sent to the first responder. As a side effect, this method posts NSMenuWillSendActionNotification and NSMenuDidSendActionNotification.
In Mac OS X v10.6 and laster the performActionForItemAtIndex no longer triggers menu validation. This is because validation is typically done during menu tracking or key equivalent matching, so the subsequent performActionForItemAtIndex validation was redundant. To trigger validation explicitly, use invoke the update method.
In Mac OS X v10.6 performActionForItemAtIndex, when called, now triggers highlighting in the menu bar. It also sends out appropriate accessibility notifications indicating the item was selected.
NSMenuMBS.popUpMenuPositioningItem(item as NSMenuItemMBS, location as NSPointMBS, view as NSViewMBS = nil) as boolean
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 14.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
item: The menu item to be positioned at the specified location in the view.
location: The location in the view coordinate system to display the menu item.
view: The view to display the menu item over.
Returns true if menu tracking ended because an item was selected, and false if menu tracking was cancelled for any reason.
Pops up the receiver as a popup menu. The top left corner of the specified item (if specified, item must be present in the receiver) is positioned at the specified location in the specified view, interpreted in the view's own coordinate system.
If item is nil, the menu is positioned such that the top left of the menu content frame is at the given location.
If view is nil, the location is interpreted in the screen coordinate system. This allows you to pop up a menu disconnected from any window.
Available in OS X v10.6 and later.
Some examples using this method:
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 9.6 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
This method is more efficient than removing menu items individually.
Unlike the other remove methods, this method does not post NSMenuDidChangeItemNotification notifications.
Available in Mac OS X v10.6 and later.
NSMenuMBS.removeItem(m as NSMenuItemMBS)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 7.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
Does nothing if menuitem is nil.
The Xojo object used to add the menuitem must not be the same as the one you use here, but the values for the menuitems handle property must match.
NSMenuMBS.removeItemAtIndex(index as Integer)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 7.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
Index is from 0 to NumberOfItems-1.
NSMenuMBS.selectedItems as NSMenuItemMBS()
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 23.5 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
An item is selected when its state is `NSControl.StateValue.on`.
Requires macOS Sonoma or newer.
NSMenuMBS.setSelectedItems(items() as NSMenuItemMBS)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 23.5 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
An item is selected when its state is `NSControl.StateValue.on`.
Setting `selectedItems` will select any items that are contained in the provided array, and deselect any previously selected items that are not in the array.
Requires macOS Sonoma or newer.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Cocoa Menus | MBS MacBase Plugin | 9.6 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop only |
The items on this page are in the following plugins: MBS MacBase Plugin.