From 128c91479ac60957a10d323957431ab1e9bb3124 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sat, 29 Nov 2008 21:29:06 +0000 Subject: [PATCH] fix a whoops with group row removal; when removing a row, select the row below it --- macosx/GroupsController.m | 2 +- macosx/GroupsWindowController.m | 63 ++++++++++++++++++++------------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/macosx/GroupsController.m b/macosx/GroupsController.m index 967b16751..8d3b7da1b 100644 --- a/macosx/GroupsController.m +++ b/macosx/GroupsController.m @@ -196,7 +196,7 @@ GroupsController * fGroupsInstance = nil; - (void) removeGroupWithRowIndex: (NSInteger) row { NSInteger index = [[[fGroups objectAtIndex: row] objectForKey: @"Index"] intValue]; - [fGroups removeObjectAtIndex: index]; + [fGroups removeObjectAtIndex: row]; [[NSNotificationCenter defaultCenter] postNotificationName: @"GroupValueRemoved" object: self userInfo: [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: index] forKey: @"Index"]]; diff --git a/macosx/GroupsWindowController.m b/macosx/GroupsWindowController.m index 133a05cbc..ae6a030d3 100644 --- a/macosx/GroupsWindowController.m +++ b/macosx/GroupsWindowController.m @@ -57,7 +57,11 @@ [fAddRemoveControl setEnabled: NO forSegment: REMOVE_TAG]; [fSelectedColorView addObserver: self forKeyPath: @"color" options: 0 context: NULL]; - [self updateSelectedColor]; + + if ([fTableView numberOfRows] > 0) + [fTableView selectRow: 0 byExtendingSelection: NO]; + else + [self updateSelectedColor]; //make sure all fields are disabled } - (NSInteger) numberOfRowsInTableView: (NSTableView *) tableview @@ -82,26 +86,6 @@ [self updateSelectedColor]; } -- (void) updateSelectedColor -{ - [fAddRemoveControl setEnabled: [fTableView numberOfSelectedRows] > 0 forSegment: REMOVE_TAG]; - if ([fTableView numberOfSelectedRows] == 1) - { - NSInteger index = [[GroupsController groups] indexForRow: [fTableView selectedRow]]; - [fSelectedColorView setColor: [[GroupsController groups] colorForIndex: index]]; - [fSelectedColorView setEnabled: YES]; - [fSelectedColorNameField setStringValue: [[GroupsController groups] nameForIndex: index]]; - [fSelectedColorNameField setEnabled: YES]; - } - else - { - [fSelectedColorView setColor: [NSColor whiteColor]]; - [fSelectedColorView setEnabled: NO]; - [fSelectedColorNameField setStringValue: @""]; - [fSelectedColorNameField setEnabled: NO]; - } -} - - (void) observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object change: (NSDictionary *) change context: (void *) context { if (object == fSelectedColorView && [fTableView numberOfSelectedRows] == 1) @@ -171,7 +155,7 @@ [fTableView reloadData]; row = [fTableView numberOfRows]-1; - [fTableView selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO]; + [fTableView selectRow: row byExtendingSelection: NO]; [fTableView scrollRowToVisible: row]; break; @@ -184,13 +168,42 @@ && row == [[GroupsController groups] rowValueForIndex: fCurrentColorIndex]) [[NSColorPanel sharedColorPanel] close]; - [[GroupsController groups] removeGroupWithRowIndex: row]; - - [fTableView deselectAll: self]; + [[GroupsController groups] removeGroupWithRowIndex: row]; + [fTableView reloadData]; + //select the next row + if (row == [fTableView numberOfRows]) + row--; + if (row >= 0) + [fTableView selectRow: row byExtendingSelection: NO]; + break; } } @end + +@implementation GroupsWindowController (Private) + +- (void) updateSelectedColor +{ + [fAddRemoveControl setEnabled: [fTableView numberOfSelectedRows] > 0 forSegment: REMOVE_TAG]; + if ([fTableView numberOfSelectedRows] == 1) + { + NSInteger index = [[GroupsController groups] indexForRow: [fTableView selectedRow]]; + [fSelectedColorView setColor: [[GroupsController groups] colorForIndex: index]]; + [fSelectedColorView setEnabled: YES]; + [fSelectedColorNameField setStringValue: [[GroupsController groups] nameForIndex: index]]; + [fSelectedColorNameField setEnabled: YES]; + } + else + { + [fSelectedColorView setColor: [NSColor whiteColor]]; + [fSelectedColorView setEnabled: NO]; + [fSelectedColorNameField setStringValue: @""]; + [fSelectedColorNameField setEnabled: NO]; + } +} + +@end