Showing progress in a sheet
Showing progress in a sheet
- Subject: Showing progress in a sheet
- From: David Feldman <email@hidden>
- Date: Mon, 28 Jan 2002 13:28:32 -0500
I have a panel that I'm using to show progress on a fairly lengthy process.
The panel includes a progress indicator and some text feedback. Periodically
the process sends messages back to the window to alter the progress
indicator or change the text.
I can't seem to get it to work right. I think I need to set up the process
itself as a separate thread, and for the most part that works -- I'm not
doing anything fancy, just launching the thread and sending the relevant
messages from the thread to my controller object. I don't know if that's
officially thread safe but since that separate thread is the only thing
talking to those objects it seems like it should work.
The problem is the sheet. I need it to be modal so users can't go up to the
menus and, for example, launch another instance of the same process. But I
can't figure out where to call runModalForWindow: and stopModal: so that (a)
the sheet receives the messages it needs to update itself, (b) the process
runs, and (c) when the sheet closes, the menu highlight goes away and the
main window re-highlights properly.
Without any calls to modal methods, everything seems to work OK if I open
the sheet and start the progress bar right before separating the thread, and
close the sheet, order it out, and stop the progress bar at the end of the
thread's main method. The problem is that the menus are still active.
The closest I've gotten is to call runModalForWindow: right after separating
the thread. (the modalForWindow: parameter in my call to beginSheet: is the
main window...I think that's correct?) The progress bar spins (I haven't set
it to use threaded animation, don't know if I should), the messages change
as expected, and the sheet closes. When it's running, some of my menu items
are still shown as active (why?) but don't seem to execute their commands.
But after the sheet closes, the menu I chose the command from remains
highlighted, and the title bar buttons in the main window are grayed out and
won't come back to life. Also I can't quit. If I try the same command again,
the sheet appears in the middle of the screen, not attached to anything.
What should I do?
Thanks,
--Dave