From ec60a32215bb07f5ccd9b8061a88112985acaf8b Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 14 Oct 2015 16:06:51 +0200 Subject: Add mysql:// URL handler (fixes #1681) --- Source/SPAppController.m | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'Source/SPAppController.m') 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]; -- cgit v1.2.3