aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/TableDocument.h7
-rw-r--r--Source/TableDocument.m114
-rw-r--r--Source/TablesList.m20
3 files changed, 50 insertions, 91 deletions
diff --git a/Source/TableDocument.h b/Source/TableDocument.h
index f6019e58..10b780a5 100644
--- a/Source/TableDocument.h
+++ b/Source/TableDocument.h
@@ -54,6 +54,7 @@
IBOutlet id favoritesButton;
IBOutlet NSTableView *connectFavoritesTableView;
IBOutlet NSArrayController *favoritesController;
+ IBOutlet id nameField;
IBOutlet id hostField;
IBOutlet id socketField;
IBOutlet id userField;
@@ -86,7 +87,6 @@
NSString *selectedDatabase;
NSString *mySQLVersion;
NSUserDefaults *prefs;
- NSString *favoriteNameBeingChanged;
NSMenu *selectEncodingMenu;
BOOL _supportsEncoding;
@@ -107,11 +107,11 @@
- (IBAction)cancelConnectSheet:(id)sender;
- (IBAction)closeSheet:(id)sender;
- (IBAction)chooseFavorite:(id)sender;
-- (IBAction)removeFavorite:(id)sender;
+- (IBAction)editFavorites:(id)sender;
- (id)selectedFavorite;
- (NSString *)selectedFavoritePassword;
- (void)connectSheetAddToFavorites:(id)sender;
-- (void)addToFavoritesHost:(NSString *)host socket:(NSString *)socket
+- (void)addToFavoritesName:(NSString *)name host:(NSString *)host socket:(NSString *)socket
user:(NSString *)user password:(NSString *)password
port:(NSString *)port database:(NSString *)database
useSSH:(BOOL)useSSH // no-longer in use
@@ -164,6 +164,7 @@
- (void)closeConnection;
//getter methods
+- (NSString *)name;
- (NSString *)database;
- (NSString *)table;
- (NSString *)mySQLVersion;
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index 97e3ecbc..f58b9b29 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -75,6 +75,7 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
// register double click for the favorites view (double click favorite to connect)
[connectFavoritesTableView setTarget:self];
+ [connectFavoritesTableView setDoubleAction:@selector(connect:)];
// find the Database -> Database Encoding menu (it's not in our nib, so we can't use interface builder)
selectEncodingMenu = [[[[[NSApp mainMenu] itemWithTag:1] submenu] itemWithTag:1] submenu];
@@ -240,6 +241,7 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
// Connect automatically to the last used or default favourite
// connectSheet must open first.
if (_shouldOpenConnectionAutomatically) {
+ _shouldOpenConnectionAutomatically = false;
[self connect:self];
}
}
@@ -341,8 +343,7 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
[tableDataInstance setConnection:mySQLConnection];
[self setFileName:[NSString stringWithFormat:@"(MySQL %@) %@@%@ %@", mySQLVersion, [userField stringValue],
[hostField stringValue], [databaseField stringValue]]];
- [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@", mySQLVersion, [userField stringValue],
- [hostField stringValue], [databaseField stringValue]]];
+ [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@/%@", mySQLVersion, [self name], [databaseField stringValue]]];
// Connected Growl notification
[[SPGrowlController sharedGrowlController] notifyWithTitle:@"Connected"
@@ -391,6 +392,7 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
if (![self selectedFavorite])
return;
+ [nameField setStringValue:[self valueForKeyPath:@"selectedFavorite.name"]];
[hostField setStringValue:[self valueForKeyPath:@"selectedFavorite.host"]];
[socketField setStringValue:[self valueForKeyPath:@"selectedFavorite.socket"]];
[userField setStringValue:[self valueForKeyPath:@"selectedFavorite.user"]];
@@ -402,28 +404,11 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
}
/**
- * Remove the selected favourite. Instead of calling the remove: method of the Favorites NSArrayController
- * directly in the XIB we do it here because we also need to remove the keychain password.
+ * Opens the preferences window, or brings it to the front, and switch to the favorites tab.
+ * If a favorite is selected in the connection sheet, it is also select in the prefs window.
*/
-- (IBAction)removeFavorite:(id)sender
+- (IBAction)editFavorites:(id)sender
{
- if (![self selectedFavorite]) {
- return;
- }
-
- NSString *name = [self valueForKeyPath:@"selectedFavorite.name"];
- NSString *user = [self valueForKeyPath:@"selectedFavorite.user"];
- NSString *host = [self valueForKeyPath:@"selectedFavorite.host"];
- NSString *database = [self valueForKeyPath:@"selectedFavorite.database"];
- int favoriteid = [[self valueForKeyPath:@"selectedFavorite.id"] intValue];
-
- [keyChainInstance deletePasswordForName:[NSString stringWithFormat:@"Sequel Pro : %@ (%i)", name, favoriteid]
- account:[NSString stringWithFormat:@"%@@%@/%@", user, host, database]];
- [keyChainInstance deletePasswordForName:[NSString stringWithFormat:@"Sequel Pro SSHTunnel : %@ (%i)", name, favoriteid]
- account:[NSString stringWithFormat:@"%@@%@/%@", user, host, database]];
-
- // Remove from favorites array controller
- [favoritesController remove:[self selectedFavorite]];
}
@@ -459,24 +444,24 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
- (void)connectSheetAddToFavorites:(id)sender
{
- [self addToFavoritesHost:[hostField stringValue] socket:[socketField stringValue] user:[userField stringValue] password:[passwordField stringValue] port:[portField stringValue] database:[databaseField stringValue] useSSH:false sshHost:@"" sshUser:@"" sshPassword:@"" sshPort:@""];
+ [self addToFavoritesName:[nameField stringValue] host:[hostField stringValue] socket:[socketField stringValue] user:[userField stringValue] password:[passwordField stringValue] port:[portField stringValue] database:[databaseField stringValue] useSSH:false sshHost:@"" sshUser:@"" sshPassword:@"" sshPort:@""];
}
/**
* add actual connection to favorites
*/
-- (void)addToFavoritesHost:(NSString *)host socket:(NSString *)socket
- user:(NSString *)user password:(NSString *)password
- port:(NSString *)port database:(NSString *)database
- useSSH:(BOOL)useSSH // no-longer in use
- sshHost:(NSString *)sshHost // no-longer in use
- sshUser:(NSString *)sshUser // no-longer in use
- sshPassword:(NSString *)sshPassword // no-longer in use
- sshPort:(NSString *)sshPort // no-longer in use
+- (void)addToFavoritesName:(NSString *)name host:(NSString *)host socket:(NSString *)socket
+ user:(NSString *)user password:(NSString *)password
+ port:(NSString *)port database:(NSString *)database
+ useSSH:(BOOL)useSSH // no-longer in use
+ sshHost:(NSString *)sshHost // no-longer in use
+ sshUser:(NSString *)sshUser // no-longer in use
+ sshPassword:(NSString *)sshPassword // no-longer in use
+ sshPort:(NSString *)sshPort // no-longer in use
{
- NSString *favoriteName = [NSString stringWithFormat:@"%@@%@", user, host];
+ NSString *favoriteName = [name length]?name:[NSString stringWithFormat:@"%@@%@", user, host];
NSNumber *favoriteid = [NSNumber numberWithInt:[[NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]] hash]];
- if (![database isEqualToString:@""])
+ if (![name length] && ![database isEqualToString:@""])
favoriteName = [NSString stringWithFormat:@"%@ %@", database, favoriteName];
// test if host and socket are not nil
@@ -529,7 +514,7 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
[self setDatabases:self];
[tablesListInstance setConnection:mySQLConnection];
[tableDumpInstance setConnection:mySQLConnection];
- [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/", mySQLVersion, [userField stringValue], [hostField stringValue]]];
+ [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@/", mySQLVersion, [self name]]];
}
}
@@ -601,7 +586,7 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
selectedDatabase = [[chooseDatabaseButton titleOfSelectedItem] retain];
[tablesListInstance setConnection:mySQLConnection];
[tableDumpInstance setConnection:mySQLConnection];
- [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@", mySQLVersion, [userField stringValue], [hostField stringValue], [self database]]];
+ [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@/%@", mySQLVersion, [self name], [self database]]];
}
/**
@@ -670,7 +655,7 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
[self setDatabases:self];
[tablesListInstance setConnection:mySQLConnection];
[tableDumpInstance setConnection:mySQLConnection];
- [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@", mySQLVersion, [userField stringValue], [hostField stringValue], selectedDatabase]];
+ [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@/%@", mySQLVersion, [self name], selectedDatabase]];
}
/**
@@ -1239,6 +1224,17 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
}
/**
+ * Returns the name
+ */
+- (NSString *)name
+{
+ if ([[nameField stringValue] length]) {
+ return [nameField stringValue];
+ }
+ return [NSString stringWithFormat:@"%@@%@", [userField stringValue], [hostField stringValue]];
+}
+
+/**
* Passes query to tablesListInstance
*/
- (void)doPerformQueryService:(NSString *)query
@@ -1860,8 +1856,10 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
*/
- (void) controlTextDidChange:(NSNotification *)aNotification
{
- if ([aNotification object] == hostField || [aNotification object] == userField || [aNotification object] == passwordField
- || [aNotification object] == databaseField || [aNotification object] == socketField || [aNotification object] == portField) {
+ if ([aNotification object] == nameField || [aNotification object] == hostField
+ || [aNotification object] == userField || [aNotification object] == passwordField
+ || [aNotification object] == databaseField || [aNotification object] == socketField
+ || [aNotification object] == portField) {
[favoritesController setSelectionIndexes:[NSIndexSet indexSet]];
}
else if ([aNotification object] == databaseNameField) {
@@ -1956,46 +1954,6 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
return theValue;
}
-/**
- * Although the connection sheet tableview uses bindings to display the favourites we implement this method in
- * order to update the keychain associated with favourites that are renamed. Its not the best approach, but it works.
- */
-- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
-{
- NSDictionary *favorite = [[favoritesController arrangedObjects] objectAtIndex:rowIndex];
- NSMutableDictionary *newFavorite;
-
- [keyChainInstance deletePasswordForName:[NSString stringWithFormat:@"Sequel Pro : %@ (%i)", favoriteNameBeingChanged, [[favorite objectForKey:@"id"] intValue]]
- account:[NSString stringWithFormat:@"%@@%@/%@", [favorite objectForKey:@"user"], [favorite objectForKey:@"host"], [favorite objectForKey:@"database"]]];
-
- if ([[passwordField stringValue] length]) {
- [keyChainInstance addPassword:[passwordField stringValue]
- forName:[NSString stringWithFormat:@"Sequel Pro : %@ (%i)", object, [[favorite objectForKey:@"id"] intValue]]
- account:[NSString stringWithFormat:@"%@@%@/%@", [favorite objectForKey:@"user"], [favorite objectForKey:@"host"], [favorite objectForKey:@"database"]]];
- }
-
- // Update the favorites array controller
- newFavorite = [NSMutableDictionary dictionaryWithDictionary:favorite];
- [newFavorite setObject:[NSString stringWithString:object] forKey:@"name"];
- [favoritesController insertObject:newFavorite atArrangedObjectIndex:rowIndex];
- [favoritesController removeObjectAtArrangedObjectIndex:(rowIndex+1)];
- [favoritesController setSelectionIndex:rowIndex];
-
- favoriteNameBeingChanged = nil;
-}
-
-/**
- * We implement this method so we can get the name of the favourtie before its renamed. We need the name so we
- * look it up in the keychain and update its name, which is done in the above method. This is obviously not the
- * best approach to doing this as it means we need an ivar just to track the favourite that is about to be renamed.
- */
-- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
-{
- favoriteNameBeingChanged = [[[favoritesController arrangedObjects] objectAtIndex:rowIndex] objectForKey:@"name"];
-
- return YES;
-}
-
- (IBAction)terminate:(id)sender
{
[[NSApp orderedDocuments] makeObjectsPerformSelector:@selector(cancelConnectSheet:) withObject:nil];
diff --git a/Source/TablesList.m b/Source/TablesList.m
index 148c7ab2..ef1f3531 100644
--- a/Source/TablesList.m
+++ b/Source/TablesList.m
@@ -179,8 +179,8 @@
}
// Set window title
- [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@/%@", [tableDocumentInstance mySQLVersion], [tableDocumentInstance user],
- [tableDocumentInstance host], [tableDocumentInstance database], tableName]];
+ [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@/%@/%@", [tableDocumentInstance mySQLVersion],
+ [tableDocumentInstance name], [tableDocumentInstance database], tableName]];
}
else {
// Error while creating new table
@@ -397,8 +397,8 @@
[tablesListView reloadData];
// set window title
- [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@", [tableDocumentInstance mySQLVersion], [tableDocumentInstance user],
- [tableDocumentInstance host], [tableDocumentInstance database]]];
+ [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@/%@", [tableDocumentInstance mySQLVersion],
+ [tableDocumentInstance name], [tableDocumentInstance database]]];
if ( error )
NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil,
[NSString stringWithFormat:NSLocalizedString(@"Couldn't remove table.\nMySQL said: %@", @"message of panel when table cannot be removed"), errorText]);
@@ -579,8 +579,8 @@
}
// Set window title
- [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@/%@", [tableDocumentInstance mySQLVersion], [tableDocumentInstance user],
- [tableDocumentInstance host], [tableDocumentInstance database], anObject]];
+ [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@/%@/%@", [tableDocumentInstance mySQLVersion],
+ [tableDocumentInstance name], [tableDocumentInstance database], anObject]];
}
else {
// Error while renaming
@@ -685,8 +685,8 @@
}
// set window title
- [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@/%@", [tableDocumentInstance mySQLVersion], [tableDocumentInstance user],
- [tableDocumentInstance host], [tableDocumentInstance database], [tables objectAtIndex:[tablesListView selectedRow]]]];
+ [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@/%@/%@", [tableDocumentInstance mySQLVersion],
+ [tableDocumentInstance name], [tableDocumentInstance database], [tables objectAtIndex:[tablesListView selectedRow]]]];
} else {
[tableSourceInstance loadTable:nil];
[tableContentInstance loadTable:nil];
@@ -696,8 +696,8 @@
statusLoaded = NO;
// set window title
- [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@", [tableDocumentInstance mySQLVersion], [tableDocumentInstance user],
- [tableDocumentInstance host], [tableDocumentInstance database]]];
+ [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@/%@", [tableDocumentInstance mySQLVersion],
+ [tableDocumentInstance name], [tableDocumentInstance database]]];
}
}