aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/TableDocument.h1
-rw-r--r--Source/TableDocument.m48
2 files changed, 49 insertions, 0 deletions
diff --git a/Source/TableDocument.h b/Source/TableDocument.h
index b9426e31..de062124 100644
--- a/Source/TableDocument.h
+++ b/Source/TableDocument.h
@@ -179,6 +179,7 @@
- (IBAction)viewContent:(id)sender;
- (IBAction)viewQuery:(id)sender;
- (IBAction)viewStatus:(id)sender;
+- (IBAction)addConnectionToFavorites:(id)sender;
//toolbar methods
- (void)setupToolbar;
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