//
//  TKPreview.m
//  ThemeKit
//
//  Created by Colin Cornaby on 12/13/04.
//  Copyright 2004 __MyCompanyName__. All rights reserved.
//

#import "TKPreview.h"


@implementation TKPreview

-(NSString *)html
{
	return myHTML;
}

-(id)htmlFiles
{
	return myFiles;
}

-(id)init
{
	[super init];
	myHTML = @"";
	myFiles = [[NSMutableDictionary alloc] init];
	return self;
}

-(void)setHTML:(NSString *)newHTML
{
	[myHTML release];
	myHTML = [newHTML retain];
}

-(void)addFile:(NSData *)newFile withName:(NSString *)name
{
	[myFiles setObject:[newFile retain] forKey:name];
}

-(void)loadIntoWebFrame:(WebFrame *)theFrame;
{
	[[NSFileManager defaultManager] createDirectoryAtPath:@"/tmp/themetemp" attributes:nil];
	[myHTML writeToFile:@"/tmp/themetemp/Index.html" atomically:NO];
	int i=0;
	for(i=0;i<[[myFiles allKeys] count];i++)
	{
		[[[myFiles allValues] objectAtIndex:i] writeToFile:[NSString stringWithFormat:@"/tmp/themetemp/%@", [[myFiles allKeys] objectAtIndex:i]] atomically:NO];
	}
	[theFrame loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:@"/tmp/themetemp/Index.html"]]];
}

- (void)encodeWithCoder:(NSCoder *)coder
{
	[coder encodeObject:myHTML forKey:@"html"];
    [coder encodeObject:myFiles forKey:@"myFiles"];
}

- (id)initWithCoder:(NSCoder *)coder
{
    myHTML = [[coder decodeObjectForKey:@"html"] retain];
    myFiles = [[coder decodeObjectForKey:@"myFiles"] retain];
	return self;
}

-(void)removeFileAtIndex:(int)theIndex
{
	[myFiles removeObjectForKey:[[myFiles allKeys] objectAtIndex:theIndex]];
}

@end
