From 33cdba3b134c797b773d11e022fb068552ae81a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20A=2E=20A=CC=81lvarez?= Date: Sat, 14 May 2016 13:06:42 +0200 Subject: [PATCH] add keyboard layout settings UI --- Mini vMac/SettingsViewController.m | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Mini vMac/SettingsViewController.m b/Mini vMac/SettingsViewController.m index e0fc626..cf172ef 100644 --- a/Mini vMac/SettingsViewController.m +++ b/Mini vMac/SettingsViewController.m @@ -14,9 +14,13 @@ @end @implementation SettingsViewController +{ + NSArray *keyboardLayouts; +} - (void)viewDidLoad { [super viewDidLoad]; + keyboardLayouts = [[NSBundle mainBundle] pathsForResourcesOfType:@"nfkeyboardlayout" inDirectory:@"Keyboard Layouts"]; } - (void)showInsertDisk:(id)sender { @@ -54,8 +58,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == 2) { - // keyboard layout - return 0; + return keyboardLayouts.count; } else { return 1; } @@ -86,10 +89,24 @@ mouseControl.selectedSegmentIndex = [defaults boolForKey:@"trackpad"] ? 1 : 0; } else if (section == 2) { cell = [tableView dequeueReusableCellWithIdentifier:@"keyboard" forIndexPath:indexPath]; + NSString *layout = keyboardLayouts[indexPath.row]; + cell.textLabel.text = layout.lastPathComponent.stringByDeletingPathExtension; + BOOL selected = [[defaults stringForKey:@"keyboardLayout"] isEqualToString:layout.lastPathComponent]; + cell.accessoryType = selected ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone; } else if (section == 3) { cell = [tableView dequeueReusableCellWithIdentifier:@"about" forIndexPath:indexPath]; } return cell; } +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + if (indexPath.section == 2) { + NSString *layout = keyboardLayouts[indexPath.row]; + [defaults setValue:layout.lastPathComponent forKey:@"keyboardLayout"]; + } + [tableView deselectRowAtIndexPath:indexPath animated:YES]; + [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic]; +} + @end