/* --------------------------------------------------------------------------

Class:			PHEvenPageTool
Version:		0.1
File:			PHEvenPageTool.m				 

Written by:		Thomas Engel
Created:		17.05.1995	(Copyleft)
Last modified:	17.05.1995


Note:	For a detailed description please read the class documentation.

 ------------------------------------------------------------------------- */

#import < PHEvenPageTool.h>
#import <misckit/MiscString.h>

@implementation PHEvenPageTool

- image
{
	return [NXImage findImageNamed:"EvenPageTool"];
}

- (BOOL)canProcess:aFile for:aController
{
	id	filetype;
	BOOL	result;
	
	// Let super store some data...but we don't care if it can open it or not.

	[super canProcess:aFile for:aController];

	result = NO;
	filetype = [aFile fileExtension];

	if( [filetype cmp:"ps"] == 0 )
		result = YES;
	[filetype free];

	return result;
}

- revert:sender
{
	if( !view )
	{
		if( [NXApp loadNibSection:"EvenPageTool.nib" owner:self] == nil )
			NXRunAlertPanel( NULL, "Couldn't load EvenPageTool.nib",
							 "OK", NULL, NULL );

	}
	// Tell the processController about the filetype we will create. That is 
	// always the packed .bit

	[processController setOutputExtension:
		[MiscString newWithString:"even.ps"]];
	
	return [super view];
}

- processInput:inPath forOutput:outPath
{
	id	execString;

	execString = [MiscString new];

	[execString setStringValue:"cd $mainBundle; "];
	[execString cat:"psselect -e \""];
	[execString concatenate:inPath];
	[execString cat:"\""];

	// If the outfile is missing we are in deep trouble IMHO.

	[execString cat:" \""];
	[execString concatenate:outPath];
	[execString cat:"\""];

	NXLogError( [execString stringValue] );
	[activeShell executeFromStringValue:execString];

	[execString free];
	return self;
}

- startProcessing:sender
{
	if( ![super startProcessing:sender] )
		return nil;

	[startButton setImage:[NXImage findImageNamed:"StopProcess"]];
	[startButton setAction:@selector(stopProcessing:)];

	return self;
}

- stopProcessing:sender
{
	[super stopProcessing:sender];

	[startButton setImage:[NXImage findImageNamed:"StartFilterProcess"]];
	[startButton setAction:@selector(startProcessing:)];

	return self;
}

@end