aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Lohrmann <dmoagx@users.noreply.github.com>2018-04-03 23:13:31 +0200
committerMax Lohrmann <dmoagx@users.noreply.github.com>2018-04-03 23:13:31 +0200
commit8ceb5be8c231395cdc72b0646dd494c0c5b4e233 (patch)
tree1796a0f78fa2401f571f270a018416781a759a68
parent75781e0d7c4bafeedee9f1f98b105a260d47a308 (diff)
downloadsequelpro-8ceb5be8c231395cdc72b0646dd494c0c5b4e233.tar.gz
sequelpro-8ceb5be8c231395cdc72b0646dd494c0c5b4e233.tar.bz2
sequelpro-8ceb5be8c231395cdc72b0646dd494c0c5b4e233.zip
Names of newly created favorites could be overwritten with the host name under specific conditions (#3015)
Also minified some duplicate code along the way
-rw-r--r--Source/SPConnectionController.m83
1 files changed, 23 insertions, 60 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index 921d4312..407c22e1 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -1318,6 +1318,14 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
}
theFavorite = [self selectedFavorite];
}
+
+ void (^_setOrRemoveKey)(NSString *, id) = ^(NSString *key, id value) {
+ if (value) {
+ [theFavorite setObject:value forKey:key];
+ } else {
+ [theFavorite removeObjectForKey:key];
+ }
+ };
// Set the name - either taking the provided name, or generating one.
if ([[self name] length]) {
@@ -1332,75 +1340,27 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
// Set standard details for the connection
[theFavorite setObject:[NSNumber numberWithInteger:[self type]] forKey:SPFavoriteTypeKey];
- if ([self host]) {
- [theFavorite setObject:[self host] forKey:SPFavoriteHostKey];
- } else {
- [theFavorite removeObjectForKey:SPFavoriteHostKey];
- }
- if ([self socket]) {
- [theFavorite setObject:[self socket] forKey:SPFavoriteSocketKey];
- } else {
- [theFavorite removeObjectForKey:SPFavoriteSocketKey];
- }
- if ([self user]) {
- [theFavorite setObject:[self user] forKey:SPFavoriteUserKey];
- } else {
- [theFavorite removeObjectForKey:SPFavoriteUserKey];
- }
- if ([self port]) {
- [theFavorite setObject:[self port] forKey:SPFavoritePortKey];
- } else {
- [theFavorite removeObjectForKey:SPFavoritePortKey];
- }
- if ([self database]) {
- [theFavorite setObject:[self database] forKey:SPFavoriteDatabaseKey];
- } else {
- [theFavorite removeObjectForKey:SPFavoriteDatabaseKey];
- }
+ _setOrRemoveKey(SPFavoriteHostKey, [self host]);
+ _setOrRemoveKey(SPFavoriteSocketKey, [self socket]);
+ _setOrRemoveKey(SPFavoriteUserKey, [self user]);
+ _setOrRemoveKey(SPFavoritePortKey, [self port]);
+ _setOrRemoveKey(SPFavoriteDatabaseKey, [self database]);
[theFavorite setObject:[NSNumber numberWithInteger:[self colorIndex]] forKey:SPFavoriteColorIndexKey];
// SSL details
[theFavorite setObject:[NSNumber numberWithInteger:[self useSSL]] forKey:SPFavoriteUseSSLKey];
[theFavorite setObject:[NSNumber numberWithInteger:[self sslKeyFileLocationEnabled]] forKey:SPFavoriteSSLKeyFileLocationEnabledKey];
- if ([self sslKeyFileLocation]) {
- [theFavorite setObject:[self sslKeyFileLocation] forKey:SPFavoriteSSLKeyFileLocationKey];
- } else {
- [theFavorite removeObjectForKey:SPFavoriteSSLKeyFileLocationKey];
- }
+ _setOrRemoveKey(SPFavoriteSSLKeyFileLocationKey, [self sslKeyFileLocation]);
[theFavorite setObject:[NSNumber numberWithInteger:[self sslCertificateFileLocationEnabled]] forKey:SPFavoriteSSLCertificateFileLocationEnabledKey];
- if ([self sslCertificateFileLocation]) {
- [theFavorite setObject:[self sslCertificateFileLocation] forKey:SPFavoriteSSLCertificateFileLocationKey];
- } else {
- [theFavorite removeObjectForKey:SPFavoriteSSLCertificateFileLocationKey];
- }
+ _setOrRemoveKey(SPFavoriteSSLCertificateFileLocationKey, [self sslCertificateFileLocation]);
[theFavorite setObject:[NSNumber numberWithInteger:[self sslCACertFileLocationEnabled]] forKey:SPFavoriteSSLCACertFileLocationEnabledKey];
- if ([self sslCACertFileLocation]) {
- [theFavorite setObject:[self sslCACertFileLocation] forKey:SPFavoriteSSLCACertFileLocationKey];
- } else {
- [theFavorite removeObjectForKey:SPFavoriteSSLCACertFileLocationKey];
- }
+ _setOrRemoveKey(SPFavoriteSSLCACertFileLocationKey, [self sslCACertFileLocation]);
// SSH details
- if ([self sshHost]) {
- [theFavorite setObject:[self sshHost] forKey:SPFavoriteSSHHostKey];
- } else {
- [theFavorite removeObjectForKey:SPFavoriteSSHHostKey];
- }
- if ([self sshUser]) {
- [theFavorite setObject:[self sshUser] forKey:SPFavoriteSSHUserKey];
- } else {
- [theFavorite removeObjectForKey:SPFavoriteSSHUserKey];
- }
- if ([self sshPort]) {
- [theFavorite setObject:[self sshPort] forKey:SPFavoriteSSHPortKey];
- } else {
- [theFavorite removeObjectForKey:SPFavoriteSSHPortKey];
- }
+ _setOrRemoveKey(SPFavoriteSSHHostKey, [self sshHost]);
+ _setOrRemoveKey(SPFavoriteSSHUserKey, [self sshUser]);
+ _setOrRemoveKey(SPFavoriteSSHPortKey, [self sshPort]);
[theFavorite setObject:[NSNumber numberWithInteger:[self sshKeyLocationEnabled]] forKey:SPFavoriteSSHKeyLocationEnabledKey];
- if ([self sshKeyLocation]) {
- [theFavorite setObject:[self sshKeyLocation] forKey:SPFavoriteSSHKeyLocationKey];
- } else {
- [theFavorite removeObjectForKey:SPFavoriteSSHKeyLocationKey];
- }
+ _setOrRemoveKey(SPFavoriteSSHKeyLocationKey, [self sshKeyLocation]);
/**
@@ -1535,6 +1495,9 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
[self _sortFavorites];
[self _scrollToSelectedNode];
}
+
+ // after saving the favorite, the name is never autogenerated (ie. overridable), regardless of the value (#3015)
+ favoriteNameFieldWasAutogenerated = NO;
[[NSNotificationCenter defaultCenter] postNotificationName:SPConnectionFavoritesChangedNotification object:self];
#endif