From 89719b64e4f6fa793c4ed7d4d1a63f8b4938812c Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sat, 3 Jul 2010 22:10:38 +0000 Subject: Various improvements to default connection favorites handling, including: - Updating the default favorite popup button to reflect the sorted order of the favorites tableview. - A new icon indicating the default favorite in the favorites tableview. - A new 'Make Default' menu item in the favorites tableview context menu. (Outstanding issue: Incorrect default favorite being selected upon launch because the sorting of favorites on the connection screen and preferences are independent of each other). --- Source/SPConnectionController.m | 85 ++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 36 deletions(-) (limited to 'Source/SPConnectionController.m') diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index ad2bdf62..ee3bb724 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -58,6 +58,8 @@ @synthesize connectionSSHKeychainItemName; @synthesize connectionSSHKeychainItemAccount; +#pragma mark - + /** * Initialise the connection controller, linking it to the * parent document and setting up the parent window. @@ -682,6 +684,9 @@ } +/** + * + */ - (void)reverseSortFavorites:(id)sender { reverseFavoritesSort = (![sender state]); @@ -694,42 +699,6 @@ [sender setState:reverseFavoritesSort]; } -- (void)_sortFavorites -{ - NSString *sortKey = @""; - - switch (currentSortItem) - { - case SPFavoritesSortNameItem: - sortKey = @"name"; - break; - case SPFavoritesSortHostItem: - sortKey = @"host"; - break; - case SPFavoritesSortTypeItem: - sortKey = @"type"; - break; - default: - sortKey = @"name"; - break; - } - - NSSortDescriptor *sortDescriptor = nil; - - if (currentSortItem == SPFavoritesSortTypeItem) { - sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:sortKey ascending:(!reverseFavoritesSort)] autorelease]; - } - else { - sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:sortKey ascending:(!reverseFavoritesSort) selector:@selector(caseInsensitiveCompare:)] autorelease]; - } - NSDictionary *first = [[favorites objectAtIndex:0] retain]; - [favorites removeObjectAtIndex:0]; - [favorites sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; - [favorites insertObject:first atIndex:0]; - [favoritesTable reloadData]; - [first release]; - -} /** * Updates the local favorites array from the user defaults */ @@ -1084,6 +1053,7 @@ #pragma mark - #pragma mark Menu Validation + -(BOOL)validateMenuItem:(NSMenuItem *)menuItem { SEL action = [menuItem action]; @@ -1103,6 +1073,49 @@ return YES; } + +#pragma mark - +#pragma mark Private API + +- (void)_sortFavorites +{ + NSString *sortKey = @""; + + switch (currentSortItem) + { + case SPFavoritesSortNameItem: + sortKey = @"name"; + break; + case SPFavoritesSortHostItem: + sortKey = @"host"; + break; + case SPFavoritesSortTypeItem: + sortKey = @"type"; + break; + default: + sortKey = @"name"; + break; + } + + NSSortDescriptor *sortDescriptor = nil; + + if (currentSortItem == SPFavoritesSortTypeItem) { + sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:sortKey ascending:(!reverseFavoritesSort)] autorelease]; + } + else { + sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:sortKey ascending:(!reverseFavoritesSort) selector:@selector(caseInsensitiveCompare:)] autorelease]; + } + + NSDictionary *first = [[favorites objectAtIndex:0] retain]; + + [favorites removeObjectAtIndex:0]; + [favorites sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; + [favorites insertObject:first atIndex:0]; + [favoritesTable reloadData]; + + [first release]; +} + @end #pragma mark - -- cgit v1.2.3