nsmenuitem

Getting NSMenuItem of NSMenu tree by title

≡放荡痞女 提交于 2019-12-06 12:04:33
问题 I have an NSMenu (let's say the Main Menu), with lots of NSMenu s in it, and NSMenuItem s at different levels. I want to be able to get the NSMenuItem instance specifying the tree path (with the title of the corresponding NSMenus/NSMenuItems in it). Example : Menu : File New Open Document Project Save Save As... Path : /File/Open/Document How would you go about it, in the most efficient and Cocoa-friendly way? 回答1: I think that best way would be to obtain the NSMenuItem by specifying its

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

风流意气都作罢 提交于 2019-12-06 03:54:14
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. Maybe you should try it this way: #define menuItem ([self enclosingMenuItem]) - (void) drawRect: (NSRect) rect { BOOL isHighlighted = [menuItem isHighlighted]; if (isHighlighted) { [[NSColor

Cannot seem to setEnabled:NO on NSMenuItem

廉价感情. 提交于 2019-12-05 09:53:49
问题 I have subclassed NSMenu and connected a bunch of NSMenuItem 's via Interface Builder. I have tested via the debugger to see that they really get initialized. The menu is set to not auto enable items. Still when I set any of my NSMenuItem's to [myMenuItem setEnabled:NO] they continue to be enabled. Even if I call [self update] from within the NSMenu subclass. What am I missing? 回答1: Had the same issue, so I thought I'd post my solution. NSMenu auto enables NSMenuButtons, so we have to

Exactly matching the background of a selected NSMenuItem

帅比萌擦擦* 提交于 2019-12-05 08:54:34
问题 I am creating a custom view for an NSMenuItem . In order to draw the background when selected, I adapted a couple of lines from the CustomMenus sample. The CustomMenus sample has: [[NSColor alternateSelectedControlColor] set]; NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); .. and I am using the selectedMenuItemColor because the alternateSelectedControlColor was a solid color and it did not look very good: [[NSColor selectedMenuItemColor] set]; NSRectFillUsingOperation(dirtyRect,

How to set the font of NSMenu/NSMenuItems?

折月煮酒 提交于 2019-12-05 08:41:29
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. They can have an attributed title, so you can set an attributed string as title with all it's attributed, font included: NSMutableAttributedString* str =[[NSMutableAttributedString alloc]initWithString: @"Title"]; [str setAttributes: @{

How to add icons to the right hand side of NSMenuItem

情到浓时终转凉″ 提交于 2019-12-05 04:00:27
I'm trying to add some icons to the right hand side of a menu next to a menu item, ideally all right justified. I'm aware that NSMenuItem allows you to add menu items (for instance, see the MenuMadness example). I'm really looking for something like the security / signal strength indicators in the OS X Wifi menu. One approach that I've seen is to add items to the menu, and use setView to provide an NSView for each item. However, that seems to be more complicated than it should be. Is there a way to just add an icon / multiple icons to the menu? On the left side of the menu, it's easy, and even

How to draw an inline style label (or button) inside NSMenuItem

旧时模样 提交于 2019-12-05 01:29:34
问题 When App Store has updates, it shows an inline style element in the menu item, like '1 new' in the screenshot below: Another place we can see this kind of menu is 10.10 Yosemite's share menu. When you install any app that adds a new share extension, the 'More' item from the share menu will show 'N new' just as the app store menu. The 'App Store...' item looks to be a normal NSMenuItem . Is there an easy way to implement this or are there any APIs supporting it without setting up a custom view

Connecting Multiple NSMenuItems with Actions and State Variables

天涯浪子 提交于 2019-12-04 19:06:46
I'm not sure how to describe what I need but I'll give it a try, via an example : Let's say we have a window and a sidebar, and want to toggle it (I mean the sidebar : on/off). Now, let's also say that : The user may toggle the sidebar via an item at the Main menu (e.g. Show Sidebar / Hide Sidebar) The user may also toggle the sidebar via a button And there is also another item, in some other menu, to do the very same thing (Show/Hide Sidebar) What would be the most practical Cocoa-friendly approach to achieve that? Of course, that means that, e.g. : When somebody clicks the button, apart from

Getting NSMenuItem of NSMenu tree by title

我与影子孤独终老i 提交于 2019-12-04 16:07:34
I have an NSMenu (let's say the Main Menu), with lots of NSMenu s in it, and NSMenuItem s at different levels. I want to be able to get the NSMenuItem instance specifying the tree path (with the title of the corresponding NSMenus/NSMenuItems in it). Example : Menu : File New Open Document Project Save Save As... Path : /File/Open/Document How would you go about it, in the most efficient and Cocoa-friendly way? I think that best way would be to obtain the NSMenuItem by specifying its title or, better, a custom defined tag. #define kMenuFileNew 1 #define kMenuFileOpen 2 NSMenu *menu = [[NSMenu

Cannot seem to setEnabled:NO on NSMenuItem

笑着哭i 提交于 2019-12-04 00:12:01
I have subclassed NSMenu and connected a bunch of NSMenuItem 's via Interface Builder. I have tested via the debugger to see that they really get initialized. The menu is set to not auto enable items. Still when I set any of my NSMenuItem's to [myMenuItem setEnabled:NO] they continue to be enabled. Even if I call [self update] from within the NSMenu subclass. What am I missing? Had the same issue, so I thought I'd post my solution. NSMenu auto enables NSMenuButtons, so we have to override that. In IB: Or programmatically: // Disable auto enable [myMenu setAutoenablesItems:NO]; // Test it