Obtain the NSToolbar look of Finder's preferences window - cocoa

I am building a preferences window for my app and would like to achieve the same "look" as the NSToolbar that Finder uses. When selected, the toolbar buttons in Finder look "pushed in". On the right-hand side of the image is my preferences window - you'll notice that even though General is selected it does not look "pushed in". How do I achieve the look of Finder (and most other built-in apps)?
Thank you,
CS

When you build the toolbar in Xcode you add toolbar items to it. Each toolbar item can be customized in the right pane of Xcode. Choose "Selectable" as behaviour and it works as you expect.

Related

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 & Symbols" under Edit menu were existing as well as the "Enter Full Screen" menu item under the View Menu. But when it comes to Window Menu nothing was automatically generated, only the menu items I've set in the code. Do I have to enable some flags or options when instantiating a Window NSMenu so it automatically generates those items? I am new to macOS development so I feel like I am kind of lost. Thanks in advance.
The Window and Help menus are a little special in that they have their own NSApplication properties, so you will need to set them to your menus so that the system will know what they are.
For example, if you just create a window menu and add it to the main, all you will get are the items that you have provided. If you also set it as the application’s windowsMenu, in addition you will get all the stuff for moving, tab support, etc.
Setting NSApp’s helpMenu is similar, where a Spotlight menu item is added to the menu.

Adding a menu-bar to the app's window

I've been asked to add a menu bar to our ARC app's chrome window. So, two questions:
Is this possible?
If so, how would one define and interact with it?
To clarify, this would be similar to the drop-down menu that the usual Chrome window has in the top-right corner but it would contain custom entries.
No there's no way to add a menu button in the top bar. The functionality you're describing sounds similar to an action bar, which is the preferred way in Android to add a menu in the app (as an overflow list), since navigation bar menu keys are being phased out: http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html

How can I get to the menu bar in my app in interface builder

XCode works in mysterious ways (at least to me).
I simply want to create a Preference pane in my app. When I run my app, the stock menu bar comes up (Apple, MyApp, File, Edit...) and the "Preferences" menu item is grayed out. It makes sense since I haven't started playing with it.
How on earth do I add/remove/activate/inactivate menu items? I'm not talking about adding anything new, simply using what should be there.
Thanks in advance.
NSMenu has "Auto Enable Items" enabled by default. That means if the menu item does not have it's action message hooked up, it will appear grayed out. So in your case, you would simply set the Preferences menu item's "Sent Action" to whatever action shows your preferences window. This can be hooked to some sort of showPreferencesWindow: method of your AppDelegate, or directly to the showWindow: method of a window controller.
To dynamically enable/disable menu items the best way is to implement the NSUserInterfaceItemValidation protocol which is excellently documented here
Edit: Your app's menu bar items live in the MainMenu.xib file. The menu bar appears as a "Main Menu" object on the left hand side (if you're using Xcode 4) Simply click on the items to modify them, and you can Ctrl+drag connections to and from them like any UI object.

Add a "Build and Analyze" button to XCode's toolbar

Is there a way to add a "Build & Analyze" icon to XCode's toolbar? If not, is there at least a way to assign a keyboard shortcut to this option?
Looks like no on the toolbar item. To see the customization options for a toolbar control-click it (or right click it if you have a two button mouse).
You can assign a keyboard shortcut to any menu item in Mac OS X via System Preferences. See http://docs.info.apple.com/article.html?path=Mac/10.5/en/8564.html
Xcode also has its own keybindings interface, which you can find in Xcode preferences.

how do you display an NSMenu programmatically?

I wrote a little app that lives in the NSStatusBar. I want to have a global shortcut that when hit, the menu bar's content is displayed, exactly like the behavior of spotlight.
I have added a global key shortcut to my application, but I am unable to get the meun bar to display. How can I do this? I tried with "popUpContextMenu" , but that method displays the menu in the bottom left hand corner, I want the menu to open up right under the NSStatusBar menu icon.
You can do it, apple provides a method for it popUpStatusItemMenu:
I don't think there is a supported way to do this without perhaps using the Accessibility framework to simulate a click on your status item. Regardless, it's probably not a good idea to abuse a menu in this way.
The Spotlight menu bar item does not use an NSMenu, it uses a custom window/view. You might consider going this route if you have some sort of custom view to display.

Resources