//
//  MyDocument.m
//  TextEditor
//
//  Created by Lieven Dekeyser on 19/11/09.
//  Copyright 2009 Lieven Dekeyser. All rights reserved.
//

#import "MyDocument.h"

@implementation MyDocument

- (id)init
{
    self = [super init];
    if (self) {
    
        // Add your subclass-specific initialization here.
        // If an error occurs here, send a [self release] message and return nil.
    
    }
    return self;
}

- (void)dealloc
{
	[mFileContents release];
	[super dealloc];
}

- (NSString *)windowNibName
{
    // Override returning the nib file name of the document
    // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
    return @"MyDocument";
}

- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
    [super windowControllerDidLoadNib:aController];
    // Add any code here that needs to be executed once the windowController has loaded the document's window.
	
	if (mFileContents != nil)
	{
		[textView setString:mFileContents];
	}
}

- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
    return [[textView string] dataUsingEncoding:NSUTF8StringEncoding];
}

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
	[mFileContents release];
	mFileContents = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    
	[textView setString:mFileContents];
	
	return mFileContents != nil;
}

@end
