nsmenu

Remove (or customize) 'Search' from help menu

左心房为你撑大大i 提交于 2019-12-04 09:21:46
My app has the default 'Help' menu. I have removed the 'Help' entry and added a Support entry that links to a forum on my website. The help menu nib looks like this: But once I have the app up and running a new menu item has been suck in: How can I make the search go away? (Or even better, how could I make it launch a url with params such as http://mywebsite.com/support?search=XXXXX ). You're looking for NSUserInterfaceItemSearching protocol. Return a single search result item and use it to open your custom URL. - (void)searchForItemsWithSearchString:(NSString *)searchString resultLimit:

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

How do I disable the Show Tab Bar menu option in Sierra apps?

吃可爱长大的小学妹 提交于 2019-12-03 23:47:58
I've got an app that uses a Toolbar in a NSWindow. I don't want users to be able to customize this toolbar for aesthetic reasons. In Sierra there's a new Menu option that gets inserted into "Menu > View" called Show Tab Bar . How do I disable this? Enabling it only seems to increase the tool bar's height as I don't have extra labels showing under the icons. You can also do this on IB, on the Window’s attributes inspector On 10.12, you need to now set the following when the window is created as Tab Bar is now available by default: [NSWindow setAllowsAutomaticWindowTabbing: NO]; If you don't

Custom NSMenu like view not displaying selectedMenuItemColor correctly

╄→гoц情女王★ 提交于 2019-12-03 17:36:52
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) drawRect:(NSRect)dirtyRect { CGRect b = self.bounds; if (selected) { [NSGraphicsContext saveGraphicsState]

How Can I Show NSMenu at Mouse Cursor?

不想你离开。 提交于 2019-12-03 17:00:28
I am working on an app where I want to show an NSMenu "context menu" next to the current mouse location. At this point, I know how to trigger the command from the WebView to show the context menu, I just can't seem to get the menu to show up at the correct placement on the screen. It seems like my coordinates are inverted vertically from what I need. This seems like such a simple problem, but I have spent a good bit of time trying to best a "best practices" solution. Do I need to figure out which screen the mouse is in and calculate the y coordinate manually? Here is my really simple code that

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

Hiding the dock icon without hiding the menu bar

烈酒焚心 提交于 2019-12-03 09:09:53
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, kProcessTransformToForegroundApplication); SetSystemUIMode(kUIModeNormal, 0); [[NSWorkspace sharedWorkspace]

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

Main Thread Runloop gets blocked on opening nsmenu

房东的猫 提交于 2019-12-01 23:46:59
I have an application for which the UI element includes an NSStatusItem and a menu. Inside my application , I am using NSTask asynchronously to perform some operation and I am using the output obtained using the NSFileHandleReadCompletionNotification to update the menu. But now whenever I click and open the menu , the main runloop goes into NSEventTrackingRunLoopMode and the notification posting fails. So basically with my menu open , no operation takes place on the main thread. Now I found a similar problem on this post but the accepted solution there does not seem to help. I understand that