How do you create NSMenuItem similar to Dropbox's menu dropdown? - objective-c

Dropbox has a wonderful new dropdown view for their menubar app. I have failed to find similiar cocoa examples to duplicate this type of view. NSMenuItem seems to be for basic lists. Any pointers in the right direction?

It's not a NSMenuItem. It is a NSStatusItem that resides in the systemwide NSStatusBar. The distinction is important, because NSStatusItems can call just about any method on any given object of your application when they're clicked.
I suspect that their NSStatusItem triggers an action that displays a borderless window.
You can find more information about status items in the Status Bar Programming Topics document.

Related

Cocoa Finder app List view

Being a starter in Cocoa Programming, I would like to know using the existing NSTableView can one be able to achieve Disclosure Button? Or one has to follow NSOutlineview?
From the above picture, on selecting the list view and getting a Folder[Super view] and getting the children using a Disclosure button
Also can a registered Mac Developer get Finder app's sample code?
Thanks
NSOutlineView is just a subclass of NSTableView, so yes just use NSOutlineView to use the disclosure button.
Check out the docs for how to use it.
And no, Apple never released the source code for Finder.

Clicking on an image in a collection view

I have a collection view and each item has an image and a label. I want to click the NSCollectionViewItem or NSImage and then hide the collection view and display a completely separate view containing the details of the object that was clicked.
I cant find any documentation on how to handle click events in this situation. How is this possible? I have built out the collection view in Interface Builder so everything was done via bindings as opposed to code.
#Jeff, I don't have permissions to add a comment so writing this as answer.
You can overwrite setSelection in your subclass of NSCollectionViewItem (as explained by #indragie in Selection Highlight in NSCollectionView) to track the selected item and perform an action.
The solution that I went with was to not actually use an Image Well, aka NSImage. I used a button and bound the Image property to an instance of an NSImage that I exposed as a property on my model.
It was easy enough but I'm shocked more people havent been asking this question.

Custom NSMenu design

Tough question. I'm looking for examples to create a custom NSMenuItem design. I want to achieve something like http://anvilformac.com/. Are there any examples out there that could put me in the right direction? Or at least a tutorial?
Apple has a section of their menu programming guide dedicated to this, and the related sample code provides a full working implementation of a custom menu view.
Drag a Custom View into your xib. Right click first Menu item and drag from the view property to the Custom View.

Custom NSMenu item

how can i go about making a custom NSMenu for a menulet such as this?
Is this an NSMenu or is it a borderless window and if so how would i go about this?
Thanks!
It's an app running running on the OSX status bar.
See Status Bar Programming at Apple. Also, NSStatusBar and NSStatusItem
This SO post has some additional pointers:
How to create a Menubar application for Mac
More specifically it could be an NSPopover, an NSWindow, or even NSStatusItem.view's custom view. In the case of an NSWindow (often a utility form of NSPanel) (or the NSPopover) you would manually open the window when the status item is clicked, using the status item's -(void)setAction and -(void)setTarget. If you use a custom view for the status item, this would be done in -mouseDown:.
Check out this post - I found it useful.
Look at the documentation for NSStatusItem. I believe you can have it display a view instead of a standard NSMenu which is what it looks like they are doing in that image.

Creating Cocoa PopUpMenus programmatically and Getting code form a GUI item built with the interface builder

I need to create many Cocoa items programmatically and most resources I can find focus on creating GUI with the builder. Is there any way to get the objective C code for an interface item created using the interface builder in Xcode? Also, I am a little confused about PopUpMenus. Are PopUpMenus contained inside PopUpButtons or are the independent? Also, can anyone link me to a good description of how to create PopUpMenus programmatically Using Cocoa and Objective-C?
It depends on what you mean by "PopUpMenus". In Cocoa a menu is a menu, specifically an instance of NSMenu. NSPopupButtons have an associated NSMenu object which you can assign to the button using the -setMenu: method.
You can certainly construct menus programmatically using the NSMenu and NSMenuItem classes. Take a look at the various -addMenuItem: methods in the NSMenu documentation.
You can also access the components of a menu created in Interface Builder programmatically if you have a reference to the menu, specifically an outlet instance variable that is connected to the menu in Interface Builder.
If you're referring to contextual menus that appear when you click the right mouse button, all you need to do is connect your menu to the view/control you want to attach it to with the -setMenu: method. You can make this connection in Interface Builder also.