More multiple movable modal madness
More multiple movable modal madness
- Subject: More multiple movable modal madness
- From: Andy Bettis <email@hidden>
- Date: Wed, 15 Jun 2005 11:48:07 +0100
HI folks,
To recap: I want to be able to display a moveable modal dialog and then
spawn a second modal dialog on top of that. There will also be a
validation alert that could be displayed on top of the second dialog,
but let's do one thing at a time.
I have set up NSWindowController subclasses to handle each dialog.
These are set up as delegates of the panel, and each have the routines:
- (void) windowDidBecomeKey:(NSNotification*) inNotification
{
[NSApp runModalForWindow:[self window]];
}
- (void) windowDidResignKey:(NSNotification*) inNotification
{
[NSApp stopModal];
}
In addition the second dialog is passed an NSWindow object whichj is
the panel of the first dialog. On creation it calls
[parentWindow addChildWindow:[self window] ordered:NSWindowAbove]
and when being removed
[parentWindow removeChildWindow:[self window]];
[[self window] orderOut:self];
Both dialogs are closed with
[NSApp stopModal];
[self autorelease];
This 'sort of' works, but there are still problems with it. When I
close the second dialog it goes away, but when I close the first dialog
the second one pops up again for a second. If I switch to another
application and then switch back the modal operation is lost and I can
select either dialog. Does the key window remain key when the app
becomes inactive, and is there a way of trapping this and making the
appropriate NSApp calls?
As an aside, is the [self autorelease] method a good way of making the
window go away? I had to add the [NSApp stopModal] call which I had
assumed would get called by windowDidResignKey when the window closed,
but in fact if it wasn't there I got a crash.
I feel like I must be going about this the wrong way. In PowerPlant I
would just make the window modal in the modal layer within Constructor
and that was pretty much it, once it was displayed the system would
handle all of the modal operation, window layering, etc. and I would
just code it as another window class. All of the moveable modal
examples I've seen in Cocoa seem to assume that the runModalForWindow
and stopModal calls would bracket the modal operation within a single
method, as with displaying an alert box. This is not what I want. I
realise that modals are a Bad Thing in Cocoa but they really do exactly
what I need and what my clients have asked for.
Are there ways of setting window level, default button, etc, within IB?
Maybe the terminology is different but I can't find anything like this
in the attributes list.
If I do have to code all this faffing about I will probably write a
subclass of NSWindowController that does it all and subclass this for
my specific dialogs - unless this has already been done? Are there
libraries of 'useful classes' for Cocoa that I can look through, or
even contribute to?
So, has anyone any experience with multiple modals like this or can
offer any advice?
Cheers
Rev. Andy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden