Cleanups to some OSX-specific code; the version # no longer appears next to

the name in the OSX menu.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1890 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2009-10-27 18:05:19 +00:00
parent aaf30c2f28
commit 174efe684d
4 changed files with 91 additions and 101 deletions

View File

@ -14,18 +14,17 @@ static AboutBox *sharedInstance = nil;
+ (AboutBox *)sharedInstance
{
return sharedInstance ? sharedInstance : [[self alloc] init];
return sharedInstance ? sharedInstance : [[self alloc] init];
}
- (id)init
{
if (sharedInstance) {
[self dealloc];
} else {
sharedInstance = [super init];
}
if (sharedInstance)
[self dealloc];
else
sharedInstance = [super init];
return sharedInstance;
return sharedInstance;
}
/*------------------------------------------------------------------------------
@ -33,88 +32,79 @@ static AboutBox *sharedInstance = nil;
*-----------------------------------------------------------------------------*/
- (IBAction)showPanel:(id)sender
{
NSRect creditsBounds;
if (!appNameField)
NSRect creditsBounds;
if (!appNameField)
{
NSWindow *theWindow;
NSString *creditsPath;
NSAttributedString *creditsString;
NSString *appName;
NSString *versionString;
NSDictionary *infoDictionary;
CFBundleRef localInfoBundle;
NSDictionary *localInfoDict;
if (![NSBundle loadNibNamed:@"AboutBox" owner:self])
{
NSWindow *theWindow;
NSString *creditsPath;
NSAttributedString *creditsString;
NSString *appName;
NSString *versionString;
NSDictionary *infoDictionary;
CFBundleRef localInfoBundle;
NSDictionary *localInfoDict;
if (![NSBundle loadNibNamed:@"AboutBox" owner:self])
{
NSLog( @"Failed to load AboutBox.nib" );
NSBeep();
return;
}
theWindow = [appNameField window];
// Get the info dictionary (Info.plist)
infoDictionary = [[NSBundle mainBundle] infoDictionary];
// Get the localized info dictionary (InfoPlist.strings)
localInfoBundle = CFBundleGetMainBundle();
localInfoDict = (NSDictionary *)
CFBundleGetLocalInfoDictionary( localInfoBundle );
// Setup the app name field
appName = @"StellaOSX";
[appNameField setStringValue:appName];
// Set the about box window title
[theWindow setTitle:[NSString stringWithFormat:@"About %@", appName]];
// Setup the version field
versionString = [infoDictionary objectForKey:@"CFBundleVersion"];
[versionField setStringValue:[NSString stringWithFormat:@"Version %@",
versionString]];
// Setup our credits
creditsPath = [[NSBundle mainBundle] pathForResource:@"Credits"
ofType:@"html"];
creditsString = [[NSAttributedString alloc] initWithPath:creditsPath
documentAttributes:nil];
[creditsField replaceCharactersInRange:NSMakeRange( 0, 0 )
withRTF:[creditsString RTFFromRange:
NSMakeRange( 0, [creditsString length] )
documentAttributes:nil]];
// Prepare some scroll info
creditsBounds = [creditsField bounds];
maxScrollHeight = creditsBounds.size.height*2.75;
// Setup the window
[theWindow setExcludedFromWindowsMenu:YES];
[theWindow setMenu:nil];
[theWindow center];
NSLog( @"Failed to load AboutBox.nib" );
NSBeep();
return;
}
theWindow = [appNameField window];
// Get the info dictionary (Info.plist)
infoDictionary = [[NSBundle mainBundle] infoDictionary];
// Get the localized info dictionary (InfoPlist.strings)
localInfoBundle = CFBundleGetMainBundle();
localInfoDict = (NSDictionary *) CFBundleGetLocalInfoDictionary( localInfoBundle );
// Setup the app name field
appName = @"StellaOSX";
[appNameField setStringValue:appName];
// Set the about box window title
[theWindow setTitle:[NSString stringWithFormat:@"About %@", appName]];
// Setup the version field
versionString = [infoDictionary objectForKey:@"CFBundleVersion"];
[versionField setStringValue:[NSString stringWithFormat:@"Version %@", versionString]];
// Setup our credits
creditsPath = [[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"html"];
creditsString = [[NSAttributedString alloc] initWithPath:creditsPath documentAttributes:nil];
[creditsField replaceCharactersInRange:NSMakeRange( 0, 0 )
withRTF:[creditsString RTFFromRange:
NSMakeRange( 0, [creditsString length] )
documentAttributes:nil]];
// Prepare some scroll info
creditsBounds = [creditsField bounds];
maxScrollHeight = creditsBounds.size.height*2.75;
// Setup the window
[theWindow setExcludedFromWindowsMenu:YES];
[theWindow setMenu:nil];
[theWindow center];
}
if (![[appNameField window] isVisible])
{
currentPosition = 0;
restartAtTop = NO;
[creditsField scrollPoint:NSMakePoint( 0, 0 )];
}
if (![[appNameField window] isVisible])
{
currentPosition = 0;
restartAtTop = NO;
[creditsField scrollPoint:NSMakePoint( 0, 0 )];
}
// Show the window
[NSApp runModalForWindow:[appNameField window]];
[[appNameField window] close];
// Show the window
[NSApp runModalForWindow:[appNameField window]];
[[appNameField window] close];
}
- (void)OK:(id)sender
{
[NSApp stopModal];
[NSApp stopModal];
}
@end

View File

@ -33,7 +33,7 @@
<key>CFBundleExecutable</key>
<string>StellaOSX</string>
<key>CFBundleGetInfoString</key>
<string>StellaOSX 3.0</string>
<string>StellaOSX</string>
<key>CFBundleHelpBookFolder</key>
<string>docs</string>
<key>CFBundleHelpBookName</key>
@ -45,13 +45,13 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>StellaOSX 3.0</string>
<string>StellaOSX</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>StLa</string>
<key>CFBundleVersion</key>
<string>StellaOSX 3.0</string>
<string>3.0</string>
<key>NSMainNibFile</key>
<string>SDLMain.nib</string>
<key>NSPrincipalClass</key>

View File

@ -10,8 +10,9 @@
/* $Id$ */
#import <Cocoa/Cocoa.h>
@interface Preferences : NSObject {
NSUserDefaults *defaults; /* Defaults pointer */
@interface Preferences : NSObject
{
NSUserDefaults *defaults; /* Defaults pointer */
}
+ (Preferences *)sharedInstance;

View File

@ -15,38 +15,39 @@
void prefsSetString(const char* key, const char* value)
{
[[Preferences sharedInstance] setString:key:value];
[[Preferences sharedInstance] setString:key:value];
}
void prefsGetString(const char* key, char* value, int size)
{
[[Preferences sharedInstance] getString:key:value:size];
[[Preferences sharedInstance] getString:key:value:size];
}
void prefsSave(void)
{
[[Preferences sharedInstance] save];
[[Preferences sharedInstance] save];
}
@implementation Preferences
static Preferences *sharedInstance = nil;
+ (Preferences *)sharedInstance {
return sharedInstance ? sharedInstance : [[self alloc] init];
+ (Preferences *)sharedInstance
{
return sharedInstance ? sharedInstance : [[self alloc] init];
}
- (id)init
{
defaults = [NSUserDefaults standardUserDefaults];
sharedInstance = self;
return(self);
defaults = [NSUserDefaults standardUserDefaults];
sharedInstance = self;
return(self);
}
- (void)setString:(const char *)key:(const char *)value
{
NSString* theKey = [NSString stringWithCString:key encoding:NSASCIIStringEncoding];
NSString* theValue = [NSString stringWithCString:value encoding:NSASCIIStringEncoding];
NSString* theValue = [NSString stringWithCString:value encoding:NSASCIIStringEncoding];
[defaults setObject:theValue forKey:theKey];
[theKey release];
@ -56,10 +57,10 @@ static Preferences *sharedInstance = nil;
- (void)getString:(const char *)key:(char *)value:(int)size
{
NSString* theKey = [NSString stringWithCString:key encoding:NSASCIIStringEncoding];
NSString* theValue = [defaults objectForKey:theKey];
if (theValue != nil)
NSString* theValue = [defaults objectForKey:theKey];
if (theValue != nil)
strncpy(value, [theValue cStringUsingEncoding: NSASCIIStringEncoding], size);
else
else
value[0] = 0;
[theKey release];
@ -68,9 +69,7 @@ static Preferences *sharedInstance = nil;
- (void)save
{
[defaults synchronize];
[defaults synchronize];
}
@end