Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Phoenix.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -52,6 +53,8 @@
B9B6A2471C5D422F009205B2 /* PropertyParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PropertyParser.h; sourceTree = "<group>"; };
B9B6A2481C5D422F009205B2 /* PropertyParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PropertyParser.m; sourceTree = "<group>"; };
B9B6A26E1C5D42D1009205B2 /* Phoenix.xcscheme */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = Phoenix.xcscheme; sourceTree = "<group>"; };
B9F1A9721CFBCF3000F45FC5 /* KATimeEstimator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KATimeEstimator.h; sourceTree = "<group>"; };
B9F1A9731CFBCF3000F45FC5 /* KATimeEstimator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KATimeEstimator.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down
41 changes: 41 additions & 0 deletions Phoenix/Phoenix.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "Property.h"
#import "PropertyParser.h"
#import "KAInitializerWriterFactory.h"
#import "KATimeEstimator.h"

@interface Phoenix()

Expand Down Expand Up @@ -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 <Property *> *properties = [parser properties];
Expand All @@ -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
17 changes: 17 additions & 0 deletions Shared Code/KATimeEstimator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// KATimeEstimator.h
// Phoenix
//
// Created by Kenneth Parker Ackerson on 5/29/16.
// Copyright © 2016 Kenneth Ackerson. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface KATimeEstimator : NSObject

- (nonnull instancetype)initWithNumberOfProperties:(NSInteger)numberOfProperties;

- (NSInteger)estimatedSecondsSaved;

@end
33 changes: 33 additions & 0 deletions Shared Code/KATimeEstimator.m
Original file line number Diff line number Diff line change
@@ -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