diff --git a/Phoenix.xcodeproj/project.pbxproj b/Phoenix.xcodeproj/project.pbxproj index 71dd8d5..87bee9a 100644 --- a/Phoenix.xcodeproj/project.pbxproj +++ b/Phoenix.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ B9B6A2501C5D422F009205B2 /* Property.m in Sources */ = {isa = PBXBuildFile; fileRef = B9B6A2461C5D422F009205B2 /* Property.m */; }; B9B6A2511C5D422F009205B2 /* PropertyParser.m in Sources */ = {isa = PBXBuildFile; fileRef = B9B6A2481C5D422F009205B2 /* PropertyParser.m */; }; B9B6A26F1C5D42D1009205B2 /* Phoenix.xcscheme in Resources */ = {isa = PBXBuildFile; fileRef = B9B6A26E1C5D42D1009205B2 /* Phoenix.xcscheme */; }; + B9F1A9741CFBCF3000F45FC5 /* KATimeEstimator.m in Sources */ = {isa = PBXBuildFile; fileRef = B9F1A9731CFBCF3000F45FC5 /* KATimeEstimator.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -52,6 +53,8 @@ B9B6A2471C5D422F009205B2 /* PropertyParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PropertyParser.h; sourceTree = ""; }; B9B6A2481C5D422F009205B2 /* PropertyParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PropertyParser.m; sourceTree = ""; }; B9B6A26E1C5D42D1009205B2 /* Phoenix.xcscheme */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = Phoenix.xcscheme; sourceTree = ""; }; + B9F1A9721CFBCF3000F45FC5 /* KATimeEstimator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KATimeEstimator.h; sourceTree = ""; }; + B9F1A9731CFBCF3000F45FC5 /* KATimeEstimator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KATimeEstimator.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -136,6 +139,8 @@ B9B6A2461C5D422F009205B2 /* Property.m */, B9B6A2471C5D422F009205B2 /* PropertyParser.h */, B9B6A2481C5D422F009205B2 /* PropertyParser.m */, + B9F1A9721CFBCF3000F45FC5 /* KATimeEstimator.h */, + B9F1A9731CFBCF3000F45FC5 /* KATimeEstimator.m */, ); path = "Shared Code"; sourceTree = SOURCE_ROOT; @@ -219,6 +224,7 @@ B9B6A24D1C5D422F009205B2 /* KAWarning+Properties.m in Sources */, B9B6A2191C5D40CC009205B2 /* Phoenix.m in Sources */, B9B6A24B1C5D422F009205B2 /* KAPropertyWarningGenerator.m in Sources */, + B9F1A9741CFBCF3000F45FC5 /* KATimeEstimator.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Phoenix/Phoenix.m b/Phoenix/Phoenix.m index 4bcb96a..0667cba 100755 --- a/Phoenix/Phoenix.m +++ b/Phoenix/Phoenix.m @@ -10,6 +10,7 @@ #import "Property.h" #import "PropertyParser.h" #import "KAInitializerWriterFactory.h" +#import "KATimeEstimator.h" @interface Phoenix() @@ -66,9 +67,39 @@ - (void)didApplicationFinishLaunchingNotification:(NSNotification *)noti { [actionMenuItem setTarget:self]; [[menuItem submenu] addItem:actionMenuItem]; + + NSMenuItem *secondsActionMenuItem = [[NSMenuItem alloc] initWithTitle:@"Phoenix stats" action:@selector(seconds) keyEquivalent:@""]; + + [secondsActionMenuItem setTarget:self]; + [[menuItem submenu] addItem:secondsActionMenuItem]; } } +- (void)seconds { + NSAlert *alert = [[NSAlert alloc] init]; + + const NSInteger seconds = [[NSUserDefaults standardUserDefaults] integerForKey:@"seconds_saved"]; + + NSString *displayString = [NSString stringWithFormat:@"Time saved: %ld seconds", seconds]; + + // This is super shitty code /shrug + + if (seconds > 60) { + displayString = [NSString stringWithFormat:@"Time saved: %0.2f minutes", seconds / 60.0]; + } + + if (seconds > 60 * 60) { + displayString = [NSString stringWithFormat:@"Time saved: %0.2f hours", (seconds / 60.0) / 60]; + } + + if (seconds > 60 * 60 * 24) { + displayString = [NSString stringWithFormat:@"Time saved: %0.2f day", ((seconds / 60.0) / 60) / 24]; + } + + [alert setMessageText:displayString]; + [alert runModal]; +} + - (void)doMenuAction { const PropertyParser *parser = [[PropertyParser alloc] initWithString:self.currentlySelectedText]; NSArray *properties = [parser properties]; @@ -87,9 +118,19 @@ - (void)doMenuAction { NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; [pasteboard clearContents]; [pasteboard writeObjects:@[initializer]]; + + KATimeEstimator *timeEstimator = [[KATimeEstimator alloc] initWithNumberOfProperties:properties.count]; + + const NSInteger currentSeconds = [[NSUserDefaults standardUserDefaults] integerForKey:@"seconds_saved"]; + + const NSInteger seconds = [timeEstimator estimatedSecondsSaved]; + + [[NSUserDefaults standardUserDefaults] setInteger:currentSeconds + seconds forKey:@"seconds_saved"]; + [[NSUserDefaults standardUserDefaults] synchronize]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } + @end diff --git a/Shared Code/KATimeEstimator.h b/Shared Code/KATimeEstimator.h new file mode 100644 index 0000000..b888a9a --- /dev/null +++ b/Shared Code/KATimeEstimator.h @@ -0,0 +1,17 @@ +// +// KATimeEstimator.h +// Phoenix +// +// Created by Kenneth Parker Ackerson on 5/29/16. +// Copyright © 2016 Kenneth Ackerson. All rights reserved. +// + +#import + +@interface KATimeEstimator : NSObject + +- (nonnull instancetype)initWithNumberOfProperties:(NSInteger)numberOfProperties; + +- (NSInteger)estimatedSecondsSaved; + +@end diff --git a/Shared Code/KATimeEstimator.m b/Shared Code/KATimeEstimator.m new file mode 100644 index 0000000..08855d0 --- /dev/null +++ b/Shared Code/KATimeEstimator.m @@ -0,0 +1,33 @@ +// +// KATimeEstimator.m +// Phoenix +// +// Created by Kenneth Parker Ackerson on 5/29/16. +// Copyright © 2016 Kenneth Ackerson. All rights reserved. +// + +#import "KATimeEstimator.h" + +@interface KATimeEstimator () + +@property (nonatomic, readonly) NSInteger numberOfProperties; + +@end + +@implementation KATimeEstimator + +- (instancetype)initWithNumberOfProperties:(NSInteger)numberOfProperties { + self = [super init]; + + if (self) { + _numberOfProperties = numberOfProperties; + } + + return self; +} + +- (NSInteger)estimatedSecondsSaved { + return self.numberOfProperties * 4; // 4 seconds per property - probably low, but this is just estimated. +} + +@end