forked from opa334/AltList
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATLApplicationListMultiSelectionController.m
88 lines (74 loc) · 2.16 KB
/
ATLApplicationListMultiSelectionController.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
#import <Foundation/Foundation.h>
#import "ATLApplicationListMultiSelectionController.h"
#import "PSSpecifier+AltList.h"
@implementation ATLApplicationListMultiSelectionController
- (void)loadPreferences
{
PSSpecifier* specifier = [self specifier];
if([specifier atl_hasValidGetter])
{
_selectedApplications = [NSMutableSet setWithArray:[specifier atl_performGetter]];
}
if(!_selectedApplications)
{
NSArray* defaultValue = [specifier propertyForKey:@"default"];
if(defaultValue && [defaultValue isKindOfClass:[NSArray class]])
{
_selectedApplications = [NSMutableSet setWithArray:defaultValue];
}
else
{
_selectedApplications = [NSMutableSet new];
}
}
}
- (void)savePreferences
{
PSSpecifier* specifier = [self specifier];
if([specifier atl_hasValidSetter])
{
[specifier atl_performSetterWithValue:[_selectedApplications allObjects]];
}
}
- (void)prepareForPopulatingSections
{
[super prepareForPopulatingSections];
NSNumber* defaultApplicationValueNum = [[self specifier] propertyForKey:@"defaultApplicationSwitchValue"];
_defaultApplicationSwitchValue = [defaultApplicationValueNum boolValue];
}
- (void)setApplicationEnabled:(NSNumber*)enabledNum specifier:(PSSpecifier*)specifier
{
NSString* applicationID = [specifier propertyForKey:@"applicationIdentifier"];
if([enabledNum boolValue] != _defaultApplicationSwitchValue)
{
[_selectedApplications addObject:applicationID];
}
else
{
[_selectedApplications removeObject:applicationID];
}
[self savePreferences];
}
- (id)readApplicationEnabled:(PSSpecifier*)specifier
{
NSString* applicationID = [specifier propertyForKey:@"applicationIdentifier"];
BOOL applicationSelected = [_selectedApplications containsObject:applicationID];
if(applicationSelected)
{
return @(!_defaultApplicationSwitchValue);
}
return @(_defaultApplicationSwitchValue);
}
- (PSCellType)cellTypeForApplicationCells
{
return PSSwitchCell;
}
- (SEL)getterForSpecifierOfApplicationProxy:(LSApplicationProxy*)applicationProxy
{
return @selector(readApplicationEnabled:);
}
- (SEL)setterForSpecifierOfApplicationProxy:(LSApplicationProxy*)applicationProxy
{
return @selector(setApplicationEnabled:specifier:);
}
@end