-
Notifications
You must be signed in to change notification settings - Fork 20
/
FPTipsController.m
110 lines (97 loc) · 3.24 KB
/
FPTipsController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// FPTipsController.m
// FormulatePro
//
// Created by Andrew de los Reyes on 9/3/07.
// Copyright 2007 __MyCompanyName__. All rights reserved.
//
#import "FPTipsController.h"
#import "FPLogging.h"
static NSString *kFPShowTipsAtStartup = @"FPShowTipsAtStartup";
static NSString *kFPNextToolTip = @"FPNextToolTip";
@implementation FPTipsController
+ (void)initialize
{
NSDictionary *defaults = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES],kFPShowTipsAtStartup,
[NSNumber numberWithUnsignedInt:0],kFPNextToolTip,
nil,nil];
[[NSUserDefaultsController sharedUserDefaultsController] setInitialValues:defaults];
}
- (unsigned int)getNextTipIndexFromDefaults
{
id dict = [[NSUserDefaultsController sharedUserDefaultsController] values];
return [(NSNumber*)[dict valueForKey:kFPNextToolTip] unsignedIntValue];
}
- (void)setNextTipIndexToDefaults:(unsigned int)nextTip;
{
// NSDictionary *defaults = [NSDictionary dictionaryWithObjectsAndKeys:
// [NSNumber numberWithUnsignedInt:nextTip],kFPNextToolTip,
// nil,nil];
id values = [[NSUserDefaultsController sharedUserDefaultsController] values];
[values setValue:[NSNumber numberWithUnsignedInt:nextTip] forKey:kFPNextToolTip];
// [[NSUserDefaultsController sharedUserDefaultsController] setInitialValues:defaults];
// DLog(@"about to save\n");
// [(NSUserDefaultsController*)[NSUserDefaultsController sharedUserDefaultsController] save:self];
// DLog(@"saved\n");
}
- (void)displayTip:(unsigned int)tip
{
if (tip >= [_tips count])
tip = 0;
[_tipTextField setStringValue:[_tips objectAtIndex:tip]];
tip++;
if (tip >= [_tips count])
tip = 0;
[self setNextTipIndexToDefaults:tip];
}
- (void)awakeFromNib
{
_tips = nil;
id values = [[NSUserDefaultsController sharedUserDefaultsController] values];
NSString *path = [[NSBundle mainBundle] pathForResource:@"tips" ofType:@"plist"];
if (nil == path) {
DLog(@"unable to locate tips.plist\n");
return;
}
NSData *data = [NSData dataWithContentsOfFile:path];
if (nil == data) {
DLog(@"unable to load tips.plist\n");
return;
}
_tips = [NSPropertyListSerialization propertyListFromData:data
mutabilityOption:NSPropertyListImmutable
format:nil
errorDescription:nil];
[_tips retain];
_tipOnDisplay = [self getNextTipIndexFromDefaults];
[self displayTip:_tipOnDisplay];
if (NO == [[values valueForKey:kFPShowTipsAtStartup] boolValue])
return;
[_tipWindow center];
[_tipWindow makeKeyAndOrderFront:self];
}
- (IBAction)nextTip:(id)sender
{
_tipOnDisplay++;
if (_tipOnDisplay >= [_tips count])
_tipOnDisplay = 0;
[self displayTip:_tipOnDisplay];
}
- (IBAction)previousTip:(id)sender
{
if (_tipOnDisplay == 0)
_tipOnDisplay = [_tips count];
_tipOnDisplay--;
[self displayTip:_tipOnDisplay];
}
- (IBAction)showExportAsPDFTip:(id)sender
{
[self displayTip:2];
[_tipWindow center];
[_tipWindow makeKeyAndOrderFront:self];
}
- (void)windowWillClose:(NSNotification *)aNotification
{
}
@end