nsmenu

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

How to place Horizontal Slider in NSMenu (Swift 3, Xcode 8)

ぃ、小莉子 提交于 2019-12-05 23:55:08
As of macOS Sierra the volume menu bar item provides a horizontal slider item to change the system's volume: I'd like to adopt this concept for my own application and came up with the following class: import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { @IBOutlet weak var window: NSWindow! let statusItem = NSStatusBar.system().statusItem(withLength: -2) func applicationDidFinishLaunching(_ aNotification: Notification) { let menu = NSMenu() let menuItem = NSMenuItem() let statusSlider = NSSlider() menu.addItem(NSMenuItem(title: "Slider:", action: nil,

NSTextfield + NSMenu and first responder

做~自己de王妃 提交于 2019-12-05 11:00:24
I'm trying to implement my own autocomplemention system (result is pull from an sqlite database) I've set up a NSTextField and the appropriate delegate. Each time the text in the NSTextField change, it call - (void)controlTextDidChange:(NSNotification *)aNotification method It work fine, in this method I build a menu programtically and finally I call/show it with that code: NSRect frame = [address frame]; NSPoint menuOrigin = [[address superview] convertPoint:NSMakePoint(frame.origin.x, frame.origin.y+frame.size.height-25) toView:nil]; NSEvent *event = [NSEvent mouseEventWithType

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

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: @{

Custom NSMenu like view not displaying selectedMenuItemColor correctly

懵懂的女人 提交于 2019-12-05 02:05:16
问题 I wrote my own NSMenu like class to show dynamic search results below a NSSearchField in a borderless NSWindow. It's working well but doesn't draw the magic selectedMenuItemColor correctly if I add some padding to the top of the subview. I put a 5 pixel padding at the top of container view to mimic NSMenu and when I do it blue selected gradient looks off. A picture & code should make this clear: Here is my drawRect code inside my item view (remember this is just a regular NSView): -(void)

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

No callback when clicking menu item

删除回忆录丶 提交于 2019-12-04 19:20:29
I'm trying to implement a simple context menu in my FinderSync extension. I built the following using some examples, and my problem is that the callback is never called when I click the menu item. Source code: ContextMenuHelper.h #import <Foundation/Foundation.h> #include "FinderSync.h" @interface ContextMenuHelper : NSObject + (NSMenu *)buildMenu; @end ContextMenuHelper.m #import "ContextMenuHelper.h" #define SharedContextMenuTarget [ContextMenuTarget sharedInstance] @interface ContextMenuTarget : NSObject + (ContextMenuTarget *) sharedInstance; @end @implementation ContextMenuTarget - (void)

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

Hiding the dock icon without hiding the menu bar

醉酒当歌 提交于 2019-12-04 16:01:19
问题 I use the ideas in this thread to hide the dock icon of my app optionally . If the dock icon is shown after all, the menu bar should be shown too. Only with Jiulong's answer I haven't been able to make this work. The menu bar is still hidden. So basically 'Application is agent' is set to '1' in the InfoPList, and this code is used : if (![[NSUserDefaults standardUserDefaults] boolForKey:@"LaunchAsAgentApp"]) { ProcessSerialNumber psn = { 0, kCurrentProcess }; TransformProcessType(&psn,