Questions tagged [nsmenuitem]

The NSMenuItem class from AppKit.framework in Mac OS, defines objects that are used as command items in menus.

The NSMenuItem class defines objects that are used as command items in menus. Additionally, the NSMenuItem class also includes some private functionality needed to maintain binary compatibility with other components of Cocoa. Because of this fact, you cannot replace the NSMenuItem class with a different class. You may, however, subclass NSMenuItem if necessary.

Prior to Mac OS X v10.5, NSMenuItem conformed to the following protocols: NSCopying, NSCoding), and NSValidatedUserInterfaceItem.

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSMenuItem_Class/Reference/Reference.html

331 questions
5
votes
1 answer

Adding static items to "Windows" menu in Cocoa application

I have a application with 2 windows (think like Twitter Timeline and mentions). For now I have been having the menus "Timeline ⌘1" and "Mentions ⌘2" in the "File" menu but this is kind of wrong. So I moved them to the "Windows" menu just by drag and…
Jeena
  • 2,172
  • 3
  • 27
  • 46
5
votes
1 answer

cocoa NSMenu add NSMenuItem in position

I'm trying to create an NSMenu in my application. I succesfully create the menu, with some fixed items, and now I have to add some items programmatically. I succeed also in that, but it adds the item at the bottom of the others. There's a way to put…
phcaze
  • 1,707
  • 5
  • 27
  • 58
4
votes
2 answers

NSMenuItem and NSPopOver

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
4
votes
1 answer

Changing visibility of NSPopUpButton's items based on keypress

I've got an application here that needs to read in a bunch of data from an external file and display it as a NSPopUpButton in a Cocoa user interface. The catch here is that the data that is being read in needs to have a flag that states if it is…
user1004332
4
votes
1 answer

Creating dynamic count of NSMenuItems

I'm currently struggling with dynamic UI in Mac OS X. I created a Menu Bar item and want to add a dynamic count of MenuItems within it. The count of the elements depends on Network interfaces on the computer. My Mac got two Interfaces, another got…
Julian F. Weinert
  • 7,474
  • 7
  • 59
  • 107
4
votes
3 answers

How to hide a NSMenuItem?

I'm currently writing a Mac App in Objective-C and can't for the life of me figure out how to hide a NSMenuItem. (Note: Yes I really mean hide, not disable/grey-out. I realize the UX implications of doing so, but the functionality isn't really what…
John Moss
  • 43
  • 3
4
votes
1 answer

How to keep focus on NSStatusItem until toggling it again

I'm building an app the uses a NSStatusItem. I'm wanting my NSStatusItem to open when clicked and stay open until the user clicks the NSStatusItem again. As of right now, it opens the menu but the NSStatusItem loses focus when I click away from it…
0SX
  • 1,252
  • 6
  • 24
  • 47
4
votes
1 answer

How to enable auto generation of Window MenuItems (e.g. Tile Window to Left/Right of Screen and Open file with checkmark) in macOS menubar

I am currently creating a macOS menubar for an app without using any interface builder (no XIB/NIB files), just pure code. However I was expecting some items to be auto-generated during the start-up of the app. Items like "Start Dictation", "Emoji &…
ujin
  • 41
  • 1
4
votes
1 answer

Fake NSWindow with a NSView inside a NSMenuItem

Before I start I should say I know this seems like a long shot, however I figured it was worth a try. One app I am working on right now is a Mac Statusbar App. It has a NSStatusItem in the menubar and when clicked it will display a custom window…
Colin Wheeler
  • 3,343
  • 2
  • 21
  • 23
4
votes
4 answers

Remove highlight from NSMenuItem after click?

I have added a custom view to my subclass of NSMenuItem (which sits in a NSStatusMenu), which means that by default it will not get "highlighted" with a blue/gray background. I implemented this by using the following code: -…
rdougan
  • 7,217
  • 2
  • 34
  • 63
4
votes
1 answer

macOS SwiftUI: MenuItem to open default browser to a URL?

I've been trying to make a MenuItem in my macOS SwiftUI app to open a default browser to a specific URL. Since I already had a MenuItem open up a PDF, I tried to modify this: @IBAction func Guide1(_ sender: Any) { if let pdfURL =…
esaruoho
  • 896
  • 1
  • 7
  • 25
4
votes
4 answers

How do you hide a Menu Item with a custom view?

I am using a very simple custom view (containing only a read-only NSTextField and an NSSegmentedControl) in an NSMenuItem (using the -setView: method). This part works as expected. Here's the problem: in the -menuNeedsUpdate: NSMenu delegate method…
Dov
  • 15,530
  • 13
  • 76
  • 177
4
votes
1 answer

Access Menu Item to Disable/Enable

I would like to implement NSMenuItemto trigger certain functionality (e.g. "Run Calculation"). How do I access the menu items in order to enable/disable the items based on the app logic? E.g. the "cut" function for text is only enable as menu item…
JFS
  • 2,992
  • 3
  • 37
  • 48
4
votes
1 answer

NSMenuItem custom view does not respond to keyEquivalent

I've set a custom NSView to a NSMenuItem to do my own drawing and rendering. However the 'keyEquivalent' assigned to the NSMenuItem does not seem to respond. I understand drawing and action handling needs to be self-handled but I can't seem to be…
strange
  • 9,654
  • 6
  • 33
  • 47
4
votes
1 answer

Main menu NSMenuItem key equivalent not working until menu has been viewed

I have a list of user-configurable things that show in a main menu submenu. The first 9 items get the shortcuts ⌘1--⌘9 assigned: let item = theMenu.addItem( withTitle: title, action: #selector(itemSelected(_:)), keyEquivalent:…
ctietze
  • 2,805
  • 25
  • 46