@@ -1318,6 +1318,14 @@ - (void)_saveCurrentDetailsCreatingNewFavorite:(BOOL)createNewFavorite validateD
1318
1318
}
1319
1319
theFavorite = [self selectedFavorite ];
1320
1320
}
1321
+
1322
+ void (^_setOrRemoveKey)(NSString *, id ) = ^(NSString *key, id value) {
1323
+ if (value) {
1324
+ [theFavorite setObject: value forKey: key];
1325
+ } else {
1326
+ [theFavorite removeObjectForKey: key];
1327
+ }
1328
+ };
1321
1329
1322
1330
// Set the name - either taking the provided name, or generating one.
1323
1331
if ([[self name ] length ]) {
@@ -1332,75 +1340,27 @@ - (void)_saveCurrentDetailsCreatingNewFavorite:(BOOL)createNewFavorite validateD
1332
1340
1333
1341
// Set standard details for the connection
1334
1342
[theFavorite setObject: [NSNumber numberWithInteger: [self type ]] forKey: SPFavoriteTypeKey];
1335
- if ([self host ]) {
1336
- [theFavorite setObject: [self host ] forKey: SPFavoriteHostKey];
1337
- } else {
1338
- [theFavorite removeObjectForKey: SPFavoriteHostKey];
1339
- }
1340
- if ([self socket ]) {
1341
- [theFavorite setObject: [self socket ] forKey: SPFavoriteSocketKey];
1342
- } else {
1343
- [theFavorite removeObjectForKey: SPFavoriteSocketKey];
1344
- }
1345
- if ([self user ]) {
1346
- [theFavorite setObject: [self user ] forKey: SPFavoriteUserKey];
1347
- } else {
1348
- [theFavorite removeObjectForKey: SPFavoriteUserKey];
1349
- }
1350
- if ([self port ]) {
1351
- [theFavorite setObject: [self port ] forKey: SPFavoritePortKey];
1352
- } else {
1353
- [theFavorite removeObjectForKey: SPFavoritePortKey];
1354
- }
1355
- if ([self database ]) {
1356
- [theFavorite setObject: [self database ] forKey: SPFavoriteDatabaseKey];
1357
- } else {
1358
- [theFavorite removeObjectForKey: SPFavoriteDatabaseKey];
1359
- }
1343
+ _setOrRemoveKey (SPFavoriteHostKey, [self host ]);
1344
+ _setOrRemoveKey (SPFavoriteSocketKey, [self socket ]);
1345
+ _setOrRemoveKey (SPFavoriteUserKey, [self user ]);
1346
+ _setOrRemoveKey (SPFavoritePortKey, [self port ]);
1347
+ _setOrRemoveKey (SPFavoriteDatabaseKey, [self database ]);
1360
1348
[theFavorite setObject: [NSNumber numberWithInteger: [self colorIndex ]] forKey: SPFavoriteColorIndexKey];
1361
1349
// SSL details
1362
1350
[theFavorite setObject: [NSNumber numberWithInteger: [self useSSL ]] forKey: SPFavoriteUseSSLKey];
1363
1351
[theFavorite setObject: [NSNumber numberWithInteger: [self sslKeyFileLocationEnabled ]] forKey: SPFavoriteSSLKeyFileLocationEnabledKey];
1364
- if ([self sslKeyFileLocation ]) {
1365
- [theFavorite setObject: [self sslKeyFileLocation ] forKey: SPFavoriteSSLKeyFileLocationKey];
1366
- } else {
1367
- [theFavorite removeObjectForKey: SPFavoriteSSLKeyFileLocationKey];
1368
- }
1352
+ _setOrRemoveKey (SPFavoriteSSLKeyFileLocationKey, [self sslKeyFileLocation ]);
1369
1353
[theFavorite setObject: [NSNumber numberWithInteger: [self sslCertificateFileLocationEnabled ]] forKey: SPFavoriteSSLCertificateFileLocationEnabledKey];
1370
- if ([self sslCertificateFileLocation ]) {
1371
- [theFavorite setObject: [self sslCertificateFileLocation ] forKey: SPFavoriteSSLCertificateFileLocationKey];
1372
- } else {
1373
- [theFavorite removeObjectForKey: SPFavoriteSSLCertificateFileLocationKey];
1374
- }
1354
+ _setOrRemoveKey (SPFavoriteSSLCertificateFileLocationKey, [self sslCertificateFileLocation ]);
1375
1355
[theFavorite setObject: [NSNumber numberWithInteger: [self sslCACertFileLocationEnabled ]] forKey: SPFavoriteSSLCACertFileLocationEnabledKey];
1376
- if ([self sslCACertFileLocation ]) {
1377
- [theFavorite setObject: [self sslCACertFileLocation ] forKey: SPFavoriteSSLCACertFileLocationKey];
1378
- } else {
1379
- [theFavorite removeObjectForKey: SPFavoriteSSLCACertFileLocationKey];
1380
- }
1356
+ _setOrRemoveKey (SPFavoriteSSLCACertFileLocationKey, [self sslCACertFileLocation ]);
1381
1357
1382
1358
// SSH details
1383
- if ([self sshHost ]) {
1384
- [theFavorite setObject: [self sshHost ] forKey: SPFavoriteSSHHostKey];
1385
- } else {
1386
- [theFavorite removeObjectForKey: SPFavoriteSSHHostKey];
1387
- }
1388
- if ([self sshUser ]) {
1389
- [theFavorite setObject: [self sshUser ] forKey: SPFavoriteSSHUserKey];
1390
- } else {
1391
- [theFavorite removeObjectForKey: SPFavoriteSSHUserKey];
1392
- }
1393
- if ([self sshPort ]) {
1394
- [theFavorite setObject: [self sshPort ] forKey: SPFavoriteSSHPortKey];
1395
- } else {
1396
- [theFavorite removeObjectForKey: SPFavoriteSSHPortKey];
1397
- }
1359
+ _setOrRemoveKey (SPFavoriteSSHHostKey, [self sshHost ]);
1360
+ _setOrRemoveKey (SPFavoriteSSHUserKey, [self sshUser ]);
1361
+ _setOrRemoveKey (SPFavoriteSSHPortKey, [self sshPort ]);
1398
1362
[theFavorite setObject: [NSNumber numberWithInteger: [self sshKeyLocationEnabled ]] forKey: SPFavoriteSSHKeyLocationEnabledKey];
1399
- if ([self sshKeyLocation ]) {
1400
- [theFavorite setObject: [self sshKeyLocation ] forKey: SPFavoriteSSHKeyLocationKey];
1401
- } else {
1402
- [theFavorite removeObjectForKey: SPFavoriteSSHKeyLocationKey];
1403
- }
1363
+ _setOrRemoveKey (SPFavoriteSSHKeyLocationKey, [self sshKeyLocation ]);
1404
1364
1405
1365
1406
1366
/* *
@@ -1535,6 +1495,9 @@ - (void)_saveCurrentDetailsCreatingNewFavorite:(BOOL)createNewFavorite validateD
1535
1495
[self _sortFavorites ];
1536
1496
[self _scrollToSelectedNode ];
1537
1497
}
1498
+
1499
+ // after saving the favorite, the name is never autogenerated (ie. overridable), regardless of the value (#3015)
1500
+ favoriteNameFieldWasAutogenerated = NO ;
1538
1501
1539
1502
[[NSNotificationCenter defaultCenter ] postNotificationName: SPConnectionFavoritesChangedNotification object: self ];
1540
1503
#endif
0 commit comments