From cdafb3e3ebcb3e6ef1fad77347916fd69a84a1cb Mon Sep 17 00:00:00 2001 From: bamse16 Date: Tue, 30 Jun 2009 14:20:14 +0000 Subject: Fixed the last use connection when you're reordering your connections Issue 240: Default connection not being set correctly --- Source/SPPreferenceController.m | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'Source') diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m index 10d58862..a8430659 100644 --- a/Source/SPPreferenceController.m +++ b/Source/SPPreferenceController.m @@ -478,7 +478,7 @@ // tableView:validateDrop:proposedRow:proposedDropOperation: // ------------------------------------------------------------------------------- - (NSDragOperation)tableView:(NSTableView *)tv validateDrop:(id )info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)operation -{ +{ int originalRow; NSArray *pboardTypes = [[info draggingPasteboard] types]; @@ -499,28 +499,32 @@ // tableView:acceptDrop:row:dropOperation: // ------------------------------------------------------------------------------- - (BOOL)tableView:(NSTableView *)tv acceptDrop:(id )info row:(int)row dropOperation:(NSTableViewDropOperation)operation -{ +{ int originalRow; int destinationRow; + int lastFavoriteIndexCached; NSMutableDictionary *draggedRow; originalRow = [[[info draggingPasteboard] stringForType:FAVORITES_PB_DRAG_TYPE] intValue]; destinationRow = row; - + if (destinationRow > originalRow) { destinationRow--; } draggedRow = [NSMutableDictionary dictionaryWithDictionary:[[favoritesController arrangedObjects] objectAtIndex:originalRow]]; + //Before deleting this favorite, we need to save the current index. + //because removeObjectAtArrangedObjectIndex will set prefs LastFavoriteIndex to 0 + lastFavoriteIndexCached = [prefs integerForKey:@"LastFavoriteIndex"]; [favoritesController removeObjectAtArrangedObjectIndex:originalRow]; [favoritesController insertObject:draggedRow atArrangedObjectIndex:destinationRow]; - + [favoritesTableView reloadData]; [favoritesTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:destinationRow] byExtendingSelection:NO]; // Update default favorite to take on new value - if ([prefs integerForKey:@"LastFavoriteIndex"] == originalRow) { + if (lastFavoriteIndexCached == originalRow) { [prefs setInteger:destinationRow forKey:@"LastFavoriteIndex"]; } -- cgit v1.2.3