

#import "MiscMMAProcessor.h"
#import "MiscMMAView.h"

#import "AppController.h"

@implementation AppController

- init
{
	[super init];
	mmaProcessor = [[MiscMMAProcessor alloc] init];
	return self;
}

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

- (void)evaluate:(id)sender
{
	NSString *expr = [expressionTextfield stringValue];
	NSDictionary *result;
	id resultComponent;

	if(!expr){
		NSBeep();
		return;
	}

	[mmaProcessor enterExpression:expr];
	result = [mmaProcessor readReturn];
	
	resultComponent = [result objectForKey:@"Error"];
	if(resultComponent){
		[statusTextfield setStringValue:resultComponent];
		return;
	}

	resultComponent = [result objectForKey:@"Syntax"];
	if(resultComponent){
		[statusTextfield setStringValue:resultComponent];
		return;
	}

	resultComponent = [result objectForKey:@"Plot"];
	if(resultComponent)
        	[mmaView setPostScriptData:resultComponent];

	resultComponent = [result objectForKey:@"Text"];
	if(resultComponent)                
		[resultTextView setString:resultComponent];

	[statusTextfield setStringValue:@""];
}
	

@end
