nsmenuitem

menu item is enabled, but still grayed out

北城余情 提交于 2020-04-08 02:50:27
问题 I have a menu with several items created in interface builder. It looks fine there and 'enabled' is checked. But when I run application, all menu items are grayed out. I've checked isEnabled , it returns true. Also, menu items created programmatically (with initWithTitle and without interface builder) work just fine. Am I missing something here? I'm really quite new to OSX development (in fact, this is my first day). Thank you 回答1: Remember to set your menu item's target and ensure that said

menu item is enabled, but still grayed out

断了今生、忘了曾经 提交于 2020-04-08 02:49:00
问题 I have a menu with several items created in interface builder. It looks fine there and 'enabled' is checked. But when I run application, all menu items are grayed out. I've checked isEnabled , it returns true. Also, menu items created programmatically (with initWithTitle and without interface builder) work just fine. Am I missing something here? I'm really quite new to OSX development (in fact, this is my first day). Thank you 回答1: Remember to set your menu item's target and ensure that said

Highlighting a NSMenuItem with a custom view?

早过忘川 提交于 2020-01-22 05:33:19
问题 I have created a simple NSStatusBar with a NSMenu set as the menu. I have also added a few NSMenuItems to this menu, which work fine (including selectors and highlighting) but as soon as I add a custom view (setView:) no highlighting occurs. CustomMenuItem *menuItem = [[CustomMenuItem alloc] initWithTitle:@"" action:@selector(openPreferences:) keyEquivalent:@""]; [menuItem foo]; [menuItem setTarget:self]; [statusMenu insertItem:menuItem atIndex:0]; [menuItem release]; And my foo method is: -

How to set the font of NSMenu/NSMenuItems?

末鹿安然 提交于 2020-01-13 10:47:10
问题 I can’t figure out how to set the font/styling of my NSMenuItems in my NSMenu. I tried the setFont method on the NSMenu but it doesn’t seem to have any effect on the menu items. NSMenuItem doesn’t seem to have a setFont method. I would like for them all to have the same font/style so I would hope there’s just one property I can set somewhere. 回答1: They can have an attributed title, so you can set an attributed string as title with all it's attributed, font included: NSMutableAttributedString*

User assigned key equivalents

烂漫一生 提交于 2020-01-05 07:49:29
问题 I'm working on a Status Bar App. I'd like to allow the user to modify the menu item key equivalents to their own preferences. I've seen this done before it's a pretty common feature. A prefs window usually has an area with textfields where the user enters their keyboard shortcut for specific menu items. How does one setup the textfield so that it displays the modifier key fonts? The default NSTextfield ignores modifiers. Also I have yet to find an example project showing this functionality,

Getting a particular menu item from MainMenu

时光怂恿深爱的人放手 提交于 2019-12-24 02:42:45
问题 I have a nib (winA.xib) that contains a window. My app delegate contains an NSWindowController subclass called WinAController. WinAController has a property (NSMenu *mainMenu) that I want to point to the MainMenu. I have set it after I instantiate WinAController with this code: WinAController = [[WinAController alloc] initWithWindowNibName:@"WinA"]; WinAController.mainMenu = [NSApp mainMenu]; I have a menu item underneath the "Window" top-level menu item on MainMenu that invokes the

When to remove dynamic NSMenuItem's from an NSMenu

北城以北 提交于 2019-12-24 00:59:49
问题 I have an NSMenu which contains a number of dynamic items. These items are created in NSMenuDelegate's menuNeedsUpdate method and are each assigned a representedObject. I'm looking to trim the object graph and hopefully regain a bit of memory when the menu is closed by removing all dynamic items (and having them recreated when the menu is re-opened). The issue I'm having is knowing exactly where and how this should be handled. The documentation states that NSMenu's menuDidClose is not a

An NSMenuItem's view (instance of an NSView subclass) isn't highlighting on hover

爱⌒轻易说出口 提交于 2019-12-22 09:53:16
问题 I need to use a custom NSView subclass to draw some content, but it isn't drawing as highlighted when the user hovers and it doesn't dismiss the NSMenu when the user clicks on it. Any ideas? Edit So using -drawRect: and [[self enclosingMenuItem] isHighlighted] I'm able to tell whether or not I need to draw the view as highlighted and am given the chance to do so. All I have to figure out is how to do that. 回答1: Maybe you should try it this way: #define menuItem ([self enclosingMenuItem]) -

NSToolbarItem validation in relevant controller

折月煮酒 提交于 2019-12-22 05:42:07
问题 I have an NSToolbarItem with an NSButton as its view and an NSMenuItem in the main menu. Both have the same action, which is sent to the first responder, not to a particular target. That method is ultimately implemented in a subclass of NSSplitViewController, somewhere in the view hierarchy of the window’s content view. I want to validate both items, but have that specific split-view controller take care of the validation, because it relies on some conditions local to that controller. I

Weird issue with NSMenuItem, custom view and mouseUp:

廉价感情. 提交于 2019-12-21 11:35:12
问题 I'm having a very very strange issue here with a NSMenu. About half the NSMenuItems I use have custom views on them through the setView: method on NSMenuItem. In this custom view I've implemented mouseUp: to catch when the user clicks on the menu item, and this works perfectly the first time I open the menu. The second time though, the mouseUp doesn't get called on any of these menu items if I hold the mouse steady when clicking. However, if I click down, then move the cursor ever so slightly