A mixin class to turn any class into a Nib owner that manages the nib loading and releasing the nib resources once it is not in use.
Copyright: (C) 2004-2006 M. Uli Kusterer, all rights reserved.
- Declared in:
- ETNibOwner.h
You can use ETNibOwner or a subclass instance to easily load a nib, the instance will be set as the File's Owner proxy, and when released it will automatically release the Nib resources (e.g. the Nib top-level objects).
Once a nib owner has been instantiated, the nib isn't
loaded until
-loadNib
is invoked.
In the example below, we show how to
use ETNibOwner:
// First declare a ETNibOwner subclass to manage the nib
@interface InspectorNibOwner : ETNibOwner
@end
@implementation InspectorNibOwner
- (void) didLoadNib
{
NSLog(@"Inspector nib is now loaded and awaken");
}
@end
// Then use InspectorNibOwner to load the nib InspectorNibOwner *nibOwner = [[InspectorNibOwner alloc] initWithNibName: @"Inspector" bundle: nil]; [nibOwner loadNib]; // Will invoke -didLoadNib
When writing an EtoileUI application, the best choice is usually to use ETController (or a subclass) to manage a Nib rather than ETNibOwner directly.
To finish the Nib loading, e.g. render the AppKit view hierarchy into a layout item tree, retrieve items or views, override some aspects or reorganize the view hierarchy or the item tree, don't override -awakeFromNib but -didLoadNib which will be called once every objects in the Nib has received -awakeFromNib . When a layout item tree is built in this way, both views and windows become owned by the items in the resulting tree. Previously the view/window ownership was in relationships such as top-level objects, subviews or content views.
To render an AppKit view hierarchy packaged in a Nib
into a layout item tree,
-rebuildTopLevelObjectsWithBuilder:
can be used.
For example, ETController overrides -didLoadNib
in a vein similar to:
- (void) didLoadNib
{
[self rebuildTopLevelObjectsWithBuilder:
[ETEtoileUIBuilder builderWithObjectGraphContext: [self objectGraphContext]]];
}
For every top-level object, when
-render:
on the builder returns a new object,
-rebuildTopLevelObjectsWithBuilder:
substitutes the initial object with the new one in the top-level object array (see -topLevelObjects).
When the AppKit view hierarchy to render is in the main Nib, see [ETApplication -rebuildMainNib]
.
On instantiation with a nil Nib name, an
object which inherits from ETNibOwner automatically
loads the Nib file which is named just like the
concrete ETNibOwner subclass it is an instance of.
For example, a direct instance of the
ETNibOwner subclass "PreferencesPanel" would try
to load the Nib file named "PreferencesPanel.nib".
Will be immediately called when the Nib loading is finished.
By default, does nothing.
If you override this method, you must first call the superclass implementation.
Initializes and returns a new Nib owner for the Nib with the given name to be found in the given bundle.
The Nib name must not be a path. However it can be
nil, but then
-loadNib
will look for a Nib whose name matches the receiver
class name. See
-nibName
.
The Nib bundle will be to be the main bundle if you
pass nil.
Initializes and returns a new Nib owner which uses the receiver class name as the nib name to be found in the main bundle.
Loads the Nib file with the receiver as the owner
and returns YES on success, otherwise
returns NO and logs a failure
message.
Raises an exception if the bundle or the Nib itself cannot be found.
Loads the Nib file with the given object as the
File's Owner and returns YES on
success, otherwise returns NO and
logs a failure message.
The owner must not be nil.
Raises an exception if the bundle or the Nib itself cannot be found.
Returns the bundle to load the Nib from.
See also -initWithNibName:bundle: .
Returns the filename (minus ".nib" suffix) for the Nib file to load.
Note that, if you subclass this and the receiver was
initialized with a nil Nib name,
it will use the subclass's name. So, you *may* want to
override this to return a predetermined Nib name
if you don't expect subclasses to use identically
named Nib files.
If you override this method, you must first call the
superclass implementation and returns its
result immediately if not nil.
Converts the top-level objects of the Nib into equivalent EtoileUI constructs if possible.
For example, views or windows become layout item trees owned by the Nib.
The conversion is delegated to the given builder with
<ENibOwnerBuilder>
protocol.
The object returned by -render:
replaces the original object. When -rebuiltObjectForObject:builder:
returns nil, the original object is removed.
Invokes
-render:
on the builder with the given object as argument.
When the builder returns nil,
returns the original object, otherwise returns a
new object.
Can be overriden to customize how each object is handed to the builder and how each object returned by the builder is handed back to -rebuildTopLevelObjectsWithBuilder: .
Returns the subset of the top-level objects which are layout items.
Returns the mutable array that stores the top level objects once the nib is loaded.
Only subclasses should use this method and mutate the array.
- Declared in:
- ETNibOwner.h
ETNibOwner requires a builder that implements
this protocol. For example, see ETEtoileUIBuilder.
ETNibOwner subclasses that overrides
-rebuildTopLevelObjectsWithBuilder:
or -rebuiltObjectForObject:builder:
might have other requirements.
See also ETTransform in EtoileFoundation.
Takes an object in argument and returns a new representation or the same object.