//*****************************************************************************
//
//	PanelController.h.  
//
//		Preferences logic.
//
//			by	Felipe A. Rodriguez		
//
//	This code is supplied "as is" the author makes no warranty as to its 
//	suitability for any purpose.  This code is free and may be distributed 
//	in accordance with the terms of the:
//		
//			GNU GENERAL PUBLIC LICENSE
//			Version 2, June 1991
//			copyright (C) 1989, 1991 Free Software Foundation, Inc.
// 			675 Mass Ave, Cambridge, MA 02139, USA
//
//*****************************************************************************

#import "InactivityPanelController.h"
#import "../Coordinator.h"


 

@implementation InactivityPanelController

//*****************************************************************************
//
//		sent to us after nib objects are unarchived and init'd 
//
//*****************************************************************************
 
- awakeFromNib
{
	[self timeout:self];				// set timeout circ slide/text field

    return self;
}
//*****************************************************************************
//
//		returns the inspector panel we control
//
//*****************************************************************************

- inspectorPanel
{
    return 	[timeoutField window];
}
//*****************************************************************************
//
// 		target of timeout circular slider 
//
//*****************************************************************************

- timeout:sender
{
static char buf[8];
int timeout;

	if(sender == self) 							// if initial display of pref
		timeout = atoi(NXGetDefaultValue([NXApp appName], "iTimeout"));
	else										// else user changed control
		{
		timeout = [sender intValue];
		sprintf(buf,"%d",(int)timeout);
		if(!NXWriteDefault([NXApp appName], "iTimeout", buf))
			[[NXApp delegate] showAlert:"ddbWriteError"];
		}
	if(timeout == 0)
		[timeoutField setStringValue:"Off"];
	else
		[timeoutField setIntValue:timeout];
	[timeoutCircSlider setIntValue:timeout];

    return self;
}
//*********************** text field matrix delegation ************************
//*****************************************************************************
//
// 		as text delegate we recieve this when textfield cell is being edited 
//
//*****************************************************************************

- (BOOL)textWillChange:textObject
{
	[[timeoutField window] setDocEdited:YES];	// indicate change is not saved

    return NO;
}
//*****************************************************************************
//
// 		text delegate receives when editing of textfield cell is ended 
//
//*****************************************************************************

- textDidEnd:textObject endChar:(unsigned short)whyEnd
{
    if ((whyEnd == 16) || (whyEnd == 17)) 
		[[timeoutField window] setDocEdited:NO];	// indicate change is saved

    return self;
}

@end
