Opening New Window using Menu Tab cocoa application - cocoa

I am new to Mac os x and am having some difficulties with the the transition from windows and widgets. In my MainMenu.xib, I have the main window of my app, call it window A, and I added a menu tab to the main menu tabs as well as a new window B to the MainMenu.xib. When I launch my app, I want window A to open (which it does) and then when the user clicks the new menu tab, I want window B to appear. Is there an easy to way to connect the menu tab to window B in the IB so that it opens when the menu tab is clicked?
Thanks for your help

What are main menu tabs?
To show Window B call [myWindowB makeKeyAndOrderFront:sender].

For window B , uncheck visible at lunch from interface builder(window attribute). when the user clicks the new menu tab.
[WindowA orderOut:sender];
[WindowB makeKeyAndOrderFront:sender];
write this code.

Related

VoiceOver focus does not move with keyboard focus while navigating through Mac app menu items

I have a Mac application of type agent (LSUIElement is true).
When app is executed, app icon is shown in top menu bar. On clicking the app icon in menu bar, menu items (NSMenuItem) are displayed.
Please find below my observations on following two scenarios:
App is executed without assigning tooltip to menu items:
While navigating using keyboard, VoiceOver focus remains on menu item on which there is a keyboard focus.
This is working as expected.
App is executed after assigning tooltip to menu items (using setTooltip method):
While navigating through menu items using keyboard, suddenly VoiceOver focus is shifted to some other UI element on screen (e.g. Finder window, Safari window, etc) or VoiceOver focus does not move with keyboard focus.
I observed that, this happens when keyboard focus is kept on a menu item for some time (e.g. around 4-5 seconds) before navigating to other menu item.
This is not working as expected.
Ideally, VoiceOver focus should move with keyboard focus even if tooltip is assigned to menu items.
Can anyone please tell me how to fix this.

Menu access from NSStatusItem (Menu Bar) Application in Swift

I'm creating an application where a menubar seems to be the most convenient way to have the user's desktop clean without a window. I've seen many tutorials online and on stack overflow but they seem to be only for Objective-C. I only use Swift. If you don't know what a menubar is, they're these icons:
I would like my app to have one of these instead of a constant full window. And if I can, how can I have a button on my menubar that brings up the window. Lastly, how can I have my icon not show, but I still have the finder advantages. (Like File, Edit..). For example,
I have already tried to put
Application is Agent (UIElement) to False
in my Info.plist but that also takes away my finder advantages.
Presumably what you're saying is that you want the text editing items (like Undo, Cut, Copy, Paste, Select All) from the Edit menu to work in your app's window.
Those menu items are part of another application, and only send messages in that application. They aren't available to your application, regardless of whether it's an “agent” (with no visible menu bar of its own). If one of your agent app's windows is the key window and the user clicks on a menu title (like File or Edit) that belongs to another app, then that app will activate and your app's window will “resign” the key window status.
You can make the usual shortcut keys (like ⌘X for Cut) work for your app, and it's easy. When one of your app's windows is the user's key window, your app receives keyboard events, and your NSApplication object (created for you automatically) will check its mainMenu for keyboard shortcuts even though the main menu is not displayed on the screen.
The OS X “Cocoa Application” project template sets up a main menu bar for you in MainMenu.xib (or in Main.storyboard), with all of the menu items wired up to the appropriate actions. So if you keep that main menu bar and the Edit menu and the menu items in the Edit menu and leave the shortcuts set on those items, then the keyboard shortcuts will work even if you set LSUIElement to YES in your Info.plist, when one of your app's windows is the key window. In other words, the shortcut keys will work by default, and you have to change things to make them stop working.
Text fields in your app's windows will also still get the default right-click menu with the usual items like Cut, Copy, and Paste, so you don't need to do anything else to make that work either.
Here's the contents of my test app's MainMenu.xib:
I've left the main menu bar alone. I've created a separate menu with two items, “Show Window” and “Quit”. I've set the shortcut for “Quit” to ⌘Q, but this shortcut has no effect. The StatusItem > Quit menu item (not visible in my screen shot) off the main menu bar has the same shortcut set, and that's the setting that matters. I've set the shortcut on this other Quit item because it's visible to the user, and the main menu bar won't be visible to the user.
I've wired this Quit item to the terminate: action of First Responder. (The StatusItem > Quit menu item is connected the same way by default.)
Here's my AppDelegate:
#NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
#IBOutlet var window: NSWindow!
#IBOutlet var statusItemMenu: NSMenu!
var statusItem: NSStatusItem?
func applicationDidFinishLaunching(aNotification: NSNotification) {
self.statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(NSVariableStatusItemLength)
let statusItem = self.statusItem!
let button = statusItem.button!
button.title = "Hello"
statusItem.menu = statusItemMenu
}
#IBAction func showWindow(sender: AnyObject) {
NSApp.activateIgnoringOtherApps(true)
window.makeKeyAndOrderFront(sender)
}
}
I've wired the “Show Window” menu item to the showWindow(_:) action, and I've connected the statusItemMenu outlet to that standalone menu in the XIB.
I also set “Application is Agent (UIElement)” to “YES” in Info.plist.
When I run this app, it creates the status item in the menu bar. I can choose “Show Window” from the item and my window comes to the front and becomes key. I can right-click the text field to get its context menu. I can use the standard shortcuts to cut/copy/paste/etc., to close the window, and even to quit the app.

How can I hide the dock and menubar in my fullscreen game?

I'm writing a game that will run in a fullscreen window. I'm using Xojo to code it (therefore any boolean window properties that might be availble in Xcode / Interface Builder are not an option).
Is there a plist key/value I can set in my app that will hide the application menubar and the dock when my window is set to full screen?
Needs to work on Yosemite.
Get the macoslib
It contains extensions for NSWindow that can do this. Just search the project for "fullscreen".
There is also a demo. If you run the project, open the menu bar: Examples -> Cocoa -> NSWindow. That window has a "Toggle Fullscreen" button for testing.
Here is what you need to place in the window Open event :
self.LiveResize = False
self.MenuBarVisible = false
self.FullScreen = true
First line turns off animation,
Second line turns off UI elements (dock and menu bar),
Third line makes the window full screen

How to make a window not open when the app loads XCode

If I have a NSWindow in Interface Builder and run my app, it opens.
How do I prevent this from happening? I'd like this window to only be opened when the user presses a button.
In the IB , you can find a check box named "Visible at Launch" in attributes tab.
You can uncheck that.So that window will not launch on app loading time

Menu closes during Drag and Drop with NSStatusItem

This question is in response to Drag and Drop with NSStatusItem
The code from #rob Keniger works for me. Following these exact steps, When I run the app, click the menu bar icon, I can drag things to my drag area and everything works. My problem is if I run the app, (then instead of clicking the menu icon first) click Finder, then click the menu bar icon, when I try to drag, the menu closes as I'm dragging.
How do I make the menu view stay open every time the user has the menu open and is dragging?
Looks like you have to do this:
[NSApp activateIgnoringOtherApps:YES];

Resources