Show application when dock icon clicked

  • I'm trying to show my application window when a user clicks on their
    dock icon. This works fine when the application is not active because
    I can do this in my window/app delegate:

    - (void)applicationDidBecomeActive:(NSNotification *)aNotification {
        [mainWindow makeKeyAndOrderFront:self];
    }

    - (BOOL)windowShouldClose:(id)window {
        [mainWindow orderOut:self];
        return NO;
    }

    That's fine if the users closes the window then deactivates it but
    doesn't work if the user closes the window then clicks on the dock
    icon. I cannot find an obvious delegate from NSApplication or NSWindow
    that provides me with a notification when the dock icon is clicked. Am
    I overlooking something?

    cheers,
    Byron
  • On Jan 17, 2008, at 2:07 PM, Byron Wright wrote:

    > That's fine if the users closes the window then deactivates it but
    > doesn't work if the user closes the window then clicks on the dock
    > icon. I cannot find an obvious delegate from NSApplication or
    > NSWindow that provides me with a notification when the dock icon is
    > clicked. Am I overlooking something?

    You might want to take a look at the "-
    applicationShouldHandleReopen:hasVisibleWindows:" NSApplication
    delegate method.

    j o a r
  • awesome! that did it. Thanks! I knew it has to be that easy, the
    method name makes it sound like it's specific to a document based
    application... might just be me.
    On Jan 17, 2008, at 2:40 PM, j o a r wrote:

    >
    > On Jan 17, 2008, at 2:07 PM, Byron Wright wrote:
    >
    >> That's fine if the users closes the window then deactivates it but
    >> doesn't work if the user closes the window then clicks on the dock
    >> icon. I cannot find an obvious delegate from NSApplication or
    >> NSWindow that provides me with a notification when the dock icon is
    >> clicked. Am I overlooking something?
    >
    >
    > You might want to take a look at the "-
    > applicationShouldHandleReopen:hasVisibleWindows:" NSApplication
    > delegate method.
    >
    > j o a r
    >
    >
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today