[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem with file owner on Renaissance files
From: |
Nicola Pero |
Subject: |
Re: Problem with file owner on Renaissance files |
Date: |
Wed, 16 Jul 2003 10:18:50 +0100 (BST) |
> Am trying to load a main menu file thus:
>
> int main(int argc, const char *argv[])
> {
> NSAutoreleasePool *pool = [NSAutoreleasePool new];
>
> [NSApplication sharedApplication];
> [NSBundle loadGSMarkupNamed:@"MainMenu" owner:NSApp];
>
> return NSApplicationMain(argc, argv);
> }
>
> But I get an app with a blank menu. If I create a dummy object to
> act as the delegate and pass an instance of that in as the owner
> then it works. Passing in nil or NSApp doesnt.
You are on Apple, are not you ? Passing NSApp works on GNUstep. I don't
have an Apple here, but I imagine NSApp doesn't work there. :-)
> How do I simply load up a main menu nib file without having to
> create a dummy deletage for it ? Theer are no references to the files
> owner in the actual markup file. I am quite puzzled by this.
The reason why this API is puzzling is that I've tried to mirror the
"standard" NIB API, and the "standard" NIB API is somewhat puzzling :-)
If you look at the documentation, loadGSMarkupNamed:owner: is behaving
precisely in the same way as loadNibFileNamed:owner:.
In particular, the owner should not be nil (this is why nil doesn't work)
- in that case, the method will just return NO immediately. If it's not
nil, NSBundle is loading the gsmarkup file from a bundle. Which bundle ?
If owner's class is from a bundle, then from that bundle. If owner's
class is not from a bundle, then the mainBundle.
On Apple, [NSBundle bundleForClass: [NSApp class]] probably returns the
AppKit framework, so if you pass NSApp as the owner, Renaissance will try
loading the gsmarkup from the AppKit bundle/framework (and that fails!).
On GNUstep, [NSBundle bundleForClass: [NSApp class]] returns nil, so
Renaissance will use [NSBundle mainBundle] instead (and that works!). Of
course, it's only a guess, I don't have an Apple at hand to check.
=
One solution to your problem could be to use the more explicit API -
[[NSBundle mainBundle] loadGSMarkupFile: @"MainMenu"
externalNameTable: [NSDictionary dictionary]
withZone: NULL];
=
But I see your point; how much important is it to be consistent with the
NIB loading API, rather than having a friendly simple gsmarkup loading
API, is up to discussion.
Maybe we could keep what we have, and if we are not satisfied with the
NIB-like loading API, add a couple of well-designed new methods.
Or just extend/stretch the one we have, for example allowing 'nil' to be
used as 'owner' in +loadGSMarkupNamed:owner:, meaning to load from the
main bundle without an NSOwner key in the external name table. I'm
tempted to do this.
Let me know your thoughts.