From 49b797222d0dda7868e5b6ce566723fe2a6248f1 Mon Sep 17 00:00:00 2001 From: Stuart Connolly Date: Sun, 19 Jan 2014 03:57:43 +0000 Subject: Display the short revision hash of the build alongside the revision number in the about dialog. --- Source/SPAboutController.m | 54 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) (limited to 'Source') diff --git a/Source/SPAboutController.m b/Source/SPAboutController.m index c1a5c30a..921e0b83 100644 --- a/Source/SPAboutController.m +++ b/Source/SPAboutController.m @@ -35,13 +35,22 @@ static NSString *SPCreditsFilename = @"Credits"; static NSString *SPLicenseFilename = @"License"; +static NSString *SPAboutPanelNibName = @"AboutPanel"; +static NSString *SPShortVersionHashKey = @"SPVersionShortHash"; + +@interface SPAboutController () + +- (void)_setVersionLabel:(BOOL)isNightly; + +@end + @implementation SPAboutController #pragma mark - - (id)init { - return [super initWithWindowNibName:@"AboutPanel"]; + return [super initWithWindowNibName:SPAboutPanelNibName]; } - (void)awakeFromNib @@ -52,10 +61,9 @@ static NSString *SPLicenseFilename = @"License"; BOOL isNightly = [version hasPrefix:@"Nightly"]; // Set the application name, but only include the major version if this is not a nightly build. - [appNameVersionTextField setStringValue:(isNightly) ? @"Sequel Pro" : [NSString stringWithFormat:@"Sequel Pro %@", version]]; - - // Set the bundle/build version - [appBuildVersionTextField setStringValue:[NSString stringWithFormat:@"%@ %@", (isNightly) ? NSLocalizedString(@"Nightly Build", @"nightly build label") : NSLocalizedString(@"Build", @"build label") , [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]]; + [appNameVersionTextField setStringValue:isNightly ? @"Sequel Pro" : [NSString stringWithFormat:@"Sequel Pro %@", version]]; + + [self _setVersionLabel:isNightly]; // Get the credits file contents NSAttributedString *credits = [[[NSAttributedString alloc] initWithPath:[[NSBundle mainBundle] pathForResource:SPCreditsFilename ofType:@"rtf"] documentAttributes:nil] autorelease]; @@ -90,4 +98,40 @@ static NSString *SPLicenseFilename = @"License"; [appLicensePanel orderOut:self]; } +#pragma mark - +#pragma mark Private API + +/** + * Set the UI version labels. + * + * @param isNightly Indicates whether or not this is a nightly build. + */ +- (void)_setVersionLabel:(BOOL)isNightly +{ + NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; + + // Get version numbers + NSString *bundleVersion = [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey]; + NSString *versionHash = [infoDictionary objectForKey:SPShortVersionHashKey]; + + BOOL hashIsEmpty = !versionHash && ![versionHash length]; + + NSString *textFieldString; + + if (!bundleVersion && ![bundleVersion length] && hashIsEmpty) { + textFieldString = @""; + } + else { + textFieldString = + [NSString stringWithFormat:@"%@ %@%@", + isNightly ? NSLocalizedString(@"Nightly Build", @"nightly build label") : NSLocalizedString(@"Build", @"build label"), + bundleVersion, + hashIsEmpty ? @"" : [NSString stringWithFormat:@" (%@)", versionHash]]; + } + + NSLog(@"%@", textFieldString); + + [appBuildVersionTextField setStringValue:textFieldString]; +} + @end -- cgit v1.2.3