Quitting when Menu closes

  • I am writing an app (my first since NeXTSTEP days)  that simply pops a
    menu up at the mouse location, responds to the selection, then quits.
    I have it doing everything I want except quitting. It should quit
    whenever the menu closes, whether an item has been chosen or not. How
    can I get the app to quit when nothing has been chosen from the menu.

    I have no problem quitting the app when a menu item is chosen. I
    simply terminate the app after performing the desired menu item
    action.

    BUT, when the user simply drags the mouse off the menu so it closes
    without making any selection, then I can't get it to quit properly.

    The menu is in a PopuUpButton "_menuButton" which lives in a Window.
    In the window's awakeFromNib I put...

        [[_menuButton menu]setDelegate:self];

    And then in among the methods for the window I include...

    - (void)menuWillClose:(NSMenu *)menu
    {
    [self close];
    }

    (Note, the app is set to quit when that window closes and the [self
    close] works find for quitting the app whenever a selection _is_
    made.)

    But this does not work. When the user drags the mouse off the menu, no
    menuWillClose event seems to be generated.

    Any ideas what I'm doing wrong? Any other thoughts on how to quite the
    app upon the menu close?

    Thanks,
    ...Eric

    --
    Eric Celeste / <efc...>
  • Am 03.11.2007 um 17:51 Uhr schrieb Eric Celeste:

    > Any ideas what I'm doing wrong?

    Nothing.

    > Any other thoughts on how to quite the
    > app upon the menu close?

    If something is hard to do in Cocoa, it's usually because it's - at
    least - uncommon.

    Why would you want to close your application if the user *aborts* an
    action? That's not at all intuitive.

    While it's most likely still possible (involving subclassing,
    probably), I think shouldn't waste more time on that.

    Andreas
  • >> Any ideas what I'm doing wrong?
    >
    > Nothing.

    OK. At least that makes me feel a bit better!

    >> Any other thoughts on how to quit the
    >> app upon the menu close?
    >
    > If something is hard to do in Cocoa, it's usually because it's - at
    > least - uncommon.
    >
    > Why would you want to close your application if the user *aborts* an
    > action? That's not at all intuitive.
    >
    > While it's most likely still possible (involving subclassing,
    > probably), I think shouldn't waste more time on that.

    I'm writing an app similar to DejaMenu, but designed to be launched
    (by a Mighty Mouse click), do its work (present a copy of the menu bar
    at the current mouse location), and disappear. So far all works well
    except the disappear. If the user aborts the menu in this case, they
    are aborting the whole app. It should just disappear.

    This is certainly an uncommon case. I've tried the notification
    approach as well, but it seems that NSMenuDidEndTrackingNotification
    is sent before NSMenuDidSendActionNotification (I'm writing a test app
    to confirm that right now), so that just resulted in the whole app
    terminating before legitimate actions were taken.

    I am puzzled that my window, which is set up as a delegate for the
    menu, does not seem to be getting the menuWillClose: call.

    Of course, if there is another way to sense an aborted menu close (as
    opposed to a proactive click on a menu item) that would be ideal.

    ...Eric

    --
    Eric Celeste / http://eric.clst.org / Saint Paul, MN / 651-323-2009 /
    <efc...>
  • Do you really think it will be fast enough to launch it in response
    to a mouse click, every time?
    Usually an app like this will always be running silently, not
    quitting and restarting itself constantly.

    On Nov 3, 2007, at 2:44 PM, Eric Celeste wrote:

    >>> Any ideas what I'm doing wrong?
    >>
    >> Nothing.
    >
    > OK. At least that makes me feel a bit better!
    >
    >>> Any other thoughts on how to quit the
    >>> app upon the menu close?
    >>
    >> If something is hard to do in Cocoa, it's usually because it's - at
    >> least - uncommon.
    >>
    >> Why would you want to close your application if the user *aborts* an
    >> action? That's not at all intuitive.
    >>
    >> While it's most likely still possible (involving subclassing,
    >> probably), I think shouldn't waste more time on that.
    >
    > I'm writing an app similar to DejaMenu, but designed to be launched
    > (by a Mighty Mouse click), do its work (present a copy of the menu bar
    > at the current mouse location), and disappear. So far all works well
    > except the disappear. If the user aborts the menu in this case, they
    > are aborting the whole app. It should just disappear.
    >
    > This is certainly an uncommon case. I've tried the notification
    > approach as well, but it seems that NSMenuDidEndTrackingNotification
    > is sent before NSMenuDidSendActionNotification (I'm writing a test app
    > to confirm that right now), so that just resulted in the whole app
    > terminating before legitimate actions were taken.
    >
    > I am puzzled that my window, which is set up as a delegate for the
    > menu, does not seem to be getting the menuWillClose: call.
    >
    > Of course, if there is another way to sense an aborted menu close (as
    > opposed to a proactive click on a menu item) that would be ideal.
    >
    > ...Eric
    >
    > --
    > Eric Celeste / http://eric.clst.org / Saint Paul, MN / 651-323-2009 /
    > <efc...>
previous month november 2007 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    
Go to today