-
Notifications
You must be signed in to change notification settings - Fork 1
/
PreferencesController.m
133 lines (108 loc) · 4.48 KB
/
PreferencesController.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* Take A Pause!
* Copyright (C) 2007, Fabio Mancinelli <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import "PreferencesController.h"
NSString *TAPWorkIntervalKey = @"WorkInterval";
NSString *TAPPauseIntervalKey = @"PauseInterval";
NSString *TAPPostponeEnabledKey = @"PostponeEnabled";
NSString *TAPPostponeIntervalKey = @"PostponeInterval";
NSString *TAPGiveUpEnabledKey = @"GiveUpEnabled";
NSString *TAPRestartIfIdleKey = @"RestartIfIdle";
NSString *TAPIdleIntervalKey = @"IdleInterval";
NSString *TAPMetalGradientLookKey = @"MetalGradientLook";
@implementation PreferencesController
- (id)init{
self = [super init];
if(self != nil) {
NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
[defaultValues setObject:[NSNumber numberWithInt:50] forKey:TAPWorkIntervalKey];
[defaultValues setObject:[NSNumber numberWithInt:10] forKey:TAPPauseIntervalKey];
[defaultValues setObject:[NSNumber numberWithBool:YES] forKey:TAPPostponeEnabledKey];
[defaultValues setObject:[NSNumber numberWithInt:5] forKey:TAPPostponeIntervalKey];
[defaultValues setObject:[NSNumber numberWithBool:YES] forKey:TAPGiveUpEnabledKey];
[defaultValues setObject:[NSNumber numberWithBool:YES] forKey:TAPRestartIfIdleKey];
[defaultValues setObject:[NSNumber numberWithInt:20] forKey:TAPIdleIntervalKey];
[defaultValues setObject:[NSNumber numberWithBool:YES] forKey:TAPMetalGradientLookKey];
standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults registerDefaults:defaultValues];
itemsList = [[NSMutableDictionary alloc] init];
}
return self;
}
- (void)awakeFromNib
{
toolbar = [[[NSToolbar alloc] initWithIdentifier:@"preferences"] autorelease];
[toolbar setAllowsUserCustomization: NO];
[toolbar setAutosavesConfiguration: NO];
[toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
[toolbar setDelegate:self];
int i;
for(i = 0; i < [tabView numberOfTabViewItems]; i++) {
[itemsList setObject:[[tabView tabViewItemAtIndex:i] label]
forKey:[[tabView tabViewItemAtIndex:i] identifier]];
}
[[self window] setToolbar:toolbar];
if([toolbar selectedItemIdentifier] == nil) {
[toolbar setSelectedItemIdentifier:[[tabView tabViewItemAtIndex:0] identifier]];
}
}
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
{
NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease];
NSString *itemLabel = [itemsList objectForKey:itemIdentifier];
if(itemLabel != nil) {
[toolbarItem setLabel: itemLabel];
[toolbarItem setPaletteLabel: itemLabel];
[toolbarItem setTag:[tabView indexOfTabViewItemWithIdentifier:itemIdentifier]];
[toolbarItem setToolTip: itemLabel];
[toolbarItem setImage: [NSImage imageNamed:itemIdentifier]];
[toolbarItem setTarget: self];
[toolbarItem setAction: @selector(select:)];
}
else
{
toolbarItem = nil;
}
return toolbarItem;
}
-(IBAction)select:(id)sender
{
[tabView selectTabViewItemAtIndex:[sender tag]];
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
{
return [itemsList allKeys];
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
{
int i;
NSMutableArray *itemIdentifiers = [NSMutableArray array];
for(i = 0; i < [tabView numberOfTabViewItems]; i++){
[itemIdentifiers addObject:[[tabView tabViewItemAtIndex:i] identifier]];
}
return itemIdentifiers;
}
-(NSArray*) toolbarSelectableItemIdentifiers: (NSToolbar*)toolbar
{
return [itemsList allKeys];
}
- (void)dealloc
{
[itemsList release];
[super dealloc];
}
@end