More Mac improvements:

Use UTF-8 for saving/getting preferences: It's more reliable.
Retain defaults in the Preferences Objective-C class.
Fill out the types for the IBOutlet
This commit is contained in:
C.W. Betts 2017-06-04 12:59:09 -06:00 committed by sa666666
parent 9dce4c9db1
commit 6c5ce1081a
3 changed files with 22 additions and 12 deletions

View File

@ -25,18 +25,18 @@
*/ */
@interface AboutBox : NSObject @interface AboutBox : NSObject
{ {
IBOutlet id appNameField; IBOutlet NSTextField *appNameField;
IBOutlet id creditsField; IBOutlet NSTextView *creditsField;
IBOutlet id versionField; IBOutlet NSTextField *versionField;
NSTimer *scrollTimer; NSTimer *scrollTimer;
float currentPosition; CGFloat currentPosition;
float maxScrollHeight; CGFloat maxScrollHeight;
NSTimeInterval startTime; NSTimeInterval startTime;
BOOL restartAtTop; BOOL restartAtTop;
} }
+ (AboutBox *)sharedInstance; + (AboutBox *)sharedInstance;
- (IBAction)showPanel:(id)sender; - (IBAction)showPanel:(id)sender;
- (void)OK:(id)sender; - (IBAction)OK:(id)sender;
@end @end

View File

@ -29,7 +29,7 @@ static AboutBox *sharedInstance = nil;
- (id)init - (id)init
{ {
if (sharedInstance) if (sharedInstance)
[self dealloc]; [self release];
else else
sharedInstance = [super init]; sharedInstance = [super init];

View File

@ -46,17 +46,27 @@ static Preferences *sharedInstance = nil;
- (id)init - (id)init
{ {
if (self = [super init]) { if (self = [super init]) {
defaults = [NSUserDefaults standardUserDefaults]; defaults = [[NSUserDefaults standardUserDefaults] retain];
sharedInstance = self; sharedInstance = self;
} }
return(self); return(self);
} }
- (void)dealloc
{
[defaults release];
if (self == sharedInstance) {
sharedInstance = nil;
}
[super dealloc];
}
- (void)setString:(const char *)key : (const char *)value - (void)setString:(const char *)key : (const char *)value
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString* theKey = [NSString stringWithCString:key encoding:NSASCIIStringEncoding]; NSString* theKey = [NSString stringWithCString:key encoding:NSUTF8StringEncoding];
NSString* theValue = [NSString stringWithCString:value encoding:NSASCIIStringEncoding]; NSString* theValue = [NSString stringWithCString:value encoding:NSUTF8StringEncoding];
[defaults setObject:theValue forKey:theKey]; [defaults setObject:theValue forKey:theKey];
[pool release]; [pool release];
@ -65,10 +75,10 @@ static Preferences *sharedInstance = nil;
- (void)getString:(const char *)key : (char *)value : (int)size - (void)getString:(const char *)key : (char *)value : (int)size
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString* theKey = [NSString stringWithCString:key encoding:NSASCIIStringEncoding]; NSString* theKey = [NSString stringWithCString:key encoding:NSUTF8StringEncoding];
NSString* theValue = [defaults objectForKey:theKey]; NSString* theValue = [defaults objectForKey:theKey];
if (theValue != nil) if (theValue != nil)
strncpy(value, [theValue cStringUsingEncoding: NSASCIIStringEncoding], size); strncpy(value, [theValue cStringUsingEncoding: NSUTF8StringEncoding], size);
else else
value[0] = 0; value[0] = 0;