Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BadWolf13

macrumors 6502
Original poster
Most programs will open a window, or open the main window when you click on the dock icon. My program doesn't do that though. If I close the central window to it, it's basically gone until you close and restart the program. How do I get it to do what iTunes and Firefox and Mail, and basically most programs do?
 
Most programs will open a window, or open the main window when you click on the dock icon. My program doesn't do that though. If I close the central window to it, it's basically gone until you close and restart the program. How do I get it to do what iTunes and Firefox and Mail, and basically most programs do?
Look under
NSApplication
->Delegate Methods
--->applicationDidBecomeActive:
or->applicationWillBecomeActive:
 
Read the documentation for -applicationShouldHandleReopen:hasVisibleWindows:.

This delegate method is called when the user clicks on the dock or reopens the app via Finder. It also explains how to take advantage of some built-in AppKit behavior.
 
Thanks guys, but I'm not sure if you're getting what I'm saying. All your suggestions seem to revolve around re-activating an app.

Let me give you an example. You're using iTunes, and for some reason or other, you close the window. Now iTunes is still running, and it's still the active application, the menu bar at the top of the screen still has the iTunes menus, but the window is gone. If you click on the dock icon, the iTunes window reappears. That's what I want my app to do.
 
Google search terms: applicationShouldHandleReopen

One of the first few hits:
http://www.cocoadev.com/index.pl?AppWindowBehaviour

You know Chown, I don't need someone to tell me how to use google. I come to this forum to ask advice from experience programmers. As I have told you previously, if your best solution is to "look elsewhere," then I kindly ask that you please don't post replies to any of my questions.
 
I don't think chown was being condescending. He simply said what google search terms he used and gave you a link to useful web page that explains how to accomplish what you're trying to do. No need to get snippy.

But you really should look at what we mentioned again. "Re-activitating" the app is exactly the user action you're describing. If you look at the documentation I mentioned instead of just brushing it off, you'd find this:

These events are sent whenever the Finder reactivates an already running application because someone double-clicked it again or used the dock to activate it.

This delegate method is called to allow you to handle reopening your main window (or doing whatever you want) when the user clicks on the dock icon.
 
I actually did read that documentation, which is what lead me to that question. As per the documentation, it uses the term "reactivates," which I took to mean switching to the application from another one, not clicking the dock icon. Quite honestly, I don't see the two terms being interchangeable. But in any case, thanks for the help.
 
I actually did read that documentation, which is what lead me to that question. As per the documentation, it uses the term "reactivates," which I took to mean switching to the application from another one, not clicking the dock icon. Quite honestly, I don't see the two terms being interchangeable.

That's why I pointed you to the cocoadev article. It seems to be a complete example, integrated with windowShouldClose:. And I noted how I found it, as there were some similar articles in the search results.

But in any case, thanks for the help.

You're welcome, I'm sure.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.