bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSWindowController doesn't load Gorm file.


From: Nicola Pero
Subject: Re: NSWindowController doesn't load Gorm file.
Date: Mon, 17 Feb 2003 01:59:37 +0000 (GMT)

> That problem is that the nib is loaded, but the internal _window is
> not set.

_window is an outlet.

You need to set it to point to the window from the nib, by connecting that
outlet to the window.  If you don't connect the outlet in Gorm, it won't
be connected ... there is no magic doing it for you.  :-)


>   Therefore, [NSWindowController window] only load the nib,
>   but not return the loaded window.
>   I can use [NSWindowController setWindow: xxx] to make it work,
>   but it is not what the Cocoa document say.
>
>   In ideal case, I can use [NSWindowController initWithNibName: Owner:].
>   And [NSWindowController window] should return the loaded window
>   because it will load and set the window.

It's not NSWindowController which sets the window.  NSWindowController
just loads the nib.  The nib file creates the window.  Then, the
connections in the nib file are established.  And the nib file should
contain an outlet which connects the 'window' outlet of the file owner to
the window.

When the NSWindowController loads the window, it is itself the file owner.  
Establishing the connection will automatically set its _window, and this
is why it would work.

If the nib/gorm file doesn't contain the outlet, the connection won't be
established, and it won't work.


>   Now, I have to manually use -loadWindow and -setWindow:.
>   I think the problem is in the -loadWindow of NSWindowController,
>   but in the source code, I can't find where the loaded window is.
>   [NSBundle loadNibNamed:] only return BOOL, not the loaded window.

Of course.  The window should be set using an outlet in the nib file
itself.

Create your window in Gorm.  Then, select the 'File Owner'.  In the
'Inspector', look for 'Attributes'.  It should list all the available
classes.  Choose 'NSWindowController'.  That tells Gorm that the file
owner will be an instance of NSWindowController.

Then, you should have the 'window' outlet available for your 'File Owner'.  
Select 'Connections' for the 'File Owner'.  There should be a 'window'
outlet.  Connect the 'window' outlet of the FileOwner to your window.

Such a file, when loaded from a NSWindowController initialized using
-initWithNibName:, will automatically set the window outlet of the file
owner (==the NSWindowController object) to point to the window, and so it
will work.


I know it's sort of pedantic and cumbersome ... I guess it's disappointing
to find out that there is really no magic, the window controller can't
know what the window is unless you set it yourself by using a primitive
outlet ... but that's it - I believe it's how it works on Apple too. :-)

If all you need to do is getting the loaded window, then you really need
an outlet, and not a NSWindowController ... :-)

I'm sorry if my explanation is difficult to follow, it's quite difficult
to explain this stuff in an email.

I personally think the NSWindowController API is not that genius piece of
software after all.  It doesn't provide you with much that you couldn't
already do, and makes the whole thing quite a lot more complicated to
understand (as exemplified by this email thread).  It makes some more
sense when used together with the NSDocument stuff.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]