aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Resources/Plists/Info.plist8
-rw-r--r--Source/SPAppController.m44
-rw-r--r--Source/SPConnectionController.h1
-rw-r--r--Source/SPConnectionController.m7
-rw-r--r--Source/SPDatabaseDocument.h1
-rw-r--r--Source/SPDatabaseDocument.m32
6 files changed, 80 insertions, 13 deletions
diff --git a/Resources/Plists/Info.plist b/Resources/Plists/Info.plist
index 2ba52aa3..a0b1401b 100644
--- a/Resources/Plists/Info.plist
+++ b/Resources/Plists/Info.plist
@@ -173,6 +173,14 @@
<string>sequelpro</string>
</array>
</dict>
+ <dict>
+ <key>CFBundleURLName</key>
+ <string>MySQL URL scheme</string>
+ <key>CFBundleURLSchemes</key>
+ <array>
+ <string>mysql</string>
+ </array>
+ </dict>
</array>
<key>CFBundleVersion</key>
<string></string>
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index 9ff2cad0..d733b48a 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -765,15 +765,57 @@
{
NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
- if (url) {
+ if ([[url scheme] isEqualToString:@"sequelpro"]) {
[self handleEventWithURL:url];
}
+ else if([[url scheme] isEqualToString:@"mysql"]) {
+ [self handleMySQLConnectWithURL:url];
+ }
else {
NSBeep();
NSLog(@"Error in sequelpro URL scheme");
}
}
+- (void)handleMySQLConnectWithURL:(NSURL *)url
+{
+ if(![[url scheme] isEqualToString:@"mysql"]) {
+ SPLog(@"unsupported url scheme: %@",url);
+ return;
+ }
+
+ // make connection window
+ [self newTab:nil];
+ SPDatabaseDocument *doc = [self frontDocument];
+
+ NSMutableDictionary *details = [NSMutableDictionary dictionary];
+
+ NSValue *connect = @NO;
+
+ [details setObject:@"SPTCPIPConnection" forKey:@"type"];
+ if([url port])
+ [details setObject:[url port] forKey:@"port"];
+
+ if([url user])
+ [details setObject:[url user] forKey:@"user"];
+
+ if([url password]) {
+ [details setObject:[url password] forKey:@"password"];
+ connect = @YES;
+ }
+
+ if([[url host] length] && ![[url host] isEqualToString:@"localhost"])
+ [details setObject:[url host] forKey:@"host"];
+ else
+ [details setObject:@"127.0.0.1" forKey:@"host"];
+
+ NSArray *pc = [url pathComponents];
+ if([pc count] > 1) // first object is "/"
+ [details setObject:[pc objectAtIndex:1] forKey:@"database"];
+
+ [doc setState:@{@"connection":details,@"auto_connect": connect} fromFile:NO];
+}
+
- (void)handleEventWithURL:(NSURL*)url
{
NSString *command = [url host];
diff --git a/Source/SPConnectionController.h b/Source/SPConnectionController.h
index 99488600..f154ef77 100644
--- a/Source/SPConnectionController.h
+++ b/Source/SPConnectionController.h
@@ -255,6 +255,7 @@
- (IBAction)duplicateFavorite:(id)sender;
- (IBAction)renameNode:(id)sender;
- (IBAction)makeSelectedFavoriteDefault:(id)sender;
+- (void)selectQuickConnectItem;
// Import/export favorites
- (IBAction)importFavorites:(id)sender;
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index 0340fd8e..5168d2c6 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -1013,6 +1013,11 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
[prefs setInteger:favoriteID forKey:SPDefaultFavorite];
}
+
+- (void)selectQuickConnectItem
+{
+ return [self _selectNode:quickConnectItem];
+}
#pragma mark -
#pragma mark Import/export favorites
@@ -1704,7 +1709,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
[self _reloadFavoritesViewData];
// Select Quick Connect item to prevent empty selection
- [self _selectNode:quickConnectItem];
+ [self selectQuickConnectItem];
[connectionResizeContainer setHidden:NO];
[connectionInstructionsTextField setStringValue:NSLocalizedString(@"Enter connection details below, or choose a favorite", @"enter connection details label")];
diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h
index a29f91cc..7419b408 100644
--- a/Source/SPDatabaseDocument.h
+++ b/Source/SPDatabaseDocument.h
@@ -515,6 +515,7 @@
// State saving and setting
- (NSDictionary *) stateIncludingDetails:(NSDictionary *)detailsToReturn;
- (BOOL)setState:(NSDictionary *)stateDetails;
+- (BOOL)setState:(NSDictionary *)stateDetails fromFile:(BOOL)spfBased;
- (BOOL)setStateFromConnectionFile:(NSString *)path;
- (void)restoreSession;
#endif
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 66a56ea7..23d4a529 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -4633,12 +4633,17 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
return stateDetails;
}
+- (BOOL)setState:(NSDictionary *)stateDetails
+{
+ return [self setState:stateDetails fromFile:YES];
+}
+
/**
* Set the state of the document to the supplied dictionary, which should
* at least contain a "connection" dictionary of details.
* Returns whether the state was set successfully.
*/
-- (BOOL)setState:(NSDictionary *)stateDetails
+- (BOOL)setState:(NSDictionary *)stateDetails fromFile:(BOOL)spfBased
{
NSDictionary *connection = nil;
NSInteger connectionType = -1;
@@ -4655,15 +4660,20 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
[self updateWindowTitle:self];
- // Deselect all favorites on the connection controller,
- // and clear and reset the connection state.
- [[connectionController favoritesOutlineView] deselectAll:connectionController];
- [connectionController updateFavoriteSelection:self];
-
- // Suppress the possibility to choose an other connection from the favorites
- // if a connection should initialized by SPF file. Otherwise it could happen
- // that the SPF file runs out of sync.
- [[connectionController favoritesOutlineView] setEnabled:NO];
+ if(spfBased) {
+ // Deselect all favorites on the connection controller,
+ // and clear and reset the connection state.
+ [[connectionController favoritesOutlineView] deselectAll:connectionController];
+ [connectionController updateFavoriteSelection:self];
+
+ // Suppress the possibility to choose an other connection from the favorites
+ // if a connection should initialized by SPF file. Otherwise it could happen
+ // that the SPF file runs out of sync.
+ [[connectionController favoritesOutlineView] setEnabled:NO];
+ }
+ else {
+ [connectionController selectQuickConnectItem];
+ }
// Set the correct connection type
if ([connection objectForKey:@"type"]) {
@@ -4774,7 +4784,7 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
// Autoconnect if appropriate
if ([stateDetails objectForKey:@"auto_connect"] && [[stateDetails valueForKey:@"auto_connect"] boolValue]) {
- [connectionController initiateConnection:self];
+ [self connect];
}
if (keychain) [keychain release];