#import "DocumentController.h"
#import "StringStorage.h"
#import <appkit/Application.h>
#import <appkit/nextstd.h>
#import <objc/NXBundle.h>
#import <sys/param.h>

@implementation DocumentController

- init
{
   [super init];

   _docType = [[StringStorage alloc] init];
   panel = nil;
   return self;
}

-free
{
   _docType = [_docType free];
   panel = [panel free];
   return [super free];
}


- setDocType: (const char *) str
{
   [_docType setStringValue: str];
   return self;
}


- makeKeyAndOrderFront:sender
{
   if(![self loadNib])
       return nil;

   [panel makeKeyAndOrderFront: sender];
   return self;
}



- loadNib
{
   if(!panel)
   {
      char buf[MAXPATHLEN + 1];

      if(!*[_docType stringValue])
	  [_docType setStringValue: [self name]];

      if(![[NXBundle bundleForClass:[self class]] 
            getPath: buf forResource: [_docType stringValue] ofType:"nib"])
      {
	 NXLogError("Could not find %s.nib\n",[_docType stringValue]);
	 return nil;
      }
      
   
      [NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];
   }
   return self;
}

   
@end
