
/* 


May 18 1992
Feel free to modify this code and the application nib file to create your own preferences.

*/

#import "PreferencesManager.h"
#import "Imports.h"

@implementation PreferencesManager

- init

{
	const NXDefaultsVector TheDefaults =
		{
			{"ContinuousZoom","NO"},
			{"ContinuousUpdateSelection","NO"},
			{"ContinuousUpdateView","NO"},
			{"MinMaxDisplay","YES"},
			
			// etc., then
			
			{NULL,NULL}
		};
	
	[super init];
	NXRegisterDefaults ([NXApp appName], TheDefaults);
	[self PerformPreferences];
	return self;
}



- SavePreferences

{
	NXWriteDefault([NXApp appName],	"ContinuousZoom", [ContinuousZoomButton intValue]? "YES":"NO");
	NXWriteDefault([NXApp appName],	"ContinuousUpdateSelection", [ContinuousUpdateSelectionButton intValue]? "YES":"NO");
	NXWriteDefault([NXApp appName],	"ContinuousUpdateView", [ContinuousUpdateViewButton intValue]? "YES":"NO");
	NXWriteDefault([NXApp appName],	"MinMaxDisplay", [MinMaxDisplayButton state]? "YES":"NO");
	[self PerformPreferences];
	return self;
}



- PerformPreferences
{
 	// Then read in the defaults and adjust the buttons, etc., on the
	// preferences panel appropriately.
	
											NXGetDefaultValue ([NXApp appName],"ContinuousUpdateSelection");
	
	if (!strcmp(NXGetDefaultValue ([NXApp appName],"ContinuousZoom"), "NO"))
		{
		// Continuous Zoom is NO.
		[ContinuousZoomButton setIntValue:0];
		[TheEditController SetContinuousZoom:NO];
		}
	else
		{
		// Continuous Zoom is YES.
		[ContinuousZoomButton setIntValue:1];
		[TheEditController SetContinuousZoom:YES];
		}
		
		
	if (!strcmp(NXGetDefaultValue ([NXApp appName],"ContinuousUpdateSelection"), "NO"))
		{
		// Continuous Selection is No.
		[ContinuousUpdateSelectionButton setIntValue:0];
		}
	else
		{
		// Continuous Selection is Yes.
		[ContinuousUpdateSelectionButton setIntValue:1];
		}


	if (!strcmp(NXGetDefaultValue ([NXApp appName],"ContinuousUpdateView"), "NO"))
		{
		// Continuous View is No.
		[ContinuousUpdateViewButton setIntValue:0];
		}
	else
		{
		// Continuous View is Yes.
		[ContinuousUpdateViewButton setIntValue:1];
		}		


	if (!strcmp(NXGetDefaultValue ([NXApp appName],"MinMaxDisplay"), "YES"))
		{
		// MinMax is Yes.
		[MinMaxDisplayButton setIntValue:1];
		[OscilliscopicDisplayButton setIntValue:0];
		}
	else
		{
		// MinMax is No.
		[MinMaxDisplayButton setIntValue:0];
		[OscilliscopicDisplayButton setIntValue:1];
		}		
	
		return self;
}

- SoundComingIn						// A nicer way for the FileManager to get the Preferences to know that the
									// user has started working on sounds.  Use this as you like.
{
	[self PerformPreferences];
	return self;
}





// a preferences return item for FileController

- (BOOL) ContinuousSelection
{
	return (BOOL) (strcmp(NXGetDefaultValue ([NXApp appName],"ContinuousUpdateSelection"), "NO"));
}


// a preferences return item for FileController

- (BOOL) ContinuousView
{
	printf ("ContinuousView:  %d", (strcmp(NXGetDefaultValue ([NXApp appName],"ContinuousUpdateView"), "NO")));
	return (BOOL) (strcmp(NXGetDefaultValue ([NXApp appName],"ContinuousUpdateView"), "NO"));
}



// a preferences return item for FileController

- (int) MinMaxDisplay
{
	if  (strcmp(NXGetDefaultValue ([NXApp appName],"MinMaxDisplay"), "YES"))
		{
		printf("SKWave\n");
		return  SK_DISPLAY_WAVE;
		}
	else
		{
		printf("MINMAX\n");
		return SK_DISPLAY_MINMAX;
		}
}






- PreferencesOkayed:sender
{
	[self SavePreferences];
	[PreferencesPanel close];
	[NXApp stopModal];
	return self;
}




- StartPreferencesPanel:sender
{
	[PreferencesPanel makeKeyAndOrderFront:self];
	[self PerformPreferences];
	[NXApp runModalFor: PreferencesPanel];
	return self;
}




@end
