[SOLVED] Window layering and save sheet attachment in multi-window document
[SOLVED] Window layering and save sheet attachment in multi-window document
- Subject: [SOLVED] Window layering and save sheet attachment in multi-window document
- From: Derrick Bass <email@hidden>
- Date: Thu, 1 Dec 2005 15:56:02 -0600
On Dec 1, 2005, at 12:31 PM, Sherm Pendley wrote:
On Dec 1, 2005, at 5:24 AM, Derrick Bass wrote:
The order seems to be:
makeWindowControllers: is called and finishes.
windowControllerDidLoadNib: is called for the first window
created, and finishes.
The first window is displayed and made front.
windowControllerDidLoadNib: is called for the second window
created, and finishes.
The second window is displayed and made front.
What I would do is keep a counter, and increment it each time
windowControllerDidLoadNib: is called. Then, when the counter
indicates that this is the last Nib to load, you could display the
windows in whatever order you want.
I think what I was doing was essentially equivalent; the problem is
that the windows are being displayed by some internal Cocoa code
somewhere and not by and methods that I wrote. That's what I meant by
"The first window is displayed and made front" and so on.
I really wish Apple would make available the source code to Cocoa (at
least the simple parts that smart people can figure out on their own
anyway, but that people like me need a little help with); that's one
of the things I really liked about PowerPlant. But anyway, I took a
look at the source code for GNUStep to figure out how all the
plumbing works. It appears that the problem is in the -[NSDocument
showWindows] method. The GNUStep routine is simply
- (void) showWindows
{
[_windowControllers makeObjectsPerformSelector: @selector
(showWindow:)
withObject: self];
}
and presumably the Cocoa routine is similar.
So I overrode this in my NSDocument subclass to be a little smarter
(warning, gratuitous C++ ahead, please fasten your seat belts):
- (void) showWindows
{
NSArray *windowControllers = [self windowControllers];
unsigned int count = [windowControllers count];
int prev = 0;
for (unsigned int i=0; i<count; ++i) {
NSWindowController *controller =
static_cast<NSWindowController*>( [windowControllers objectAtIndex:i] );
if (prev == 0)
[controller showWindow:self];
else
[[controller window] orderWindow:NSWindowBelow
relativeTo:prev];
prev = [[controller window] windowNumber];
}
}
What this does is display the windows in the same order they are
created, but the layering is reversed from what you'd normally
expect; the first window is on top, the second behind that, the third
behind the second, etc.
I think in general I'd want it even a little smarter, and have all
the shouldCloseDocument==YES windows be in front of the
shouldCloseDocument==NO windows. That's what I expected to happen
automatically. (I also expected the save sheet to automatically be
attached only to shouldCloseDocument==YES windows; I guess I just
expect too much.) Anyway, the above code works for me for now.
Derrick
_______________________________________________
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