Re: regenerate a nib file from the output of nibtool?
Re: regenerate a nib file from the output of nibtool?
- Subject: Re: regenerate a nib file from the output of nibtool?
- From: Bill Bumgarner <email@hidden>
- Date: Wed, 21 Aug 2002 10:53:46 -0400
I have recently been working on a project that involved converting more
than 50 NIBs that were created on NeXTSTEP 3.3 to OS X 10.2. The
original nibs contained hundreds of instances of palettized objects as
well as custom views and thousands of regular UI objects. Converting
the NIBs required writing code to heavily edit the NIB documents as
they were passed through both the command line NIB tool and IB itself.
So, as such, I may be able to help you out... :-) Some of this
information will be a rehash of what you already know -- it is included
for the benefit of anyone else on the list who might be interested.
WARNING: There is a bug-- maybe a feature-- in /usr/bin/nibtool such
that any NIB file written by nibtool cannot subsequently be edited in
IB. Depending on what you are doing, this may not be a problem. If
you want to open the resulting NIBs in IB, then you cannot use nibtool
to do the conversion. This behavior has changed in 10.2 -- it appears
that NIBs passed through nibtool can now be edited in IB successfully.
I am assuming that what you want to do is:
- load the NIB file
- edit the contents of the NIB document
- save the modified NIB file
To do this with nibtool, you would use a combination of the -w/-W flags
and -P. -P would be used to specify the path to an IB palette that
you need to implement to do the conversion.
Specifically, create a new IB Palette project in Project Builder.
Edit the the *Palette.m file and:
- add a notification listener for IBDidOpenDocumentNotification
notifications.
+ (void) load
{
[[NSNotificationCenter defaultCenter] addObserver: self
selector:
@selector(ibDocumentDidOpen:)
name:
IBDidOpenDocumentNotification
object: nil];
}
- add a handler that is executed whenever the notification is received:
+ (void) ibDocumentDidOpen: (NSNotification *) aNotification
{
id <IBDocuments> ibDocument = [aNotification object];
NSEnumerator *documentObjectsEnumerator;
id anObject;
documentObjectsEnumerator = [[ibDocument objects] objectEnumerator];
while( anObject = [documentObjectsEnumerator nextObject] ) {
if ([anObject isKindOfClass: [NSMatrix class]])
[self _ibDocument: ibDocument adjustKindsOfNSMatrix:
anObject];
if ([anObject isKindOfClass: [NSText class]])
[self _ibDocument: ibDocument _adjustKindsOfNSText:
anObject];
}
}
The above handler walks the list of objects found within the NIB
document -- not ALL objects, but only those that are directly a part of
the NIB document -- and checks the kind of the object. If it is of a
particular kind (in this case: instances of the NSMatrix or NSText
class or subclasses), then a method is invoked to perform the class
specific adjustments. For example -- the following code fixes a bug in
the AppKit's conversion code for NIBs that were originally written on
OpenStep 4.2. In certain circumstances, an NSText instance would be
created that lacked a superview. This method detects this situation
and attempts to correctly install the NSText instance into the
encapsulating scrollview/clipview using a combination of the methods
found in the IBDocuments protocol and standard AppKit view hierarchy
manipulation methods.
+ (void) _ibDocument: (id <IBDocuments>) document _adjustKindsOfNSText:
(NSText *) aText
{
id parent;
if ([aText superview])
return;
parent = [document parentOfObject: aText];
if ([parent isKindOfClass: [NSScrollView class]]) {
NSClipView *aClipView = [parent contentView];
[aText setFrame: [aClipView documentVisibleRect]];
[aClipView setDocumentView: aText];
} else
NSLog(@" **** WARNING *** No idea how to adjust object %@ that
lacks a superview, but is a child of a %@ (and not a scrollvi
ew)", aText, parent);
}
The resulting palette can be used both inside of IB or at the command
line to perform the necessary conversions. It doesn't explicitly save
the modified document as that task is taken care of by one of -r, -w,
or -W for nibtool or by simply saving the document if the conversion is
performed with IB itself.
good luck!
b.bum
On Tuesday, August 20, 2002, at 12:24 PM,
email@hidden wrote:
From: "Sean McBride" <email@hidden>
Cc: <email@hidden>
Subject: regenerate a nib file from the output of nibtool?
Date: Tue, 20 Aug 2002 11:39:25 -0400
Is it possible to regenerate a nib file using the output of nibtool?
The
man page says no, but maybe there is another way?
I'm trying to edit an existing nib file (particularily the binary
objects.nib inside the bundle) programatically. With nibtool I'm able
to
find what I'm looking for, and changing the text result is easy, but
then
how to get back to the orignal format?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.