Reputation: 580
Hello I am working on a program which uses 2 windows. With the main window you are able to open the second window.
If i click on the runnable file while the program is running the first window opens over the second window. Thats no wanted. How could i exclusively open the first window if the second is not opened or minimised, otherwise i would prefer to activate the second window without reopening the first.
I hope you could help me because i can't find anything useful in the internet. I am new to OSX programming but I am not that bad in other languages.
Upvotes: 2
Views: 321
Reputation: 5665
You need to implement the NSApplicationDelegate
method applicationShouldHandleReopen:hasVisibleWindows:
I've only used this when the app has closed all it's windows and needs to reopen one, but I believe this would work for you:
- (BOOL) applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag
{
return !flag;
}
That tells the NSApp
to reopen the default way (YES
) if there are no visible windows, and to "do nothing" (NO
) if there are visible windows.
What seems odd, though, is that this should be the default behavior, unless your second window is an NSPanel
. So perhaps that is the root of your problem? Let me know if this works... happy to update with feedback.
Upvotes: 1