- Controller: implement ticking, swapped thumbstick mapping to match common usage - External mouse should continue sending move while mouse button is being held - Tweak touch scroll velocity division to 100
74 lines
2.4 KiB
Objective-C
74 lines
2.4 KiB
Objective-C
#import "FileListViewController.h"
|
|
|
|
@interface FileListViewController () {
|
|
}
|
|
|
|
@property(nonatomic) NSMutableArray *fileList;
|
|
|
|
@end
|
|
|
|
@implementation FileListViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
if (self.fileList == nil) {
|
|
self.fileList = [NSMutableArray array];
|
|
} else {
|
|
[self.fileList removeAllObjects];
|
|
}
|
|
|
|
// List files
|
|
NSFileManager *fm = [NSFileManager defaultManager];
|
|
NSArray *files = [fm contentsOfDirectoryAtPath:self.listPath error:nil];
|
|
for(NSString *file in files) {
|
|
NSString *path = [self.listPath stringByAppendingPathComponent:file];
|
|
BOOL isDir = NO;
|
|
[fm fileExistsAtPath:path isDirectory:(&isDir)];
|
|
if(!isDir && [file hasSuffix:@".json"]) {
|
|
[self.fileList addObject:[file stringByDeletingPathExtension]];
|
|
}
|
|
}
|
|
|
|
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
|
|
}
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
{
|
|
return self.fileList.count;
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
|
|
|
|
if (cell == nil) {
|
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
|
|
}
|
|
|
|
cell.textLabel.text = [self.fileList objectAtIndex:indexPath.row];
|
|
return cell;
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
self.whenItemSelected(self.fileList [indexPath.row]);
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
|
NSString *str = [self.fileList objectAtIndex:indexPath.row];
|
|
NSFileManager *fm = [NSFileManager defaultManager];
|
|
NSString *path = [NSString stringWithFormat:@"%@/%@.json", self.listPath, str];
|
|
if (self.whenDelete != nil) {
|
|
self.whenDelete(path);
|
|
}
|
|
[fm removeItemAtPath:path error:nil];
|
|
[self.fileList removeObjectAtIndex:indexPath.row];
|
|
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
|
}
|
|
}
|
|
|
|
@end
|