nsmenuitem

Exactly matching the background of a selected NSMenuItem

大憨熊 提交于 2019-12-03 21:58:40
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, NSCompositeSourceOver); Using selectedMenuItemColor is better, but it's still not exactly the same as a

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

夙愿已清 提交于 2019-12-03 16:36:16
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 for the menu item? "Cocoa" NSMenus are actually built entirely on Carbon, so while the Cocoa APIs don

Creating NSMenu with NSMenuItems in it, programmatically?

六眼飞鱼酱① 提交于 2019-12-03 11:40:28
问题 First, I'd like to point out that this question is probably already asked, I just couldn't find any answers from them. So, I'm programmatically trying to create a NSMenu and NSMenuItem to the main bar, so fe. NSMenu would be File and then it would have 3x NSMenuItem in it, New, Open and Save. But nothing's working, here's what I have currently: NSMenu *fileMenu = [[NSMenu alloc] initWithTitle:@"File"]; NSMenuItem *newMenu = [[NSMenuItem alloc] initWithTitle:@"New" action:NULL keyEquivalent:@"

Custom NSView in NSMenuItem not receiving mouse events

落花浮王杯 提交于 2019-12-03 03:22:18
I have an NSMenu popping out of an NSStatusItem using popUpStatusItemMenu. These NSMenuItems show a bunch of different links, and each one is connected with setAction: to the openLink: method of a target. This arrangement has been working fine for a long time. The user chooses a link from the menu and the openLink: method then deals with it. Unfortunately, I recently decided to experiment with using NSMenuItem's setView: method to provide a nicer/slicker interface. Basically, I just stopped setting the title, created the NSMenuItem, and then used setView: to display a custom view. This works

How do I set the sender on a NSMenuItem's action?

时光毁灭记忆、已成空白 提交于 2019-12-02 22:20:39
The Apple documentation says that the sender passed to the NSMenuItem's action can be set to some custom object, but I can't seem to figure out how to do this. Is there a method I'm not seeing someplace in the documentation? I'm not sure what piece of documentation you're referring to (a link would help). You can use the -setRepresentedObject: method of NSMenuItem to associate an arbitrary object with a menu item: //assume "item" is an NSMenuItem object: NSString* someObj = @"Some Arbitrary Object"; [item setRepresentedObject:someObj]; [item setAction:@selector(doSomething:)]; Then when the

Searching NSMenuItem inside NSMenu recursively

淺唱寂寞╮ 提交于 2019-12-02 07:51:00
问题 The method itemWithTitle locates a menu item within a NSMenu . However it looks only inside the first level. I cannot find a ready-to-use method that will do the same job recursively by searching inside all the nested submenus. Or, somehow equivalently, a function that swipes NSmenu 's recursively. It looks quite incredible to me that such a thing would not exist. Maybe there is some function not directly related to NSMenu that can come in handy? 回答1: Ok, since I really need to do this clumsy

NSMenuItem and NSPopOver

时间秒杀一切 提交于 2019-11-30 23:42:44
On OS X app, what is the technique to show a NSPopover when the mouse is over a NSMenuItem (like in spotlight for example). Thanks a lot!!! Christopjhe I know it's been a while, but if you still haven't found a solution: Register your class as a NSMenuDelegate to the menu that contains the NSMenuItem , and implement - (void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item; then show the popover when this method is called. Can you show your code in the question? It would make it easier to help you. But without knowing what your code looks like, this might work for you: Add this to your

How to update NSMenu while it's open?

ぐ巨炮叔叔 提交于 2019-11-30 20:43:13
I have a NSMenu with dynamically added NSMenuItems. The NSMenu is not refreshing properly while it's kept open. I am calling NSMenu update method in NSEventTrackingRunLoopModes . I have implemented following methods to update NSMenu. - (void)menuNeedsUpdate:(NSMenu *)menu { for (NSInteger index = 0; index < count; index++) [self menu:menu updateItem:[menu itemAtIndex:index] atIndex:index shouldCancel:NO]; } - (BOOL)menu:(NSMenu *)menu updateItem:(NSMenuItem *)item atIndex:(NSInteger)index shouldCancel:(BOOL)shouldCancel` - (NSInteger)numberOfItemsInMenu:(NSMenu *)menu I am dynamically

NSMenuItem and NSPopOver

安稳与你 提交于 2019-11-30 18:02:23
问题 On OS X app, what is the technique to show a NSPopover when the mouse is over a NSMenuItem (like in spotlight for example). Thanks a lot!!! Christopjhe 回答1: I know it's been a while, but if you still haven't found a solution: Register your class as a NSMenuDelegate to the menu that contains the NSMenuItem , and implement - (void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item; then show the popover when this method is called. 回答2: Can you show your code in the question? It would make

How to update NSMenu while it's open?

一个人想着一个人 提交于 2019-11-30 05:45:54
问题 I have a NSMenu with dynamically added NSMenuItems. The NSMenu is not refreshing properly while it's kept open. I am calling NSMenu update method in NSEventTrackingRunLoopModes . I have implemented following methods to update NSMenu. - (void)menuNeedsUpdate:(NSMenu *)menu { for (NSInteger index = 0; index < count; index++) [self menu:menu updateItem:[menu itemAtIndex:index] atIndex:index shouldCancel:NO]; } - (BOOL)menu:(NSMenu *)menu updateItem:(NSMenuItem *)item atIndex:(NSInteger)index