-
Notifications
You must be signed in to change notification settings - Fork 11
/
SyntaxSelectorViewController.xm
117 lines (96 loc) · 4.42 KB
/
SyntaxSelectorViewController.xm
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
#import "SyntaxSelectorViewController.h"
#import "Headers/ThemeManager.h"
%subclass SyntaxSelectorViewController : ThemeSelectorViewController
%property (nonatomic, retain) NSArray *themes;
%property (nonatomic, retain) NSArray *fonts;
- (id)init {
self = %orig;
if (self) {
}
return self;
}
- (void)viewWillAppear:(bool)animated {
NSString *themePath = @"/Library/Application Support/FilzaPlus/Themes/";
NSArray *themeFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:themePath error:NULL];
NSMutableArray *themes = [[NSMutableArray alloc] init];
[themeFiles enumerateObjectsUsingBlock:^(NSString *filename, NSUInteger idx, BOOL *stop) {
NSString *extension = [[filename pathExtension] lowercaseString];
if ([extension isEqualToString:@"plist"]) {
[themes addObject:[filename stringByDeletingPathExtension]];
}
}];
self.themes = [themes copy];
NSString *fontPath = @"/Library/Application Support/FilzaPlus/Fonts/";
NSArray *fontFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:fontPath error:NULL];
[fontFiles enumerateObjectsUsingBlock:^(NSString *filename, NSUInteger idx, BOOL *stop) {
NSString *extension = [[filename pathExtension] lowercaseString];
if ([extension isEqualToString:@"ttf"]) {
CGDataProviderRef dataProvider = CGDataProviderCreateWithFilename([[NSString stringWithFormat:@"/Library/Application Support/FilzaPlus/Fonts/%@", filename] UTF8String]);
CGFontRef font = CGFontCreateWithDataProvider(dataProvider);
CGDataProviderRelease(dataProvider);
CTFontManagerRegisterGraphicsFont(font, nil);
CGFontRelease(font);
}
}];
self.fonts = @[@"Default", @"Consolas", @"Source Code Pro", @"Menlo", @"Monaco"];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (section == 0) {
return @"Theme";
} else if (section == 1) {
return @"Font";
}
return @"";
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return self.themes.count;
}
return self.fonts.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
cell.backgroundColor = [[NSClassFromString(@"ThemeManager") sharedInstance] background];
cell.textLabel.textColor = [[NSClassFromString(@"ThemeManager") sharedInstance] text];
if (indexPath.section == 0) {
[cell.textLabel setText:self.themes[indexPath.row]];
if ([[[%c(ThemeManager) sharedInstance] syntaxTheme] isEqual:[NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/Library/Application Support/FilzaPlus/Themes/%@.plist", self.themes[indexPath.row]]]]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
} else {
[cell.textLabel setText:self.fonts[indexPath.row]];
if ([[[%c(ThemeManager) sharedInstance] syntaxFont] isEqual:self.fonts[indexPath.row]]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
if ([[%c(ThemeManager) sharedInstance] isBlackTheme]) {
UIView *bg = [[UIView alloc] init];
bg.backgroundColor = [[%c(ThemeManager) sharedInstance] selected];
[cell setSelectedBackgroundView:bg];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSMutableDictionary *prefs = [NSMutableDictionary dictionaryWithDictionary:[NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/xyz.skitty.filzaplus.plist"]];
if (indexPath.section == 0) {
[prefs setValue:self.themes[indexPath.row] forKey:@"syntax-theme"];
[prefs writeToFile:@"/var/mobile/Library/Preferences/xyz.skitty.filzaplus.plist" atomically:TRUE];
} else {
[prefs setValue:self.fonts[indexPath.row] forKey:@"syntax-font"];
[prefs writeToFile:@"/var/mobile/Library/Preferences/xyz.skitty.filzaplus.plist" atomically:TRUE];
}
[[%c(ThemeManager) sharedInstance] refresh];
[tableView reloadData];
}
%end