Multiple movable modals
-
Hello again,
In my app I want to display a moveable modal dialog. (Please take my
word that I have good reasons for doing this.) I have subclassed
NSWindowController to control the dialog, with an init method:
- (id)init
{
self = [super initWithWindowNibName:@"CCategoriesDialog"];
return(self);
}
I use a class method to start the dialog up:
+ (id)create:(MyDocument*) inDocument
{
CCategoriesDialog* theDialog = [[CCategoriesDialog alloc] init];
[theDialog setDocument:inDocument];
[[theDialog window] setLevel:NSModalPanelWindowLevel];
[NSApp runModalForWindow:[theDialog window]];
[theDialog showWindow:self];
return(theDialog);
}
And I have a 'go away' method:
- (IBAction)OK:(id)sender
{
[NSApp stopModal];
[self autorelease];
}
So far, all is well. Should I be doing anything else to tidy up when
the panel goes away?
Unfortunately I want to spawn a second modal dialog from this one. When
I do so it looks fine but the new window is not modal, it is possible
to click and select the first one, which is not what I want. I imagine
that I need to call [NSApp stopModal] on the first window before
calling [NSApp runModalForWindow:[theDialog window]] on the second one
- is this true? If so I need to know when the second one has gone away
so I can restore the [NSApp runModalForWindow:[theDialog window]] call
on the first window again. What I would like to do is to put the NSApp
modal on/off calls in methods that are called when the window becomes
or stops being the key window but I can't work out where this should
be. Do I need to use notifications for this?
Also, is it possible to set the window level in IB?
Thanks in advance,
Rev. Andy -
Andy,
You can try something like this:
[currentModalWindow addChildWindow:newModalWindow
ordered:NSWindowAbove];
[NSApp runModalForWindow:newModalWindow];
// Modal window runs here
[currentModalWindow removeChildWindow:newModalWindow];
[newModalWindow orderOut:self];
I've done that before to have a modal window on top of another modal
window, and it worked fine if I remember correctly.
zach
On Jun 14, 2005, at 6:46 AM, Andy Bettis wrote:> Hello again,
>
> In my app I want to display a moveable modal dialog. (Please take
> my word that I have good reasons for doing this.) I have subclassed
> NSWindowController to control the dialog, with an init method:
>
> - (id)init
> {
> self = [super initWithWindowNibName:@"CCategoriesDialog"];
> return(self);
> }
>
> I use a class method to start the dialog up:
>
> + (id)create:(MyDocument*) inDocument
> {
> CCategoriesDialog* theDialog = [[CCategoriesDialog alloc] init];
>
> [theDialog setDocument:inDocument];
>
> [[theDialog window] setLevel:NSModalPanelWindowLevel];
>
> [NSApp runModalForWindow:[theDialog window]];
>
> [theDialog showWindow:self];
>
> return(theDialog);
> }
>
> And I have a 'go away' method:
>
> - (IBAction)OK:(id)sender
> {
> [NSApp stopModal];
>
> [self autorelease];
> }
>
> So far, all is well. Should I be doing anything else to tidy up
> when the panel goes away?
>
> Unfortunately I want to spawn a second modal dialog from this one.
> When I do so it looks fine but the new window is not modal, it is
> possible to click and select the first one, which is not what I
> want. I imagine that I need to call [NSApp stopModal] on the first
> window before calling [NSApp runModalForWindow:[theDialog window]]
> on the second one - is this true? If so I need to know when the
> second one has gone away so I can restore the [NSApp
> runModalForWindow:[theDialog window]] call on the first window
> again. What I would like to do is to put the NSApp modal on/off
> calls in methods that are called when the window becomes or stops
> being the key window but I can't work out where this should be. Do
> I need to use notifications for this?
>
> Also, is it possible to set the window level in IB?
>
> Thanks in advance,
>
> Rev. Andy
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (<Cocoa-dev...>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<zach...>
>
> This email sent to <zach...>
> -
On Jun 14, 2005, at 8:46 AM, Andy Bettis wrote:> Unfortunately I want to spawn a second modal dialog from this one.
> When I do so it looks fine but the new window is not modal, it is
> possible to click and select the first one, which is not what I
> want. I imagine that I need to call [NSApp stopModal] on the first
> window before calling [NSApp runModalForWindow:[theDialog window]]
> on the second one - is this true? If so I need to know when the
> second one has gone away so I can restore the [NSApp
> runModalForWindow:[theDialog window]] call on the first window
> again. What I would like to do is to put the NSApp modal on/off
> calls in methods that are called when the window becomes or stops
> being the key window but I can't work out where this should be. Do
> I need to use notifications for this?
- (void) registerAsDelegate
{
// register as delegate to the second window
[theWindow setDelegate:self];
}
- (void) windowWillClose:(NSNotification*note)
{
// this method is called when the window is closed
}
Eric Brunstad
Mind Sprockets Software
<eric...>
www.mindsprockets.com


