From 93005290f2ceee7a573d69379a4d1f1875d5aa95 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Mon, 28 May 2012 00:59:47 +0000 Subject: - Fix issues where removing favorites could cause crashes in other tabs/windows where the favorite was selected (Issue #1351) - Keep multiple windows and tabs in sync when editing favorites - Fix a new KVO observation not being removed on object teardown --- Source/SPConnectionControllerInitializer.m | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'Source/SPConnectionControllerInitializer.m') diff --git a/Source/SPConnectionControllerInitializer.m b/Source/SPConnectionControllerInitializer.m index 09847b98..e123f5a8 100644 --- a/Source/SPConnectionControllerInitializer.m +++ b/Source/SPConnectionControllerInitializer.m @@ -35,6 +35,7 @@ static NSString *SPConnectionViewNibName = @"ConnectionView"; @interface SPConnectionController () +- (void)_processFavoritesDataChange; - (void)_reloadFavoritesViewData; - (void)_selectNode:(SPTreeNode *)node; - (void)_scrollToSelectedNode; @@ -145,6 +146,10 @@ static NSString *SPConnectionViewNibName = @"ConnectionView"; selector:@selector(scrollViewFrameChanged:) name:NSViewFrameDidChangeNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(_processFavoritesDataChange:) + name:SPConnectionFavoritesChangedNotification + object:nil]; // Registered to be notified of changes to connection information [self addObserver:self @@ -285,6 +290,30 @@ static NSString *SPConnectionViewNibName = @"ConnectionView"; #pragma mark - #pragma mark Private API +/** + * Responds to notifications that the favorites root has changed, + * and updates the interface to match. + */ +- (void)_processFavoritesDataChange:(NSNotification *)aNotification +{ + + // Check the supplied notification for the sender; if the sender + // was this object, ignore it + if ([aNotification object] == self) return; + + NSArray *selectedFavoriteNodes = [self selectedFavoriteNodes]; + + [self _reloadFavoritesViewData]; + + NSMutableIndexSet *selectionIndexes = [NSMutableIndexSet indexSet]; + for (SPTreeNode *eachNode in selectedFavoriteNodes) { + NSInteger anIndex = [favoritesOutlineView rowForItem:eachNode]; + if (anIndex == -1) continue; + [selectionIndexes addIndex:anIndex]; + } + [favoritesOutlineView selectRowIndexes:selectionIndexes byExtendingSelection:NO]; +} + /** * Restores the outline views group nodes expansion state. * -- cgit v1.2.3