Add an option to view the Library in Files

This commit is contained in:
Lior Halphon
2024-06-04 00:30:34 +03:00
parent 322f3c7013
commit 0bc0618a6a

View File

@@ -16,6 +16,12 @@
{ {
self = [super initWithStyle:UITableViewStyleGrouped]; self = [super initWithStyle:UITableViewStyleGrouped];
self.navigationItem.rightBarButtonItem = self.editButtonItem; self.navigationItem.rightBarButtonItem = self.editButtonItem;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(deselectRow)
name:UIApplicationDidBecomeActiveNotification
object:nil];
return self; return self;
} }
@@ -26,7 +32,7 @@
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{ {
if (section == 1) return 1; if (section == 1) return 2;
return [GBROMManager sharedManager].allROMs.count; return [GBROMManager sharedManager].allROMs.count;
} }
@@ -34,7 +40,10 @@
{ {
if (indexPath.section == 1) { if (indexPath.section == 1) {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.textLabel.text = @"Import ROM files"; switch (indexPath.item) {
case 0: cell.textLabel.text = @"Import ROM files"; break;
case 1: cell.textLabel.text = @"Show Library in Files"; break;
}
return cell; return cell;
} }
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
@@ -83,6 +92,8 @@
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ {
if (indexPath.section == 1) { if (indexPath.section == 1) {
switch (indexPath.item) {
case 0: {
UIViewController *parent = self.presentingViewController; UIViewController *parent = self.presentingViewController;
NSString *gbUTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)@"gb", NULL); NSString *gbUTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)@"gb", NULL);
NSString *gbcUTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)@"gbc", NULL); NSString *gbcUTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)@"gbc", NULL);
@@ -127,6 +138,14 @@
}]; }];
return; return;
} }
case 1: {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"shareddocuments://%@", NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true).firstObject]]
options:nil
completionHandler:nil];
return;
}
}
}
[GBROMManager sharedManager].currentROM = [GBROMManager sharedManager].allROMs[[indexPath indexAtPosition:1]]; [GBROMManager sharedManager].currentROM = [GBROMManager sharedManager].allROMs[[indexPath indexAtPosition:1]];
[self.presentingViewController dismissViewControllerAnimated:true completion:^{ [self.presentingViewController dismissViewControllerAnimated:true completion:^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"GBROMChanged" object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"GBROMChanged" object:nil];
@@ -297,4 +316,11 @@ contextMenuConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath
}]; }];
} }
- (void)deselectRow
{
if (self.tableView.indexPathForSelectedRow) {
[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:true];
}
}
@end @end