diff options
author | rowanbeentje <rowan@beent.je> | 2009-07-06 21:01:52 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2009-07-06 21:01:52 +0000 |
commit | 86b104a1da6857792c1feb7dcec0d3d654fdac5f (patch) | |
tree | 112acee41b8870a1197f6cf5591ae9f4fa6c2343 | |
parent | ba53d971b598247500e93a665b4cdb0526a36a50 (diff) | |
download | sequelpro-86b104a1da6857792c1feb7dcec0d3d654fdac5f.tar.gz sequelpro-86b104a1da6857792c1feb7dcec0d3d654fdac5f.tar.bz2 sequelpro-86b104a1da6857792c1feb7dcec0d3d654fdac5f.zip |
- Improve handling of the new favorites interface in preferences, simplifying the code and fixing one or two edge cases that caused disassociation (desynch) of keychain passwords from the favorite
-rw-r--r-- | Interfaces/English.lproj/Preferences.xib | 273 | ||||
-rw-r--r-- | Source/SPPreferenceController.h | 14 | ||||
-rw-r--r-- | Source/SPPreferenceController.m | 198 |
3 files changed, 230 insertions, 255 deletions
diff --git a/Interfaces/English.lproj/Preferences.xib b/Interfaces/English.lproj/Preferences.xib index 78dde430..b07f25e5 100644 --- a/Interfaces/English.lproj/Preferences.xib +++ b/Interfaces/English.lproj/Preferences.xib @@ -8,7 +8,7 @@ <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="1174"/> + <integer value="400"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -3983,14 +3983,6 @@ AQAAAAA</bytes> <int key="connectionID">777</int> </object> <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> - <string key="label">nameField</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="415835787"/> - </object> - <int key="connectionID">778</int> - </object> - <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> <string key="label">contentArray: values.favorites</string> <reference key="source" ref="937123943"/> @@ -4493,22 +4485,6 @@ AQAAAAA</bytes> </object> <object class="IBConnectionRecord"> <object class="IBOutletConnection" key="connection"> - <string key="label">sshHostField</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="905879958"/> - </object> - <int key="connectionID">1116</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> - <string key="label">sshUserField</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="1041581151"/> - </object> - <int key="connectionID">1117</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> <string key="label">delegate</string> <reference key="source" ref="905879958"/> <reference key="destination" ref="1001"/> @@ -4794,22 +4770,6 @@ AQAAAAA</bytes> </object> <object class="IBConnectionRecord"> <object class="IBOutletConnection" key="connection"> - <string key="label">sshSQLHostField</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="619305072"/> - </object> - <int key="connectionID">1296</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> - <string key="label">sshSQLUserField</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="917213113"/> - </object> - <int key="connectionID">1297</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> <string key="label">sshSQLPasswordField</string> <reference key="source" ref="1001"/> <reference key="destination" ref="602383030"/> @@ -4850,14 +4810,6 @@ AQAAAAA</bytes> </object> <object class="IBConnectionRecord"> <object class="IBOutletConnection" key="connection"> - <string key="label">sshDatabaseField</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="471638951"/> - </object> - <int key="connectionID">1303</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> <string key="label">delegate</string> <reference key="source" ref="119091130"/> <reference key="destination" ref="1001"/> @@ -4866,14 +4818,6 @@ AQAAAAA</bytes> </object> <object class="IBConnectionRecord"> <object class="IBOutletConnection" key="connection"> - <string key="label">socketUserField</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="119091130"/> - </object> - <int key="connectionID">1305</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> <string key="label">delegate</string> <reference key="source" ref="340136489"/> <reference key="destination" ref="1001"/> @@ -4898,30 +4842,6 @@ AQAAAAA</bytes> </object> <object class="IBConnectionRecord"> <object class="IBOutletConnection" key="connection"> - <string key="label">socketDatabaseField</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="634238753"/> - </object> - <int key="connectionID">1309</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> - <string key="label">standardSQLHostField</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="77492794"/> - </object> - <int key="connectionID">1310</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> - <string key="label">standardUserField</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="133134378"/> - </object> - <int key="connectionID">1311</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> <string key="label">standardPasswordField</string> <reference key="source" ref="1001"/> <reference key="destination" ref="755342553"/> @@ -4929,12 +4849,12 @@ AQAAAAA</bytes> <int key="connectionID">1312</int> </object> <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> - <string key="label">standardDatabaseField</string> + <object class="IBActionConnection" key="connection"> + <string key="label">favoriteTypeDidChange:</string> <reference key="source" ref="1001"/> - <reference key="destination" ref="796172881"/> + <reference key="destination" ref="1065964214"/> </object> - <int key="connectionID">1313</int> + <int key="connectionID">1329</int> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> @@ -4952,18 +4872,20 @@ AQAAAAA</bytes> <object class="NSMutableArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>NSAllowsEditingMultipleValuesSelection</string> + <string>NSContinuouslyUpdatesValue</string> <string>NSNoSelectionPlaceholder</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> <reference ref="6"/> + <reference ref="5"/> <string>no selection</string> </object> </object> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> - <int key="connectionID">1314</int> + <int key="connectionID">1330</int> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> @@ -4981,18 +4903,20 @@ AQAAAAA</bytes> <object class="NSMutableArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>NSAllowsEditingMultipleValuesSelection</string> + <string>NSContinuouslyUpdatesValue</string> <string>NSNoSelectionPlaceholder</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> <reference ref="6"/> + <reference ref="5"/> <string>no selection</string> </object> </object> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> - <int key="connectionID">1315</int> + <int key="connectionID">1331</int> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> @@ -5010,12 +4934,14 @@ AQAAAAA</bytes> <object class="NSMutableArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>NSAllowsEditingMultipleValuesSelection</string> + <string>NSContinuouslyUpdatesValue</string> <string>NSNoSelectionPlaceholder</string> <string>NSNullPlaceholder</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> <reference ref="6"/> + <reference ref="5"/> <string>no selection</string> <string>optional</string> </object> @@ -5023,7 +4949,7 @@ AQAAAAA</bytes> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> - <int key="connectionID">1316</int> + <int key="connectionID">1332</int> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> @@ -5041,12 +4967,14 @@ AQAAAAA</bytes> <object class="NSMutableArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>NSAllowsEditingMultipleValuesSelection</string> + <string>NSContinuouslyUpdatesValue</string> <string>NSNoSelectionPlaceholder</string> <string>NSNullPlaceholder</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> <reference ref="6"/> + <reference ref="5"/> <string>no selection</string> <string>3306</string> </object> @@ -5054,7 +4982,7 @@ AQAAAAA</bytes> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> - <int key="connectionID">1317</int> + <int key="connectionID">1333</int> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> @@ -5068,13 +4996,22 @@ AQAAAAA</bytes> <string key="NSBinding">value</string> <string key="NSKeyPath">selection.user</string> <object class="NSDictionary" key="NSOptions"> - <string key="NS.key.0">NSNoSelectionPlaceholder</string> - <string key="NS.object.0">no selection</string> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>NSContinuouslyUpdatesValue</string> + <string>NSNoSelectionPlaceholder</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="5"/> + <string>no selection</string> + </object> </object> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> - <int key="connectionID">1318</int> + <int key="connectionID">1334</int> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> @@ -5091,11 +5028,13 @@ AQAAAAA</bytes> <bool key="EncodedWithXMLCoder">YES</bool> <object class="NSMutableArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> + <string>NSContinuouslyUpdatesValue</string> <string>NSNoSelectionPlaceholder</string> <string>NSNullPlaceholder</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="5"/> <string>no selection</string> <string>optional</string> </object> @@ -5103,7 +5042,7 @@ AQAAAAA</bytes> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> - <int key="connectionID">1319</int> + <int key="connectionID">1335</int> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> @@ -5120,11 +5059,13 @@ AQAAAAA</bytes> <bool key="EncodedWithXMLCoder">YES</bool> <object class="NSMutableArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> + <string>NSContinuouslyUpdatesValue</string> <string>NSNoSelectionPlaceholder</string> <string>NSNullPlaceholder</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="5"/> <string>no selection</string> <string>optional</string> </object> @@ -5132,7 +5073,38 @@ AQAAAAA</bytes> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> - <int key="connectionID">1320</int> + <int key="connectionID">1336</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBBindingConnection" key="connection"> + <string key="label">value: selection.name</string> + <reference key="source" ref="415835787"/> + <reference key="destination" ref="937123943"/> + <object class="NSNibBindingConnector" key="connector"> + <reference key="NSSource" ref="415835787"/> + <reference key="NSDestination" ref="937123943"/> + <string key="NSLabel">value: selection.name</string> + <string key="NSBinding">value</string> + <string key="NSKeyPath">selection.name</string> + <object class="NSDictionary" key="NSOptions"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>NSAllowsEditingMultipleValuesSelection</string> + <string>NSContinuouslyUpdatesValue</string> + <string>NSNoSelectionPlaceholder</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="6"/> + <reference ref="5"/> + <string>no selection</string> + </object> + </object> + <int key="NSNibBindingConnectorVersion">2</int> + </object> + </object> + <int key="connectionID">1337</int> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> @@ -5146,13 +5118,22 @@ AQAAAAA</bytes> <string key="NSBinding">value</string> <string key="NSKeyPath">selection.host</string> <object class="NSDictionary" key="NSOptions"> - <string key="NS.key.0">NSNoSelectionPlaceholder</string> - <string key="NS.object.0">no selection</string> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>NSContinuouslyUpdatesValue</string> + <string>NSNoSelectionPlaceholder</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="5"/> + <string>no selection</string> + </object> </object> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> - <int key="connectionID">1321</int> + <int key="connectionID">1338</int> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> @@ -5166,13 +5147,22 @@ AQAAAAA</bytes> <string key="NSBinding">value</string> <string key="NSKeyPath">selection.user</string> <object class="NSDictionary" key="NSOptions"> - <string key="NS.key.0">NSNoSelectionPlaceholder</string> - <string key="NS.object.0">no selection</string> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>NSContinuouslyUpdatesValue</string> + <string>NSNoSelectionPlaceholder</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="5"/> + <string>no selection</string> + </object> </object> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> - <int key="connectionID">1322</int> + <int key="connectionID">1339</int> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> @@ -5189,11 +5179,13 @@ AQAAAAA</bytes> <bool key="EncodedWithXMLCoder">YES</bool> <object class="NSMutableArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> + <string>NSContinuouslyUpdatesValue</string> <string>NSNoSelectionPlaceholder</string> <string>NSNullPlaceholder</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="5"/> <string>no selection</string> <string>optional</string> </object> @@ -5201,7 +5193,7 @@ AQAAAAA</bytes> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> - <int key="connectionID">1323</int> + <int key="connectionID">1340</int> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> @@ -5218,11 +5210,13 @@ AQAAAAA</bytes> <bool key="EncodedWithXMLCoder">YES</bool> <object class="NSMutableArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> + <string>NSContinuouslyUpdatesValue</string> <string>NSNoSelectionPlaceholder</string> <string>NSNullPlaceholder</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="5"/> <string>no selection</string> <string>3306</string> </object> @@ -5230,7 +5224,7 @@ AQAAAAA</bytes> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> - <int key="connectionID">1324</int> + <int key="connectionID">1341</int> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> @@ -5244,13 +5238,22 @@ AQAAAAA</bytes> <string key="NSBinding">value</string> <string key="NSKeyPath">selection.sshHost</string> <object class="NSDictionary" key="NSOptions"> - <string key="NS.key.0">NSNoSelectionPlaceholder</string> - <string key="NS.object.0">no selection</string> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>NSContinuouslyUpdatesValue</string> + <string>NSNoSelectionPlaceholder</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="5"/> + <string>no selection</string> + </object> </object> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> - <int key="connectionID">1325</int> + <int key="connectionID">1342</int> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> @@ -5264,13 +5267,22 @@ AQAAAAA</bytes> <string key="NSBinding">value</string> <string key="NSKeyPath">selection.sshUser</string> <object class="NSDictionary" key="NSOptions"> - <string key="NS.key.0">NSNoSelectionPlaceholder</string> - <string key="NS.object.0">no selection</string> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>NSContinuouslyUpdatesValue</string> + <string>NSNoSelectionPlaceholder</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="5"/> + <string>no selection</string> + </object> </object> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> - <int key="connectionID">1326</int> + <int key="connectionID">1343</int> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> @@ -5287,11 +5299,13 @@ AQAAAAA</bytes> <bool key="EncodedWithXMLCoder">YES</bool> <object class="NSMutableArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> + <string>NSContinuouslyUpdatesValue</string> <string>NSNoSelectionPlaceholder</string> <string>NSNullPlaceholder</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="5"/> <string>no selection</string> <string>22</string> </object> @@ -5299,44 +5313,23 @@ AQAAAAA</bytes> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> - <int key="connectionID">1327</int> + <int key="connectionID">1344</int> </object> <object class="IBConnectionRecord"> - <object class="IBBindingConnection" key="connection"> - <string key="label">value: selection.name</string> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> <reference key="source" ref="415835787"/> - <reference key="destination" ref="937123943"/> - <object class="NSNibBindingConnector" key="connector"> - <reference key="NSSource" ref="415835787"/> - <reference key="NSDestination" ref="937123943"/> - <string key="NSLabel">value: selection.name</string> - <string key="NSBinding">value</string> - <string key="NSKeyPath">selection.name</string> - <object class="NSDictionary" key="NSOptions"> - <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSMutableArray" key="dict.sortedKeys"> - <bool key="EncodedWithXMLCoder">YES</bool> - <string>NSAllowsEditingMultipleValuesSelection</string> - <string>NSNoSelectionPlaceholder</string> - </object> - <object class="NSMutableArray" key="dict.values"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="6"/> - <string>no selection</string> - </object> - </object> - <int key="NSNibBindingConnectorVersion">2</int> - </object> + <reference key="destination" ref="1065964214"/> </object> - <int key="connectionID">1328</int> + <int key="connectionID">1346</int> </object> <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">favoriteTypeDidChange:</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="1065964214"/> + <object class="IBOutletConnection" key="connection"> + <string key="label">nextKeyView</string> + <reference key="source" ref="1065964214"/> + <reference key="destination" ref="77492794"/> </object> - <int key="connectionID">1329</int> + <int key="connectionID">1350</int> </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> @@ -8519,7 +8512,7 @@ AQAAAAA</bytes> </object> </object> <nil key="sourceID"/> - <int key="maxID">1329</int> + <int key="maxID">1350</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> diff --git a/Source/SPPreferenceController.h b/Source/SPPreferenceController.h index 221508a2..f5035787 100644 --- a/Source/SPPreferenceController.h +++ b/Source/SPPreferenceController.h @@ -45,22 +45,13 @@ IBOutlet NSArrayController *favoritesController; IBOutlet NSTabView *favoritesTabView; - IBOutlet NSTextField *nameField; - IBOutlet NSTextField *standardSQLHostField; - IBOutlet NSTextField *standardUserField; IBOutlet NSSecureTextField *standardPasswordField; - IBOutlet NSTextField *standardDatabaseField; - IBOutlet NSTextField *socketUserField; IBOutlet NSSecureTextField *socketPasswordField; - IBOutlet NSTextField *socketDatabaseField; - IBOutlet NSTextField *sshSQLHostField; - IBOutlet NSTextField *sshSQLUserField; IBOutlet NSSecureTextField *sshSQLPasswordField; - IBOutlet NSTextField *sshDatabaseField; - IBOutlet NSTextField *sshHostField; - IBOutlet NSTextField *sshUserField; IBOutlet NSSecureTextField *sshPasswordField; + KeyChain *keychain; + NSDictionary *currentFavorite; IBOutlet NSTextField *editorFontName; @@ -104,5 +95,6 @@ - (void)selectFavoriteAtIndex:(unsigned int)theIndex; - (void)changeFont:(id)sender; - (IBAction)favoriteTypeDidChange:(id)sender; +- (void)updateFavoritePasswordsFromField:(NSControl *)passwordControl; @end diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m index 9550e897..78d16a20 100644 --- a/Source/SPPreferenceController.m +++ b/Source/SPPreferenceController.m @@ -61,6 +61,7 @@ if (self = [super initWithWindowNibName:@"Preferences"]) { prefs = [NSUserDefaults standardUserDefaults]; [self applyRevisionChanges]; + currentFavorite = nil; } return self; @@ -597,7 +598,7 @@ [favoritesController setSelectionIndexes:[favoritesTableView selectedRowIndexes]]; } - // If no selection is present, blank the field. + // If no selection is present, blank the password fields (which can't use bindings) if ([[favoritesTableView selectedRowIndexes] count] == 0) { [standardPasswordField setStringValue:@""]; [socketPasswordField setStringValue:@""]; @@ -605,18 +606,22 @@ [sshPasswordField setStringValue:@""]; return; } + + // Keep a copy of the favorite as it currently stands + if (currentFavorite) [currentFavorite release]; + currentFavorite = [[[favoritesController selectedObjects] objectAtIndex:0] copy]; - // Otherwise retrieve and set the password. - NSString *keychainName = [keychain nameForFavoriteName:[favoritesController valueForKeyPath:@"selection.name"] id:[favoritesController valueForKeyPath:@"selection.id"]]; - NSString *keychainAccount = [keychain accountForUser:[favoritesController valueForKeyPath:@"selection.user"] host:[favoritesController valueForKeyPath:@"selection.host"] database:[favoritesController valueForKeyPath:@"selection.database"]]; + // Retrieve and set the password. + NSString *keychainName = [keychain nameForFavoriteName:[currentFavorite objectForKey:@"name"] id:[currentFavorite objectForKey:@"id"]]; + NSString *keychainAccount = [keychain accountForUser:[currentFavorite objectForKey:@"user"] host:[currentFavorite objectForKey:@"host"] database:[currentFavorite objectForKey:@"database"]]; NSString *passwordValue = [keychain getPasswordForName:keychainName account:keychainAccount]; [standardPasswordField setStringValue:passwordValue]; [socketPasswordField setStringValue:passwordValue]; [sshSQLPasswordField setStringValue:passwordValue]; // Retrieve the SSH keychain password if appropriate. - NSString *keychainSSHName = [keychain nameForSSHForFavoriteName:[favoritesController valueForKeyPath:@"selection.name"] id:[favoritesController valueForKeyPath:@"selection.id"]]; - NSString *keychainSSHAccount = [keychain accountForSSHUser:[favoritesController valueForKeyPath:@"selection.sshUser"] sshHost:[favoritesController valueForKeyPath:@"selection.sshHost"]]; + NSString *keychainSSHName = [keychain nameForSSHForFavoriteName:[currentFavorite objectForKey:@"name"] id:[currentFavorite objectForKey:@"id"]]; + NSString *keychainSSHAccount = [keychain accountForSSHUser:[currentFavorite objectForKey:@"sshUser"] sshHost:[currentFavorite objectForKey:@"sshHost"]]; [sshPasswordField setStringValue:[keychain getPasswordForName:keychainSSHName account:keychainSSHAccount]]; } @@ -709,130 +714,112 @@ // ------------------------------------------------------------------------------- - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor { - NSString *nameValue, *hostValue, *userValue, *databaseValue, *passwordValue; + + // Request a password refresh to keep keychain references in synch with favorites + [self updateFavoritePasswordsFromField:control]; + + // Proceed with editing + return YES; +} + +// ------------------------------------------------------------------------------- +// favoriteTypeDidChange: +// Update the favorite host when the type changes. +// ------------------------------------------------------------------------------- +- (IBAction)favoriteTypeDidChange:(id)sender +{ + if ([sender indexOfSelectedItem] == 1) { // Socket + [favoritesController setValue:@"localhost" forKeyPath:@"selection.host"]; + } else if ([[favoritesController valueForKeyPath:@"selection.host"] isEqualToString:@"localhost"]) { + [favoritesController setValue:@"" forKeyPath:@"selection.host"]; + } + + // Request a password refresh to keep keychain references in synch with the favorites + [self updateFavoritePasswordsFromField:nil]; +} + +// ------------------------------------------------------------------------------- +// updateFavoritePasswordsFromField: +// Check all fields used in the keychain names against the old values for that +// favorite, and update the keychain names to match if necessary. +// If an (optional) recognised password field is supplied, that field is assumed +// to have changed and is used to supply the new value. +// ------------------------------------------------------------------------------- +- (void)updateFavoritePasswordsFromField:(NSControl *)passwordControl +{ + if (!currentFavorite) return; + + NSString *passwordValue; NSString *oldKeychainName, *newKeychainName; NSString *oldKeychainAccount, *newKeychainAccount; - // Only proceed for name, host, user or database changes, for standard, socket or SSH - if (control != nameField && control != standardSQLHostField && control != standardUserField - && control != standardPasswordField && control != standardDatabaseField - && control != socketUserField && control != socketPasswordField - && control != socketDatabaseField && control != sshSQLHostField - && control != sshSQLUserField && control != sshSQLPasswordField - && control != sshDatabaseField && control != sshHostField - && control != sshUserField && control != sshPasswordField) - return YES; - - // Determine the appropriate name, host, user and database details - nameValue = [nameField stringValue]; - switch ([[favoritesController valueForKeyPath:@"selection.type"] intValue]) { - case 0: // Standard - hostValue = [standardSQLHostField stringValue]; - userValue = [standardUserField stringValue]; - databaseValue = [standardDatabaseField stringValue]; - passwordValue = [standardPasswordField stringValue]; - break; + // SQL passwords are indexed by name, host, user and database. If any of these + // have changed, or a standard password field has, alter the keychain item to match. + if (![[currentFavorite objectForKey:@"name"] isEqualToString:[favoritesController valueForKeyPath:@"selection.name"]] + || ![[currentFavorite objectForKey:@"host"] isEqualToString:[favoritesController valueForKeyPath:@"selection.host"]] + || ![[currentFavorite objectForKey:@"user"] isEqualToString:[favoritesController valueForKeyPath:@"selection.user"]] + || ![[currentFavorite objectForKey:@"database"] isEqualToString:[favoritesController valueForKeyPath:@"selection.database"]] + || passwordControl == standardPasswordField || passwordControl == socketPasswordField || passwordControl == sshSQLPasswordField) + { - case 1: // Socket - hostValue = @"localhost"; - userValue = [socketUserField stringValue]; - databaseValue = [socketDatabaseField stringValue]; + // Determine the correct password field to read the password from, defaulting to standard + if (passwordControl == socketPasswordField) { passwordValue = [socketPasswordField stringValue]; - break; - - case 2: // SSH - hostValue = [sshSQLHostField stringValue]; - userValue = [sshSQLUserField stringValue]; - databaseValue = [sshDatabaseField stringValue]; + } else if (passwordControl == sshSQLPasswordField) { passwordValue = [sshSQLPasswordField stringValue]; - break; - } - - // If account/password details have changed, update the keychain to match - if (![nameValue isEqualToString:[favoritesController valueForKeyPath:@"selection.name"]] - || ![hostValue isEqualToString:[favoritesController valueForKeyPath:@"selection.host"]] - || ![userValue isEqualToString:[favoritesController valueForKeyPath:@"selection.user"]] - || ![databaseValue isEqualToString:[favoritesController valueForKeyPath:@"selection.database"]] - || control == standardPasswordField || control == socketPasswordField || control == sshSQLPasswordField) { - - // Get the current keychain name and account strings - oldKeychainName = [keychain nameForFavoriteName:[favoritesController valueForKeyPath:@"selection.name"] id:[favoritesController valueForKeyPath:@"selection.id"]]; - oldKeychainAccount = [keychain accountForUser:[favoritesController valueForKeyPath:@"selection.user"] host:[favoritesController valueForKeyPath:@"selection.host"] database:[favoritesController valueForKeyPath:@"selection.database"]]; + } else { + passwordValue = [standardPasswordField stringValue]; + } - // Set up the new keychain name and account strings - newKeychainName = [keychain nameForFavoriteName:nameValue id:[favoritesController valueForKeyPath:@"selection.id"]]; - newKeychainAccount = [keychain accountForUser:userValue host:hostValue database:databaseValue]; + // Get the old keychain name and account strings + oldKeychainName = [keychain nameForFavoriteName:[currentFavorite objectForKey:@"name"] id:[favoritesController valueForKeyPath:@"selection.id"]]; + oldKeychainAccount = [keychain accountForUser:[currentFavorite objectForKey:@"user"] host:[currentFavorite objectForKey:@"host"] database:[currentFavorite objectForKey:@"database"]]; // Delete the old keychain item [keychain deletePasswordForName:oldKeychainName account:oldKeychainAccount]; + // Set up the new keychain name and account strings + newKeychainName = [keychain nameForFavoriteName:[favoritesController valueForKeyPath:@"selection.name"] id:[favoritesController valueForKeyPath:@"selection.id"]]; + newKeychainAccount = [keychain accountForUser:[favoritesController valueForKeyPath:@"selection.user"] host:[favoritesController valueForKeyPath:@"selection.host"] database:[favoritesController valueForKeyPath:@"selection.database"]]; + // Add the new keychain item if the password field has a value if ([passwordValue length]) [keychain addPassword:passwordValue forName:newKeychainName account:newKeychainAccount]; + + // Synch password changes + [standardPasswordField setStringValue:passwordValue]; + [socketPasswordField setStringValue:passwordValue]; + [sshSQLPasswordField setStringValue:passwordValue]; + + passwordValue = @""; } - - // Synch password changes - [standardPasswordField setStringValue:passwordValue]; - [socketPasswordField setStringValue:passwordValue]; - [sshSQLPasswordField setStringValue:passwordValue]; // If SSH account/password details have changed, update the keychain to match - if (![[nameField stringValue] isEqualToString:[favoritesController valueForKeyPath:@"selection.name"]] - || ![[sshHostField stringValue] isEqualToString:[favoritesController valueForKeyPath:@"selection.sshHost"]] - || ![[sshUserField stringValue] isEqualToString:[favoritesController valueForKeyPath:@"selection.sshUser"]] - || control == sshPasswordField) { - - // Get the current keychain name and account strings - oldKeychainName = [keychain nameForSSHForFavoriteName:[favoritesController valueForKeyPath:@"selection.name"] id:[favoritesController valueForKeyPath:@"selection.id"]]; - oldKeychainAccount = [keychain accountForSSHUser:[favoritesController valueForKeyPath:@"selection.sshUser"] sshHost:[favoritesController valueForKeyPath:@"selection.sshHost"]]; + if (![[currentFavorite objectForKey:@"name"] isEqualToString:[favoritesController valueForKeyPath:@"selection.name"]] + || ![[currentFavorite objectForKey:@"sshHost"] isEqualToString:[favoritesController valueForKeyPath:@"selection.sshHost"]] + || ![[currentFavorite objectForKey:@"sshUser"] isEqualToString:[favoritesController valueForKeyPath:@"selection.sshUser"]] + || passwordControl == sshPasswordField) { - // Set up the new keychain name and account strings - newKeychainName = [keychain nameForSSHForFavoriteName:nameValue id:[favoritesController valueForKeyPath:@"selection.id"]]; - newKeychainAccount = [keychain accountForSSHUser:[sshUserField stringValue] sshHost:[sshHostField stringValue]]; + // Get the old keychain name and account strings + oldKeychainName = [keychain nameForSSHForFavoriteName:[currentFavorite objectForKey:@"name"] id:[favoritesController valueForKeyPath:@"selection.id"]]; + oldKeychainAccount = [keychain accountForSSHUser:[currentFavorite objectForKey:@"sshUser"] sshHost:[currentFavorite objectForKey:@"sshHost"]]; // Delete the old keychain item [keychain deletePasswordForName:oldKeychainName account:oldKeychainAccount]; + // Set up the new keychain name and account strings + newKeychainName = [keychain nameForSSHForFavoriteName:[favoritesController valueForKeyPath:@"selection.name"] id:[favoritesController valueForKeyPath:@"selection.id"]]; + newKeychainAccount = [keychain accountForSSHUser:[favoritesController valueForKeyPath:@"selection.sshUser"] sshHost:[favoritesController valueForKeyPath:@"selection.sshHost"]]; + // Add the new keychain item if the password field has a value if ([[sshPasswordField stringValue] length]) [keychain addPassword:[sshPasswordField stringValue] forName:newKeychainName account:newKeychainAccount]; } - // Proceed with editing - return YES; -} - -// ------------------------------------------------------------------------------- -// favoriteTypeDidChange: -// Update the favorite host when the type changes. -// ------------------------------------------------------------------------------- -- (IBAction)favoriteTypeDidChange:(id)sender -{ - NSString *oldKeychainName, *newKeychainName; - NSString *oldKeychainAccount, *newKeychainAccount; - - // Get the current keychain name and account strings - oldKeychainName = [keychain nameForFavoriteName:[favoritesController valueForKeyPath:@"selection.name"] id:[favoritesController valueForKeyPath:@"selection.id"]]; - oldKeychainAccount = [keychain accountForUser:[favoritesController valueForKeyPath:@"selection.user"] host:[favoritesController valueForKeyPath:@"selection.host"] database:[favoritesController valueForKeyPath:@"selection.database"]]; - - // Delete the old keychain item - [keychain deletePasswordForName:oldKeychainName account:oldKeychainAccount]; - - if ([sender indexOfSelectedItem] == 1) { // Socket - [favoritesController setValue:@"localhost" forKeyPath:@"selection.host"]; - [self control:socketPasswordField textShouldEndEditing:nil]; - } else if ([[favoritesController valueForKeyPath:@"selection.host"] isEqualToString:@"localhost"]) { - [favoritesController setValue:@"" forKeyPath:@"selection.host"]; - [self control:standardPasswordField textShouldEndEditing:nil]; - } - - // Set up the new keychain name and account strings - newKeychainName = [keychain nameForFavoriteName:[favoritesController valueForKeyPath:@"selection.name"] id:[favoritesController valueForKeyPath:@"selection.id"]]; - newKeychainAccount = [keychain accountForUser:[favoritesController valueForKeyPath:@"selection.user"] host:[favoritesController valueForKeyPath:@"selection.host"] database:[favoritesController valueForKeyPath:@"selection.database"]]; - - // Add the new keychain item if the password field has a value - if ([[standardPasswordField stringValue] length]) - [keychain addPassword:[standardPasswordField stringValue] forName:newKeychainName account:newKeychainAccount]; + // Update the current favorite + if (currentFavorite) [currentFavorite release], currentFavorite = nil; + if ([[favoritesTableView selectedRowIndexes] count] > 0) + currentFavorite = [[[favoritesController selectedObjects] objectAtIndex:0] copy]; } #pragma mark - @@ -913,6 +900,7 @@ - (void)selectFavorites:(NSArray *)favorites { [favoritesController setSelectedObjects:favorites]; + [favoritesTableView scrollRowToVisible:[favoritesController selectionIndex]]; } // ------------------------------------------------------------------------------- @@ -923,6 +911,7 @@ - (void)selectFavoriteAtIndex:(unsigned int)theIndex { [favoritesController setSelectionIndex:theIndex]; + [favoritesTableView scrollRowToVisible:theIndex]; } // ------------------------------------------------------------------------------- @@ -970,7 +959,8 @@ - (void)dealloc { [keychain release], keychain = nil; - + if (currentFavorite) [currentFavorite release]; + [super dealloc]; } |