aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Interfaces/English.lproj/MainMenu.xib44
-rw-r--r--Source/TableDocument.h1
-rw-r--r--Source/TableDocument.m48
3 files changed, 84 insertions, 9 deletions
diff --git a/Interfaces/English.lproj/MainMenu.xib b/Interfaces/English.lproj/MainMenu.xib
index ed5a59d3..17277447 100644
--- a/Interfaces/English.lproj/MainMenu.xib
+++ b/Interfaces/English.lproj/MainMenu.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="758"/>
+ <integer value="81"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -240,6 +240,14 @@
<reference key="NSOnImage" ref="625762401"/>
<reference key="NSMixedImage" ref="315854375"/>
</object>
+ <object class="NSMenuItem" id="791156990">
+ <reference key="NSMenu" ref="709725194"/>
+ <string key="NSTitle">Add To Favorites...</string>
+ <string key="NSKeyEquiv"/>
+ <int key="NSMnemonicLoc">2147483647</int>
+ <reference key="NSOnImage" ref="625762401"/>
+ <reference key="NSMixedImage" ref="315854375"/>
+ </object>
<object class="NSMenuItem" id="3878246">
<reference key="NSMenu" ref="709725194"/>
<bool key="NSIsDisabled">YES</bool>
@@ -4192,6 +4200,14 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
</object>
<int key="connectionID">905</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">addConnectionToFavorites:</string>
+ <reference key="source" ref="63651044"/>
+ <reference key="destination" ref="791156990"/>
+ </object>
+ <int key="connectionID">909</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -4412,6 +4428,7 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
<reference ref="258329286"/>
<reference ref="390057667"/>
<reference ref="3878246"/>
+ <reference ref="791156990"/>
</object>
<reference key="parent" ref="86447006"/>
</object>
@@ -6342,6 +6359,11 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
<reference key="object" ref="449401330"/>
<reference key="parent" ref="1056168652"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">908</int>
+ <reference key="object" ref="791156990"/>
+ <reference key="parent" ref="709725194"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -6927,6 +6949,7 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
<string>864.IBPluginDependency</string>
<string>865.IBPluginDependency</string>
<string>906.IBPluginDependency</string>
+ <string>908.IBPluginDependency</string>
<string>92.IBPluginDependency</string>
<string>92.ImportedFromIB2</string>
</object>
@@ -6989,7 +7012,7 @@ ARcABAAAAAEAAAACARwAAwAAAAEAAQAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
- <string>{{677, 298}, {146, 213}}</string>
+ <string>{{421, 149}, {146, 213}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{654, 613}, {157, 223}}</string>
@@ -7103,7 +7126,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
</object>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
- <string>{{928, 484}, {197, 73}}</string>
+ <string>{{652, 289}, {197, 73}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{449, 1007}, {197, 53}}</string>
@@ -7199,7 +7222,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
</object>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
- <string>{{202, 280}, {511, 20}}</string>
+ <string>{{363, 768}, {511, 20}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{506, 836}, {511, 20}}</string>
@@ -7290,7 +7313,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
- <string>{{808, 328}, {235, 183}}</string>
+ <string>{{594, 238}, {235, 183}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{698, 703}, {184, 133}}</string>
@@ -7413,7 +7436,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
- <string>{{444, 127}, {231, 153}}</string>
+ <string>{{644, 268}, {231, 153}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{312, 683}, {231, 153}}</string>
@@ -7532,7 +7555,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{525, 97}, {268, 183}}</string>
+ <string>{{725, 238}, {268, 183}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{829, 663}, {268, 173}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -7561,7 +7584,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{722, 358}, {205, 153}}</string>
+ <string>{{469, 595}, {222, 173}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{180, 535}, {182, 253}}</string>
@@ -7661,6 +7684,7 @@ w6gg4oaSIGZhY2FkZV0</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
</object>
</object>
@@ -7684,7 +7708,7 @@ w6gg4oaSIGZhY2FkZV0</string>
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">907</int>
+ <int key="maxID">909</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -8017,6 +8041,7 @@ w6gg4oaSIGZhY2FkZV0</string>
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMutableArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
+ <string>addConnectionToFavorites:</string>
<string>addDatabase:</string>
<string>analyzeTable:</string>
<string>cancelConnectSheet:</string>
@@ -8082,6 +8107,7 @@ w6gg4oaSIGZhY2FkZV0</string>
<string>id</string>
<string>id</string>
<string>id</string>
+ <string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
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