diff options
author | stuconnolly <stuart02@gmail.com> | 2010-07-05 21:54:28 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2010-07-05 21:54:28 +0000 |
commit | 9de3398e48f50646f616893df3eba30211d94eec (patch) | |
tree | edfe3297166f27e5424ff1a9b298eee45ab98ce0 /Source | |
parent | ee39747795b41551509a11fa770d8a937feb5f39 (diff) | |
download | sequelpro-9de3398e48f50646f616893df3eba30211d94eec.tar.gz sequelpro-9de3398e48f50646f616893df3eba30211d94eec.tar.bz2 sequelpro-9de3398e48f50646f616893df3eba30211d94eec.zip |
Enable manual sorting of connection favourites in the preferences, which will disable automatic sorting. Also, connection favourites sort order in the preferences and the connection view should now be in sync. Needs thoroughly tested. Fixes issue #655.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPConnectionController.h | 4 | ||||
-rw-r--r-- | Source/SPConnectionController.m | 114 | ||||
-rw-r--r-- | Source/SPPreferenceController.h | 1 | ||||
-rw-r--r-- | Source/SPPreferenceController.m | 36 |
4 files changed, 98 insertions, 57 deletions
diff --git a/Source/SPConnectionController.h b/Source/SPConnectionController.h index 6d1f23ed..edf6f5fd 100644 --- a/Source/SPConnectionController.h +++ b/Source/SPConnectionController.h @@ -114,8 +114,10 @@ IBOutlet NSButton *helpButton; IBOutlet NSProgressIndicator *progressIndicator; IBOutlet NSTextField *progressIndicatorText; - + IBOutlet NSMenuItem *favoritesSortByMenuItem; + BOOL reverseFavoritesSort; + SPFavoritesSortItem previousSortItem, currentSortItem; } diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index ee3bb724..a270a716 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -114,13 +114,10 @@ [favoritesTable setDraggingSourceOperationMask:NSDragOperationMove forLocal:YES]; // Sort the favourites to match prefs and select the appropriate row - [self _sortFavorites]; - NSInteger tableRow; - if ([prefs boolForKey:SPSelectLastFavoriteUsed] == YES) { - tableRow = [prefs integerForKey:SPLastFavoriteIndex] + 1; - } else { - tableRow = [prefs integerForKey:SPDefaultFavorite] + 1; - } + if (currentSortItem > -1) [self _sortFavorites]; + + NSInteger tableRow = ([prefs integerForKey:[prefs boolForKey:SPSelectLastFavoriteUsed] ? SPLastFavoriteIndex : SPDefaultFavorite] + 1); + if (tableRow < [favorites count]) { previousType = [[[favorites objectAtIndex:tableRow] objectForKey:@"type"] integerValue]; [self resizeTabViewToConnectionType:[[[favorites objectAtIndex:tableRow] objectForKey:@"type"] integerValue] animating:NO]; @@ -679,9 +676,9 @@ // Perform sorting [self _sortFavorites]; - [[[sender menu] itemAtIndex:previousSortItem] setState:NSOffState]; + if (previousSortItem > -1) [[[sender menu] itemAtIndex:previousSortItem] setState:NSOffState]; + [[[sender menu] itemAtIndex:currentSortItem] setState:NSOnState]; - } /** @@ -891,29 +888,49 @@ } #pragma mark - -#pragma mark Favorites tableview datasource and delegate methods +#pragma mark TableView drag & drop delegate methods -/** - * Returns the number of favorites to display - */ -- (NSInteger) numberOfRowsInTableView:(NSTableView *)aTableView +- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard { - return [favorites count]; + NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes]; + [pboard declareTypes:[NSArray arrayWithObject:favoritesPBoardType] owner:self]; + [pboard setData:archivedData forType:favoritesPBoardType]; + return YES; } -/** - * Returns the favorite names to be displayed in the table - */ -- (id) tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex +- (NSDragOperation)tableView:(NSTableView *)aTableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation { - return [[favorites objectAtIndex:rowIndex] objectForKey:@"name"]; + if (row == 0) return NSDragOperationNone; + if ([info draggingSource] == aTableView) + { + [aTableView setDropRow:row dropOperation:NSTableViewDropAbove]; + return NSDragOperationMove; + } + return NSDragOperationNone; } -- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id < NSDraggingInfo >)info - row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation +- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation { BOOL acceptedDrop = NO; - if ((row == 0) || ([info draggingSource] != aTableView)) return acceptedDrop; + + if ((row == 0) || ([info draggingSource] != aTableView)) return acceptedDrop; + + // Disable all automatic sorting + currentSortItem = -1; + reverseFavoritesSort = NO; + + [prefs setInteger:currentSortItem forKey:SPFavoritesSortedBy]; + [prefs setBool:NO forKey:SPFavoritesSortedInReverse]; + + // Remove sort descriptors + [favorites sortUsingDescriptors:[NSArray array]]; + + // Uncheck sort by menu items + for (NSMenuItem *menuItem in [[favoritesSortByMenuItem submenu] itemArray]) + { + [menuItem setState:NSOffState]; + } + NSPasteboard* pboard = [info draggingPasteboard]; NSData* rowData = [pboard dataForType:favoritesPBoardType]; NSIndexSet* rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData]; @@ -932,39 +949,45 @@ [favorites insertObject:draggedFavorite atIndex:row]; [aTableView reloadData]; [aTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO]; - // reset the prefs with the new order + + // reset the prefs with the new order NSMutableArray *reorderedFavorites = [[NSMutableArray alloc] initWithArray:favorites]; [reorderedFavorites removeObjectAtIndex:0]; [prefs setObject:reorderedFavorites forKey:SPFavorites]; + [[[NSApp delegate] preferenceController] updateDefaultFavoritePopup]; - [reorderedFavorites release]; - [self updateFavorites]; - acceptedDrop = YES; + + [reorderedFavorites release]; + + [self updateFavorites]; + + acceptedDrop = YES; + return acceptedDrop; - } -- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes - toPasteboard:(NSPasteboard *)pboard +#pragma mark - +#pragma mark Favorites tableview datasource methods + +/** + * Returns the number of favorites to display + */ +- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView { - NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes]; - [pboard declareTypes:[NSArray arrayWithObject:favoritesPBoardType] owner:self]; - [pboard setData:archivedData forType:favoritesPBoardType]; - return YES; + return [favorites count]; } -- (NSDragOperation)tableView:(NSTableView *)aTableView validateDrop:(id < NSDraggingInfo >)info - proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation +/** + * Returns the favorite names to be displayed in the table + */ +- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { - if (row == 0) return NSDragOperationNone; - if ([info draggingSource] == aTableView) - { - [aTableView setDropRow:row dropOperation:NSTableViewDropAbove]; - return NSDragOperationMove; - } - return NSDragOperationNone; + return [[favorites objectAtIndex:rowIndex] objectForKey:@"name"]; } +#pragma mark - +#pragma mark Favorites tableview delegate methods + /** * Loads a favorite, if any are selected. */ @@ -1021,7 +1044,7 @@ #pragma mark - -#pragma mark NSSplitView delegate methods +#pragma mark SplitView delegate methods /** * When the split view is resized, trigger a resize in the hidden table @@ -1032,6 +1055,7 @@ - (CGFloat)splitView:(NSSplitView *)splitView constrainSplitPosition:(CGFloat)proposedPosition ofSubviewAt:(NSInteger)dividerIndex { [databaseConnectionView setPosition:[[[connectionSplitView subviews] objectAtIndex:0] frame].size.width ofDividerAtIndex:0]; + return proposedPosition; } @@ -1131,6 +1155,4 @@ return YES; } - - @end diff --git a/Source/SPPreferenceController.h b/Source/SPPreferenceController.h index c2b4b18a..cf9d2cc1 100644 --- a/Source/SPPreferenceController.h +++ b/Source/SPPreferenceController.h @@ -57,6 +57,7 @@ IBOutlet NSTextField *favoriteUserTextFieldSocket; IBOutlet NSTextField *favoriteUserTextFieldSSH; IBOutlet NSTextField *favoriteHostTextFieldSSH; + IBOutlet NSMenuItem *favoritesSortByMenuItem; IBOutlet id tableCell; diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m index 66dc2597..ab8ec067 100644 --- a/Source/SPPreferenceController.m +++ b/Source/SPPreferenceController.m @@ -98,7 +98,9 @@ [prefs synchronize]; - [self _sortFavorites]; + if (currentSortItem > -1) { + [self _sortFavorites]; + } } #pragma mark - @@ -456,7 +458,7 @@ * Sorts the favorites table view based on the selected sort by item */ - (IBAction)sortFavorites:(id)sender -{ +{ previousSortItem = currentSortItem; currentSortItem = [[sender menu] indexOfItem:sender]; @@ -465,8 +467,9 @@ // Perform sorting [self _sortFavorites]; - [[[sender menu] itemAtIndex:previousSortItem] setState:NSOffState]; - [[[sender menu] itemAtIndex:currentSortItem] setState:NSOnState]; + if (previousSortItem > -1) [[[sender menu] itemAtIndex:previousSortItem] setState:NSOffState]; + + [[[sender menu] itemAtIndex:currentSortItem] setState:NSOnState]; } /** @@ -621,12 +624,12 @@ } #pragma mark - -#pragma mark TableView drag & drop datasource methods +#pragma mark TableView drag & drop delegate methods // ------------------------------------------------------------------------------- // tableView:writeRowsWithIndexes:toPasteboard: // ------------------------------------------------------------------------------- -/*- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rows toPasteboard:(NSPasteboard*)pboard +- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rows toPasteboard:(NSPasteboard*)pboard { if ([rows count] == 1) { [pboard declareTypes:[NSArray arrayWithObject:SPFavoritesPasteboardDragType] owner:nil]; @@ -670,6 +673,22 @@ NSInteger lastFavoriteIndexCached; NSMutableDictionary *draggedRow; + // Disable all automatic sorting + currentSortItem = -1; + reverseFavoritesSort = NO; + + [prefs setInteger:currentSortItem forKey:SPFavoritesSortedBy]; + [prefs setBool:NO forKey:SPFavoritesSortedInReverse]; + + // Remove sort descriptors + [favoritesController setSortDescriptors:[NSArray array]]; + + // Uncheck sort by menu items + for (NSMenuItem *menuItem in [[favoritesSortByMenuItem submenu] itemArray]) + { + [menuItem setState:NSOffState]; + } + originalRow = [[[info draggingPasteboard] stringForType:SPFavoritesPasteboardDragType] integerValue]; destinationRow = row; @@ -701,7 +720,7 @@ [self updateDefaultFavoritePopup]; return YES; -}*/ +} #pragma mark - #pragma mark TableView delegate methods @@ -1384,9 +1403,6 @@ case SPFavoritesSortTypeItem: sortKey = @"type"; break; - default: - sortKey = @"name"; - break; } NSSortDescriptor *sortDescriptor = nil; |