Re-opening window by clicking on the dock icon

Discussion in 'Mac Programming' started by BadWolf13, Jun 20, 2010.

  1. BadWolf13 macrumors 6502

    Joined:
    Dec 17, 2009
    #1
    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?
     
  2. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #2
    Look under
    NSApplication
    ->Delegate Methods
    --->applicationDidBecomeActive:
    or->applicationWillBecomeActive:
     
  3. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #3
    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.
     
  4. BadWolf13 thread starter macrumors 6502

    Joined:
    Dec 17, 2009
    #4
    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.
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
  6. BadWolf13 thread starter macrumors 6502

    Joined:
    Dec 17, 2009
    #6
    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.
     
  7. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #7
    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:

    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.
     
  8. BadWolf13 thread starter macrumors 6502

    Joined:
    Dec 17, 2009
    #8
    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.
     
  9. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #9
    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.

    You're welcome, I'm sure.
     

Share This Page