home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!rosie!next.com
- From: jdoenias@next.com (Josh Doenias)
- Newsgroups: comp.sys.next.programmer
- Subject: Re: How do I make my "stop" button work?
- Message-ID: <6032@rosie.NeXT.COM>
- Date: 14 Dec 92 01:36:45 GMT
- References: <BywsHq.Hv4@cmcl2.nyu.edu>
- Sender: news@NeXT.COM
- Lines: 67
-
- In article <BywsHq.Hv4@cmcl2.nyu.edu> dario@cns.nyu.edu (Dario Ringach,
- x3941) writes:
- >I have a button sending an -abortCalculation message to an object which
- >is engaged in a loop... Something like this:
- >
- >-compute:sender
- >{
- > notAborted = YES;
- > while(notAborted) {
- > ....
- > }
- > return self;
- >}
- >
- >-abortCalculation:sender
- >{
- > notAborted = NO;
- > return self;
- >}
- >
- >Needless to say... it doesn't work.
- >How can I make it to work?
-
-
- Your abortCaclulation: message is the target of a button. It will get
- called as a result of a user action -- namely, the user clicking on the
- button.
- However, your app is busy in its while(notAborted) loop, so it can't
- respond to user actions. You have to give the app the opportunity to
- respond to events.
-
- You can do this in one of several different ways, but probably the easiest
- and most appropriate for this situation is to use a modal session.
-
- A modal session allows you to run your loop while still processing events.
- You can only respond to events in one window with this method. That's
- probably okay, since all you care about is the window with the stop button
- in it.
- This would end up looking something like this:
-
- - compute:sender
- {
- NXModalSession session;
-
- [NXApp beginModalSession:&session for:theWindow]; // theWindow is the
- window with the stop button in it.
- while ([NXApp runModalSession:&session] == NX_RUNCONTINUES) {
- /* Do the rest of your computation loop here */
- }
- [NXApp endModalSession:&session];
- return self;
- }
-
- - abortCalculation:sender
- {
- [NXApp stopModal];
- return self;
- }
-
-
- For a slightly different way to make an abortable procedure, check out the
- description of NXUserAborted(). This will let you break out of a loop if
- the user hits cmd - period.
-
- Hope this helps,
-
- -- josh
-