From 36fa01d0c98481af4b6a17061ac94c0a5a0186fe Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Tue, 19 Feb 2013 01:09:30 +0000 Subject: - Fix crashes when importing favorites on the connection view, addressing Issue #1556 - Select and scroll to newly created favorites after import --- Source/SPConnectionControllerDelegate.m | 17 +++++++++++++++-- Source/SPFavoritesImporter.m | 4 +--- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'Source') diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m index a6001309..ec1c65f1 100644 --- a/Source/SPConnectionControllerDelegate.m +++ b/Source/SPConnectionControllerDelegate.m @@ -57,6 +57,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf"; - (void)_sortFavorites; - (void)_favoriteTypeDidChange; - (void)_reloadFavoritesViewData; +- (void)_scrollToSelectedNode; - (NSString *)_stripInvalidCharactersFromString:(NSString *)subject; @@ -665,17 +666,29 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf"; */ - (void)favoritesImportData:(NSArray *)data { + SPTreeNode *newNode; + NSMutableArray *importedNodes = [NSMutableArray array]; + NSMutableIndexSet *importedIndexSet = [NSMutableIndexSet indexSet]; + // Add each of the imported favorites to the root node for (NSMutableDictionary *favorite in data) { - [favoritesController addFavoriteNodeWithData:favorite asChildOfNode:nil]; + newNode = [favoritesController addFavoriteNodeWithData:favorite asChildOfNode:nil]; + [importedNodes addObject:newNode]; } if (currentSortItem > SPFavoritesSortUnsorted) { [self _sortFavorites]; -} + } [self _reloadFavoritesViewData]; + + // Select the new nodes and scroll into view + for (SPTreeNode *eachNode in importedNodes) { + [importedIndexSet addIndex:[favoritesOutlineView rowForItem:eachNode]]; + } + [favoritesOutlineView selectRowIndexes:importedIndexSet byExtendingSelection:NO]; + [self _scrollToSelectedNode]; } /** diff --git a/Source/SPFavoritesImporter.m b/Source/SPFavoritesImporter.m index f33e1705..bb027104 100644 --- a/Source/SPFavoritesImporter.m +++ b/Source/SPFavoritesImporter.m @@ -73,12 +73,10 @@ NSFileManager *fileManager = [NSFileManager defaultManager]; if ([fileManager fileExistsAtPath:[self importPath]]) { - importData = [[NSDictionary alloc] initWithContentsOfFile:[self importPath]]; + importData = [[[NSDictionary alloc] initWithContentsOfFile:[self importPath]] autorelease]; NSArray *favorites = [importData valueForKey:SPFavoritesDataRootKey]; - [importData release]; - if (favorites) { [self _informDelegateOfImportDataAvailable:favorites]; } -- cgit v1.2.3