Replace use of deprecated selectRow:byExtendingSelection:.
[enjoyable.git] / ConfigsController.m
index 01bd0d3..f6770cc 100644 (file)
 -(void) restoreNeutralConfig {
        if(!neutralConfig)
                return;
-       if([configs indexOfObject:neutralConfig] < 0) {// deleted, keep what we have
-               neutralConfig = NULL;
-               return;
-       }
        [self activateConfig: neutralConfig forApplication: NULL];
 }
 
@@ -49,7 +45,7 @@
        [removeButton setEnabled: ![config protect]];
        [targetController load];
        [(ApplicationController *)[[NSApplication sharedApplication] delegate] configChanged];
-       [tableView selectRow: [configs indexOfObject: config] byExtendingSelection: NO];
+    [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:[configs indexOfObject:config]] byExtendingSelection:NO];
 }
 
 -(IBAction) addPressed: (id)sender {
@@ -58,7 +54,7 @@
        [configs addObject: newConfig];
        [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged];
        [tableView reloadData];
-       [tableView selectRow: ([configs count]-1) byExtendingSelection: NO];
+    [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:configs.count - 1] byExtendingSelection:NO];
        [tableView editColumn: 0 row:([configs count]-1) withEvent:nil select:YES];
 }
 -(IBAction) removePressed: (id)sender {
@@ -84,7 +80,8 @@
 }
 
 -(void)tableViewSelectionDidChange:(NSNotification*) notify {
-       [self activateConfig: (Config*)[configs objectAtIndex:[tableView selectedRow]] forApplication: NULL];
+    if (tableView.selectedRow < configs.count)
+        [self activateConfig: (Config*)[configs objectAtIndex:[tableView selectedRow]] forApplication: NULL];
 }
        
 -(id) tableView: (NSTableView*)view objectValueForTableColumn: (NSTableColumn*) column row: (int) index {
        for(int i=0; i<[ary count]; i++) {
                NSDictionary* dict = [[ary objectAtIndex:i] objectForKey:@"entries"];
                for(id key in dict) {
-                       [[[newConfigs objectAtIndex:i] entries] 
+                       [[[newConfigs objectAtIndex:i] entries]
                         setObject: [Target unstringify: [dict objectForKey: key] withConfigList: newConfigs]
                         forKey: key];
                }
        [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged];
        
        int index = [[envelope objectForKey: @"selectedIndex"] intValue];
-       [self activateConfig: [configs objectAtIndex:index] forApplication: NULL];
+    if (index < configs.count)
+        [self activateConfig: [configs objectAtIndex:index] forApplication: NULL];
 }
 
 -(void) applicationSwitchedTo: (NSString*) name withPsn: (ProcessSerialNumber) psn {