aboutsummaryrefslogtreecommitdiffstats
path: root/Source
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
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')
-rw-r--r--Source/SPConnectionController.m7
-rw-r--r--Source/SPConnectionControllerDelegate.m4
-rw-r--r--Source/SPConnectionControllerInitializer.m29
-rw-r--r--Source/SPConstants.h1
-rw-r--r--Source/SPConstants.m1
-rw-r--r--Source/SPFavoritesController.m6
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 -