diff options
-rw-r--r-- | Source/SPConnectionController.m | 7 | ||||
-rw-r--r-- | Source/SPConnectionControllerDelegate.m | 4 | ||||
-rw-r--r-- | Source/SPConnectionControllerInitializer.m | 29 | ||||
-rw-r--r-- | Source/SPConstants.h | 1 | ||||
-rw-r--r-- | Source/SPConstants.m | 1 | ||||
-rw-r--r-- | Source/SPFavoritesController.m | 6 |
6 files changed, 47 insertions, 1 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index 68d7bb16..6de0c9c3 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -971,6 +971,10 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, [favoritesController saveFavorites]; [self _reloadFavoritesViewData]; + + if ([keyPath isEqualToString:SPFavoriteNameKey]) { + [[NSNotificationCenter defaultCenter] postNotificationName:SPConnectionFavoritesChangedNotification object:self]; + } } } @@ -1126,6 +1130,8 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, [favoritesController saveFavorites]; [self _reloadFavoritesViewData]; + + [[NSNotificationCenter defaultCenter] postNotificationName:SPConnectionFavoritesChangedNotification object:self]; } /** @@ -1524,6 +1530,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, [NSObject cancelPreviousPerformRequestsWithTarget:self]; // Unregister observers + [self removeObserver:self forKeyPath:SPFavoriteTypeKey]; [self removeObserver:self forKeyPath:SPFavoriteNameKey]; [self removeObserver:self forKeyPath:SPFavoriteHostKey]; [self removeObserver:self forKeyPath:SPFavoriteUserKey]; diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m index a1a12c1c..bbdf7624 100644 --- a/Source/SPConnectionControllerDelegate.m +++ b/Source/SPConnectionControllerDelegate.m @@ -310,7 +310,9 @@ static NSString *SPDatabaseImage = @"database-small"; [favoritesController saveFavorites]; [self _reloadFavoritesViewData]; - + + [[NSNotificationCenter defaultCenter] postNotificationName:SPConnectionFavoritesChangedNotification object:self]; + [[[[NSApp delegate] preferenceController] generalPreferencePane] updateDefaultFavoritePopup]; // Update the selection to account for rearranged faourites 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 @@ -286,6 +291,30 @@ static NSString *SPConnectionViewNibName = @"ConnectionView"; #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. * * @param node The node to traverse diff --git a/Source/SPConstants.h b/Source/SPConstants.h index e696e71f..6f25e357 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -455,6 +455,7 @@ extern NSString *SPFavoriteSSLCertificateFileLocationEnabledKey; extern NSString *SPFavoriteSSLCertificateFileLocationKey; extern NSString *SPFavoriteSSLCACertFileLocationEnabledKey; extern NSString *SPFavoriteSSLCACertFileLocationKey; +extern NSString *SPConnectionFavoritesChangedNotification; // Favorites import/export extern NSString *SPFavoritesDataRootKey; diff --git a/Source/SPConstants.m b/Source/SPConstants.m index 024f1df0..d7e836af 100644 --- a/Source/SPConstants.m +++ b/Source/SPConstants.m @@ -276,6 +276,7 @@ NSString *SPFavoriteSSLCertificateFileLocationEnabledKey = @"sslCertificateFileL NSString *SPFavoriteSSLCertificateFileLocationKey = @"sslCertificateFileLocation"; NSString *SPFavoriteSSLCACertFileLocationEnabledKey = @"sslCACertFileLocationEnabled"; NSString *SPFavoriteSSLCACertFileLocationKey = @"sslCACertFileLocation"; +NSString *SPConnectionFavoritesChangedNotification = @"SPConnectionFavoritesChanged"; // Favorites import/export NSString *SPFavoritesDataRootKey = @"SPConnectionFavorites"; diff --git a/Source/SPFavoritesController.m b/Source/SPFavoritesController.m index f49749c8..2a432326 100644 --- a/Source/SPFavoritesController.m +++ b/Source/SPFavoritesController.m @@ -147,6 +147,8 @@ static SPFavoritesController *sharedFavoritesController = nil; [node setIsGroup:YES]; [self _addNode:node asChildOfNode:parent]; + + [[NSNotificationCenter defaultCenter] postNotificationName:SPConnectionFavoritesChangedNotification object:self]; return node; } @@ -165,6 +167,8 @@ static SPFavoritesController *sharedFavoritesController = nil; [self _addNode:node asChildOfNode:parent]; + [[NSNotificationCenter defaultCenter] postNotificationName:SPConnectionFavoritesChangedNotification object:self]; + return node; } @@ -180,6 +184,8 @@ static SPFavoritesController *sharedFavoritesController = nil; // Save data to disk [self saveFavorites]; + + [[NSNotificationCenter defaultCenter] postNotificationName:SPConnectionFavoritesChangedNotification object:self]; } #pragma mark - |