Path: utzoo!attcan!uunet!nih-csl!lhc!ncifcrf!haven!purdue!decwrl!adobe!heaven!glenn From: glenn@heaven.woodside.ca.us (Glenn Reid) Newsgroups: comp.sys.next Subject: Re: How do I interrupt my App? Message-ID: <313@heaven.woodside.ca.us> Date: 5 Nov 90 23:00:14 GMT References: <1614@libra.cs.nps.navy.mil> Reply-To: glenn@heaven.woodside.ca.us (Glenn Reid) Organization: RightBrain Software, Woodside, CA Lines: 71 In article <1614@libra.cs.nps.navy.mil> sisk@cs.nps.navy.mil (Tamara Sisk) writes: >I'm polishing up a nifty App to submit to the sites, but I'm stuck on >one thing. > >Part of the App involves creating a (very) long list in a ScrollView. >I want to be able to stop the listing without crashing my App, once >I'm happy with how long the list is. Currently, there is a "Start" button >that starts the listing. I'd like to make it so that this button >turns into a "Stop" button while the list is going, so that if >I push it again, the method creating the list just stops, just like >ScorePlayer, for example, whose start button turns into a stop button. This turns out to be a little more complicated than you might think, but below is some code that does the trick, thanks to some pointers from NeXT people a long time ago. The basic idea is this: * start a "modal session" for the active window * enter your busy loop in which you create the long list in the scrollview * periodically within the loop you call a method to see if the modal dialog has been stopped, and exit the loop if so * end the modal session and clean up Here are some code fragments; assume that you have a button that triggers a method called "stop" in your object, and that the object itself has a outlet to the button called "stopButton" so it can disable it. My code does not make the same button into the STOP button, but you can figure out that part. /****************************** yourMethod */ - yourMethod:sender { NXModalSession session; short whatever = TRUE; [NXApp beginModalSession: &session for: window]; [stopButton setEnabled:TRUE]; while ( whatever ) { if ( [NXApp runModalSession: &session] != NX_RUNCONTINUES ) { // stop button was hit // clean up and exit while loop break; } } [NXApp endModalSession: &session]; [stopButton setEnabled:FALSE]; return self; } // yourMethod /****************************** stop */ - stop:sender { [NXApp stopModal]; NXBeep(); NXRunAlertPanel ( "Stopped", "Stopped at your request.", NULL, NULL, NULL ); return self; } // stop -- Glenn Reid RightBrain Software glenn@heaven.woodside.ca.us PostScript/NeXT developers ..{adobe,next}!heaven!glenn 415-851-1785