Included TransformerKit for easier NSValueTransformer generation

Date picking for expiry dates now works
This commit is contained in:
michael starke
2014-03-17 18:09:58 +01:00
parent 51a59d73c6
commit 00da9013a8
29 changed files with 282 additions and 203 deletions

View File

@@ -8,7 +8,11 @@
#import "MPDatePickingViewController.h"
typedef NS_ENUM(NSUInteger, MPDatePresets) {
#import "MPDocument.h"
#import "KPKNode.h"
#import "KPKTimeInfo.h"
typedef NS_ENUM(NSUInteger, MPDatePreset) {
MPDatePresetTomorrow,
MPDatePresetOneWeek,
MPDatePresetOneMonth,
@@ -30,16 +34,18 @@ typedef NS_ENUM(NSUInteger, MPDatePresets) {
- (void)awakeFromNib {
NSMenu *presetMenu = [[NSMenu alloc] init];
NSDictionary *dateItems = @{ @(MPDatePresetTomorrow): NSLocalizedString(@"TOMORROW", ""),
@(MPDatePresetOneWeek): NSLocalizedString(@"ONE_WEEK", ""),
@(MPDatePresetOneMonth): NSLocalizedString(@"ONE_MONTH", ""),
@(MPDatePresetOneYear): NSLocalizedString(@"ONE_YEAR", "") };
for(NSNumber *tagNumber in dateItems) {
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:dateItems[tagNumber] action:NULL keyEquivalent:@""];
[item setTag:[tagNumber integerValue]];
NSUInteger tags[] = { MPDatePresetTomorrow, MPDatePresetOneWeek, MPDatePresetOneMonth, MPDatePresetOneYear };
NSArray *dateItems = @[ NSLocalizedString(@"TOMORROW", ""), NSLocalizedString(@"ONE_WEEK", ""), NSLocalizedString(@"ONE_MONTH", ""), NSLocalizedString(@"ONE_YEAR", "") ];
for(NSInteger iIndex = 0; iIndex < sizeof(tags)/sizeof(NSUInteger); iIndex++) {
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:dateItems[iIndex] action:NULL keyEquivalent:@""];
[item setTag:tags[iIndex]];
[presetMenu addItem:item];
}
MPDocument *document = [[self windowController] document];
[self.datePicker setDateValue:document.selectedItem.timeInfo.expiryTime];
[self.presetPopupButton setAction:@selector(setDatePreset:)];
[self.presetPopupButton setMenu:presetMenu];
}
@@ -54,4 +60,30 @@ typedef NS_ENUM(NSUInteger, MPDatePresets) {
id target = [NSApp targetForAction:@selector(performClose:)];
[target performClose:sender];
}
- (IBAction)setDatePreset:(id)sender {
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
MPDatePreset preset = [[sender selectedItem] tag];
switch(preset) {
case MPDatePresetTomorrow:
[offsetComponents setDay:1];
break;
case MPDatePresetOneWeek:
[offsetComponents setWeek:1];
break;
case MPDatePresetOneMonth:
[offsetComponents setMonth:1];
break;
case MPDatePresetOneYear:
[offsetComponents setYear:1];
break;
default:
break;
}
NSDate *newDate = [gregorian dateByAddingComponents:offsetComponents toDate:[NSDate date] options:0];
[self.datePicker setDateValue:newDate];
}
@end