forked from hac/googlebookdownloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HacPrefsController.m
82 lines (60 loc) · 2.55 KB
/
HacPrefsController.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
#import "HacPrefsController.h"
#define defaultBookWidth 1000
@implementation HacPrefsController
- (void)awakeFromNib
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// These are the default preferences:
NSDictionary *defaultDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:defaultBookWidth], @"BookWidth",
[NSNumber numberWithBool:NO], @"UseCustomPageWidth",
[NSNumber numberWithBool:YES], @"AutoOpenDownloadsInFinder",
[NSNumber numberWithBool:NO], @"DonateAlertShown",
[NSNumber numberWithInt:10], @"ZoomLevel", nil];
[defaults registerDefaults:defaultDictionary];
[openBookInFinderAfterSaving setState:[defaults boolForKey:@"AutoOpenDownloadsInFinder"]];
[documentWidth setIntValue:[defaults integerForKey:@"BookWidth"]];
[widthPrefsMatrix setState:![defaults boolForKey:@"UseCustomPageWidth"]
atRow:1
column:0];
[zoomLeverSlider setIntValue:[defaults integerForKey:@"ZoomLevel"]];
[documentWidth setDelegate:self];
[[documentWidth window] setDelegate:self];
}
- (IBAction)savePrefs:(id)sender
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (sender == openBookInFinderAfterSaving)
[defaults setBool:[openBookInFinderAfterSaving state] forKey:@"AutoOpenDownloadsInFinder"];
if (sender == documentWidth)
[defaults setInteger:[documentWidth intValue] forKey:@"BookWidth"];
if (![documentWidth intValue])
[documentWidth setIntValue:defaultBookWidth];
else
[documentWidth setIntValue:[documentWidth intValue]];
if (sender == zoomLeverSlider)
[defaults setInteger:[zoomLeverSlider intValue] forKey:@"ZoomLevel"];
[defaults setBool:![widthPrefsMatrix selectedRow] forKey:@"UseCustomPageWidth"];
[documentWidth setEnabled:![widthPrefsMatrix selectedRow]];
[self controlTextDidChange:nil];
}
#pragma mark -
#pragma mark Delegate Methods
- (void)controlTextDidChange:(NSNotification *)aNotification
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([documentWidth intValue] && [[[NSNumber numberWithInt:[documentWidth intValue]] stringValue] isEqualToString:[documentWidth stringValue]])
[documentWidth setTextColor:[NSColor blackColor]];
else
[documentWidth setTextColor:[NSColor colorWithDeviceRed:.8 green:0 blue:0 alpha:1]];
[defaults setInteger:[documentWidth intValue] forKey:@"BookWidth"];
}
- (void)windowDidBecomeKey:(NSNotification *)notification
{
[self savePrefs:nil];
}
- (void)windowDidResignKey:(NSNotification *)notification
{
[self savePrefs:nil];
}
@end