nsmenu

Is there an equivalent technique in Cocoa for the synchronous TrackPopupMenu in Windows?

In response to a rightMouse event I want to call a function that displays a context menu, runs it, and responds to the selected menu item. In Windows I can use TrackPopupMenu with the TPM_RETURNCMD flag. What is the easiest way to implement this in Cocoa? It seems NSMenu:popUpContextMenu wants to post an event to the specified NSView....

How can I keep an NSPopUpButton open after the user selects a menu item?

I have an NSPopUpButton providing the NSMenu for a status item with a custom view. The popup button displays a list of links. When the user selects a link from the list, the link is displayed in the user's browser (in the background). Naturally, the menu closes every time the user selects a link. I would like to change this: I want t...

App crashes when updating an highlighted NSMenuItem

Heyho! I've a little app running as LSUIElement with a NSStatusItem. Sometimes the popupmenu's menuitems are updated by the code. But when the updated NSMenuItem (or its supermenu) is "highlighted" the app crashes without logging something. Do you have any idea? Thank you very much for your answers. ...

contextual menu item are not getting activated

Thanks Chuck for the quick reply. I am having a new problem now. my contextual menu is getting displayed but the menu items are not activated. so my new code for displaying the menu is as follows: NSMenu *defMenu = [[[NSMenu alloc] initWithTitle:@"default Contextual Menu"] autorelease]; [defMenu insertItemWithTitle:@"Open" action:@sele...

How to have an NSMenu with dynamic actions

I want to create an NSMenu with an option similar to the Send To option you'd find in Windows Explorer where it will list the devices attached that you can send the file to. From my research it seems that it's not possible to define a selector that sends a parameter to the function as well, so it's not a case of having @selector(@"sendT...

How to add a pop-up menu to a NSToolbarItem?

Hi, I'm trying to open a pop-up menu from a NSToolbarItem. I tried following this example but I can't use that class method because NSToolbar and NSToolbarItem inherit from NSObject and not from NSView. Apart from creating a custom view, what is the best way to open a pop-up menu from a NSToolbarItem? ...

What's the cleanest way to bind enumerated properties?

I have a menu which has an item for each value in an enum. The menu: [ ] Sort by Due Date [ ] Sort by Priority [√] Sort by Title The enum: typedef enum CW_TASK_SORT_METHOD { CWTaskSortMethodDueDate, CWTaskSortMethodPriority, CWTaskSortMethodTitle } CWTaskSortMethod; The property: @property(readwrite, assign) CWTaskSo...

How to associate an action to a keyboard shortcut?

Hi all, I've an IBAction that calls up a panel. I want to invoke that action with a keyboard shortcut but I'm at a loss on how to do it. I guess one way of doing it would be to create a menu item, associate the action to the item and then assign the shortcut to that item, but I haven't done my menus yet. Any ideas or suggestions? ...

Custom NSStatusItem with custom view - Use NSWindow, NSView, custom NSMenuItem?

I'm trying to create a LSUIElement app that behaves like Spotlight, CoverSutra and other apps of that type. I managed to create a custom NSStatusItem, which popups up an NSWindow but the problem is that the app that currently has focus will the focus to my custom NSWindow. I've based myself on Matt Gemmell's example (http://mattgemmell....

NSView in NSMenu -- how to make "key" for accepting keyboard commands [specifically, return]

I have a text field and a button living in a view inside a menu item. The button submits the string in the text field to a function, and that works fine. However, I've also set the button's key equivalent to "return." The key command isn't being picked up, probably because the menu is not the "key" window. I know how to make a window th...

Adding item to NSMenu with action selector preset

I'm new to Obj-C/Cocoa programming, and I'm having an issue trying to dynamically add menu items to an NSMenu instance and have the items action selector already set upon insertion. I can, add the dynamic menu items fine, but the action selector doesn't trigger when the item is clicked via the menu. The first line below is the line of ...

Can't populate NSMenu from document controller

Hi all, I've a MainMenu.xib and a MyDocument.xib. I need to dynamically populate some NSMenuItem's from my document controller but I'm at a loss on how to get to it from MainMenu.xib. I've tried adding an NSObject to MainMenu.xib and make it an instance of my document controller but I can't populate the NSMenuItem's from the NSArrayCon...

Disabling/enabling an application menu item

In trying to learn the very fundamentals of menu handling. My test app's menubar has 3 menus -- namely "TestApp", "File" and "Help". I find I can remove these menus entirely, simply by calling say: NSMenu* rootMenu = [NSApp mainMenu]; [rootMenu removeItemAtIndex:2]; However, I'd only ever want to temporarily disable them (gray them ou...

Looking for popUpMenuPositioningItem:atLocation:inView: equivalent for 10.5

I'm working on an application that needs to display a context menu on screen in various scenarios. In the function I'm writing, I don't have access to any NSWindows or NSViews. I'd like to use popUpMenuPositioningItem:atLocation:inView as this function works perfectly for me in 10.6. However, we have a requirement to support 10.5, so thi...

Force NSMenu (nested submenu) update for Main Menu of Cocoa App

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 run...

How to add multiple menu items with the same title to NSPopUpButton(NSMenu)?

As docs say it's impossible to add two menu items to NSPopUpButton if they both have the same title. I was trying to add menu items to [popupButton menu], but with no luck. I was also trying to create a new menu, add items to it and then use [popupButton setMenu:newMenu], but no. Menu always display only one item per name. But I know it...

How to make an NSMenu recent list

I'm working on a small URL shortening application for someone, and I need to have a list, similar to that of Droplr's, that has all of the recently shortened URLs. The list should be a submenu of the main menu, which is attached to an NSStatusItem. I need to have that list add an item each time a URL is shortened, and I'd like to have a...

How do I get a textbox in an NSMenu?

I'm pretty sure i've seen this somewhere (not counting the help menu), and I feel like you could just drag one in under ib in leopard. Not that it matters, but it will either go into a dock menu or a service. Thanks ...

NSMenuItem not responding to setIndentationLevel:

If I call setIndentationLevel: on an NSMenuItem then nothing happens, if I call indentationLevel on it after I set it to 3, it returns 3 like it should. I'm adding the menu items to the Dock menu and I don't see anything changing. NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle: @"title" action: nil keyEquivalent: @""]; [menuIt...

Cocoa AppKit - Dismissing a modal window (i.e. popup or contextual menu) and pressing the button currently hovered above

Basically I want to create the effect of that provided in the system's menu bar. A user presses on one of the menu headings, and as he moves across the different headings, the menus open up automatically. The snag is that if I open a pop-up menu for a button, the user has to click again to dismiss it. The entire runloop is on hold as I ...