RE: Using sheets with DO Threads (was Working with sheets...)
RE: Using sheets with DO Threads (was Working with sheets...)
- Subject: RE: Using sheets with DO Threads (was Working with sheets...)
- From: "Huyler, Christopher M" <email@hidden>
- Date: Tue, 9 Dec 2003 13:51:09 -0500
- Thread-topic: Using sheets with DO Threads (was Working with sheets...)
I did some brainstorming and research this morning myself and came up
with what I was looking for:
-- A custom sheet that runs as a modal session --
First read:
http://developer.apple.com/documentation/Cocoa/Conceptual/Sheets/index.h
tml
Then, this should make sense:
- (void)showCustomSheet: (NSWindow *)window
// User has asked to see the custom display. Display it.
{
if (!myCustomSheet)
[NSBundle loadNibNamed: @"MyCustomSheet" owner: self];
[NSApp beginSheet: myCustomSheet
modalForWindow: window
modalDelegate: nil
didEndSelector: nil
contextInfo: nil];
sheet = [NSApp beginModalSessionForWindow: myCustomSheet];
[NSApp runModalSession: session];
// Sheet is up here.
// showCustomSheet() finishes and frees up run loop for other tasks
// such as receiving DO actions or NSTimer scheduled routines.
// However, any user event outside the sheet is ignored until
// the sheet is dismissed.
}
- (IBAction)closeMyCustomSheet: (id)sender
{
[NSApp endModalSession:session];
[NSApp endSheet: myCustomSheet];
[myCustomSheet orderOut: self];
// Sheet is closed normal operation commences
}
Make sure you define "NSModalSession session" in your class header file
so that it can be used in both functions.
My implementation creates a DO thread, calls a one-way function using
the thread (see Simple Threads sample code) then opens the sheet. The
DO thread periodically calls procedures to its controller (the object
that created the thread) which update the state of an
NSProgressIndicator displayed within the sheet. When the thread is
finished, it executes another of the controller's procedures which runs
the code in closeMyCustomSheet. All the while a NSTimer is executing
more code to keep a NSTable in the underlying main window filled with
the most up-to-date information.
I'm happy now.
~ Chris
-----Original Message-----
From: Fritz Anderson [
mailto:email@hidden]
Sent: Tuesday, December 09, 2003 1:20 PM
To: Huyler, Christopher M
Cc: email@hidden
Subject: Re: Working with sheets...
This is brainstorming at the keyboard...
Your controller class is the owner of an NSPanel, which is the sheet.
The controller's designated initializer takes the parent window as a
parameter, saves it, and loads the panel's nib.
A separate run method starts the task and the monitor thread. It then
does beginSheet:modalForWindow:... / runModalForWindow: ... / endSheet:
/ [panel close].
During rubModalForWindow:, events come in from the thread
asynchronously, and the controller's action methods get fired by
controls in the sheet. (I am, off the top of my head, unclear on
whether the runloop mode for the sheet would lock out the DO
notifications. My guess is not, but it's a potential bug to watch for.)
If the user cancels, tell the thread to kill the task and return from
its loop, and send [NSApp stopModal]. If the task completes, have the
thread return after calling a DO method on the controller's main thread
that will send [NSApp stopModal].
The run method returns. Various status will be left in the controller
object for you to harvest. So far as the controller's client is
concerned it looks like:
controller = [[Controller alloc] initWithParent: window ...];
[controller run];
information = [controller getWhatever];
[controller release];
-- F
On 9 Dec 2003, at 7:55 AM, Huyler, Christopher M wrote:
>
Simple:
>
If I create a window that I want to display as a sheet. How can I
have
>
a section of code run when the sheet is displayed?
>
>
Complex:
>
The user presses a button which creates a separate thread to launch an
>
external application. The application sends updates back to the
>
separate thread, which then relays the messages (via DO) to the main
>
controller class. I want to pop up a sheet when the user presses this
>
button and have the sheet (and its controller) do all this work
instead
>
of the main controller class. That way, the user cannot do anything
>
else until the process has finished.
>
>
Is this possible?
>
>
--
>
Christopher Huyler
>
Computer Associates Intl.
>
mailto:email@hidden
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.