diff options
author | stuconnolly <stuart02@gmail.com> | 2009-04-10 12:44:06 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2009-04-10 12:44:06 +0000 |
commit | 8340fe85798a0ed932de04ed9f740781728ab7f1 (patch) | |
tree | b24d5f8b915962976bdbce77243e5c1cb83c7418 /Source/TableDocument.m | |
parent | 68b9bbc92bfdcb027db31e775cf67b3c573d473b (diff) | |
download | sequelpro-8340fe85798a0ed932de04ed9f740781728ab7f1.tar.gz sequelpro-8340fe85798a0ed932de04ed9f740781728ab7f1.tar.bz2 sequelpro-8340fe85798a0ed932de04ed9f740781728ab7f1.zip |
Implementation of enhancement described in issue #75. You can now add the current connection details to your favourites provided it doesn't already exist.
Diffstat (limited to 'Source/TableDocument.m')
-rw-r--r-- | Source/TableDocument.m | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Source/TableDocument.m b/Source/TableDocument.m index f6e419c5..e8599c47 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -44,6 +44,12 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocumentFavoritesControllerSelectionIndexDidChange"; NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocumentFavoritesControllerFavoritesDidChange"; +@interface TableDocument (PrivateAPI) + +- (BOOL)_favoriteAlreadyExists:(NSString *)database host:(NSString *)host user:(NSString *)user; + +@end + @implementation TableDocument - (id)init @@ -1351,6 +1357,10 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum return ([self table] != nil && [[self table] isNotEqualTo:@""]); } + if ([menuItem action] == @selector(addConnectionToFavorites:)) { + return (![self _favoriteAlreadyExists:[self database] host:[self host] user:[self user]]); + } + return [super validateMenuItem:menuItem]; } @@ -1423,6 +1433,21 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum [mainToolbar setSelectedItemIdentifier:@"SwitchToTableStatusToolbarItemIdentifier"]; } +/** + * Adds the current database connection details to the user's favorites if it doesn't already exist. + */ +- (IBAction)addConnectionToFavorites:(id)sender +{ + // Obviously don't add if it already exists. We shouldn't really need this as the menu item validation + // enables or disables the menu item based on the same method. Although to be safe do the check anyway + // as we don't know what's calling this method. + if ([self _favoriteAlreadyExists:[self database] host:[self host] user:[self user]]) { + return; + } + + // Add current connection to favorites using the same method as used on the connection sheet to provide consistency. + [self connectSheetAddToFavorites:self]; +} #pragma mark Toolbar Methods @@ -1887,3 +1912,26 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum } @end + +@implementation TableDocument (PrivateAPI) + +/** + * Checks to see if a favorite with the supplied details already exists. + */ +- (BOOL)_favoriteAlreadyExists:(NSString *)database host:(NSString *)host user:(NSString *)user +{ + // Loop the favorites and check their details + for (NSDictionary *favorite in favorites) + { + if ([[favorite objectForKey:@"database"] isEqualToString:database] && + [[favorite objectForKey:@"host"] isEqualToString:host] && + [[favorite objectForKey:@"user"] isEqualToString:user]) { + + return YES; + } + } + + return NO; +} + +@end |