Merge pull request #10 from gunyarakun/fix-invalid-return
[cocotron.git] / AppKit / NSViewController.m
blob143a304c238682a087a57fde4b07f9a75d4851b3
1 #import <AppKit/NSViewController.h>
2 #import <AppKit/NSNibLoading.h>
3 #import <AppKit/NSNib.h>
4 #import <AppKit/NSRaise.h>
6 @implementation NSViewController
8 -initWithNibName:(NSString *)name bundle:(NSBundle *)bundle {
9    _nibName=[name copy];
10    _nibBundle=[bundle retain];
11    return self;
14 -initWithCoder:(NSCoder *)coder {
15    if([coder allowsKeyedCoding]){
16     _nibName=[[coder decodeObjectForKey:@"NSNibName"] copy];
17     _title=[[coder decodeObjectForKey:@"NSTitle"] copy];
18     NSString *bundleIdentifier=[coder decodeObjectForKey:@"NSNibBundleIdentifier"];
19     if(bundleIdentifier!=nil)
20      _nibBundle=[NSBundle bundleWithIdentifier:bundleIdentifier];
21    }
22    
23    return self;
26 -(NSString *)nibName {
27    return _nibName;
30 -(NSBundle *)nibBundle {
31    return _nibBundle;
34 -(NSView *)view {
35    if(_view==nil)
36     [self loadView];
37     
38    return _view;
41 -(NSString *)title {
42    return _title;
45 -representedObject {
46    return _representedObject;
49 -(void)setRepresentedObject:object {
50    object=[object retain];
51    [_representedObject release];
52    _representedObject=object;
55 -(void)setTitle:(NSString *)value {
56    value=[value retain];
57    [_title release];
58    _title=value;
61 -(void)setView:(NSView *)value {
62    value=[value retain];
63    [_view release];
64    _view=value;
67 -(void)loadView {
68    NSString *name=[self nibName];
69    NSBundle *bundle=[self nibBundle];
71    if(name==nil){
72    // should pathForResource assert name for non-nil?
73     [NSException raise:NSInvalidArgumentException format:@"-[%@ %s] nibName is nil",isa,_cmd];
74     return;
75    }
76    
77    if(bundle==nil)
78     bundle=[NSBundle mainBundle];
80    NSString     *path=[bundle pathForResource:name ofType:@"nib"];
81    NSDictionary *nameTable=[NSDictionary dictionaryWithObject:self forKey:NSNibOwner];
83    if(path==nil)
84     NSLog(@"NSViewController unable to find nib named %@, bundle=%@",name,bundle);    
86    [bundle loadNibFile:path externalNameTable:nameTable withZone:NULL];
89 -(void)discardEditing {
90    NSUnimplementedMethod();
93 -(BOOL)commitEditing {
94    NSUnimplementedMethod();
95    return NO;
98 -(void)commitEditingWithDelegate:delegate didCommitSelector:(SEL)didCommitSelector contextInfo:(void *)contextInfo {
99    NSUnimplementedMethod();
102 @end