aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPConnectionControllerInitializer.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-05-28 00:59:47 +0000
committerrowanbeentje <rowan@beent.je>2012-05-28 00:59:47 +0000
commit93005290f2ceee7a573d69379a4d1f1875d5aa95 (patch)
tree2c515a4420a36368ca9da2fc35ed8c886bb268da /Source/SPConnectionControllerInitializer.m
parent733e7c89c5f092bc11a06d754bde149a5423c928 (diff)
downloadsequelpro-93005290f2ceee7a573d69379a4d1f1875d5aa95.tar.gz
sequelpro-93005290f2ceee7a573d69379a4d1f1875d5aa95.tar.bz2
sequelpro-93005290f2ceee7a573d69379a4d1f1875d5aa95.zip
- 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
Diffstat (limited to 'Source/SPConnectionControllerInitializer.m')
-rw-r--r--Source/SPConnectionControllerInitializer.m29
1 files changed, 29 insertions, 0 deletions
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