diff options
author | Bibiko <bibiko@eva.mpg.de> | 2009-08-22 10:54:17 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2009-08-22 10:54:17 +0000 |
commit | a35bbeac66279cd42230e301332dee1c26ae4be2 (patch) | |
tree | 36f59f1f918484d6da7493350287d040467fbd2f /Source | |
parent | a946912ea562fe7eb02ec51b77420e63db3a38da (diff) | |
download | sequelpro-a35bbeac66279cd42230e301332dee1c26ae4be2.tar.gz sequelpro-a35bbeac66279cd42230e301332dee1c26ae4be2.tar.bz2 sequelpro-a35bbeac66279cd42230e301332dee1c26ae4be2.zip |
• further improvements for open/save SQL/SPF files
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPAppController.h | 1 | ||||
-rw-r--r-- | Source/SPAppController.m | 43 | ||||
-rw-r--r-- | Source/TableDocument.h | 1 | ||||
-rw-r--r-- | Source/TableDocument.m | 57 |
4 files changed, 77 insertions, 25 deletions
diff --git a/Source/SPAppController.h b/Source/SPAppController.h index af4a2df4..d328d353 100644 --- a/Source/SPAppController.h +++ b/Source/SPAppController.h @@ -36,6 +36,7 @@ // IBAction methods - (IBAction)openPreferences:(id)sender; +- (IBAction)openConnectionSheet:(id)sender; // Services menu methods - (void)doPerformQueryService:(NSPasteboard *)pboard userData:(NSString *)data error:(NSString **)error; diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 9b0bce1d..2dba0c68 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -47,6 +47,33 @@ return self; } +- (IBAction)openConnectionSheet:(id)sender +{ + NSOpenPanel *panel = [NSOpenPanel openPanel]; + [panel setCanSelectHiddenExtension:YES]; + [panel setDelegate:self]; + [panel setCanChooseDirectories:NO]; + [panel setAllowsMultipleSelection:YES]; + [panel setResolvesAliases:YES]; + // [panel setAccessoryView:encodingAccessoryView]; + + // Set up encoding list + // [encodingPopUp setEnabled:NO]; + + // If no lastSqlFileEncoding in prefs set it to UTF-8 + if(![[NSUserDefaults standardUserDefaults] integerForKey:@"lastSqlFileEncoding"]) { + [[NSUserDefaults standardUserDefaults] setInteger:4 forKey:@"lastSqlFileEncoding"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + } + + // [self setupPopUp:encodingPopUp selectedEncoding:[prefs integerForKey:@"lastSqlFileEncoding"] withDefaultEntry:NO]; + int returnCode = [panel runModalForDirectory:nil file:nil types:[NSArray arrayWithObjects:@"spf", @"sql", nil]]; + + if( returnCode ) + [self application:nil openFiles:[panel filenames]]; + +} + /** * Called if user drag and drops files on Sequel Pro's dock item or double-clicked * at files *.spf or *.sql @@ -61,8 +88,7 @@ // Check if at least one document exists if (![[[NSDocumentController sharedDocumentController] documents] count]) { - // TODO : maybe open a connection first - // return; + TableDocument *firstTableDocument; // Manually open a new document, setting SPAppController as sender to trigger autoconnection @@ -82,7 +108,18 @@ } else if([[[filename pathExtension] lowercaseString] isEqualToString:@"spf"]) { - NSLog(@"open connection %@", filename); + + TableDocument *newTableDocument; + + // Manually open a new document, setting SPAppController as sender to trigger autoconnection + if (newTableDocument = [[NSDocumentController sharedDocumentController] makeUntitledDocumentOfType:@"DocumentType" error:nil]) { + [newTableDocument setShouldAutomaticallyConnect:NO]; + [[NSDocumentController sharedDocumentController] addDocument:newTableDocument]; + [newTableDocument makeWindowControllers]; + [newTableDocument showWindows]; + [newTableDocument initWithConnectionFile:filename]; + } + } else { NSLog(@"Only files with the extensions ‘spf’ or ‘sql’ are allowed."); diff --git a/Source/TableDocument.h b/Source/TableDocument.h index 9b1a053f..22c836db 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -129,6 +129,7 @@ enum { - (IBAction)showUserManager:(id)sender; - (void)initQueryEditorWithString:(NSString *)query; +- (void)initWithConnectionFile:(NSString *)path; // Connection callback and methods - (void) setConnection:(MCPConnection *)theConnection; - (void)setShouldAutomaticallyConnect:(BOOL)shouldAutomaticallyConnect; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 86763614..70d4089f 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -161,6 +161,32 @@ } } +- (void)initWithConnectionFile:(NSString *)path +{ + + NSError *readError = nil; + NSString *convError = nil; + NSPropertyListFormat format; + NSData *pData = [[NSData dataWithContentsOfFile:path options:NSUncachedRead error:&readError] decompress]; + NSDictionary *spfData = [NSPropertyListSerialization propertyListFromData:pData + mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError]; + + if(!spfData || readError != nil || [convError length] | format != NSPropertyListBinaryFormat_v1_0) { + NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")] + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:NSLocalizedString(@"Connection data file couldn't be read.", @"error while reading connection data file")]; + + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert runModal]; + return; + } + + NSLog(@"s: %@", [spfData description]); + +} + #pragma mark - #pragma mark Connection callback and methods @@ -1713,29 +1739,16 @@ break; // open only the first SQL file } else if([[[filename pathExtension] lowercaseString] isEqualToString:@"spf"]) { - - - NSError *readError = nil; - NSString *convError = nil; - NSPropertyListFormat format; - NSData *pData = [[NSData dataWithContentsOfFile:filename options:NSUncachedRead error:&readError] decompress]; - NSDictionary *spfData = [NSPropertyListSerialization propertyListFromData:pData - mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError]; - - if(!spfData || readError != nil || [convError length] | format != NSPropertyListBinaryFormat_v1_0) { - NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")] - defaultButton:NSLocalizedString(@"OK", @"OK button") - alternateButton:nil - otherButton:nil - informativeTextWithFormat:NSLocalizedString(@"Connection data file couldn't be read.", @"error while reading connection data file")]; - - [alert setAlertStyle:NSCriticalAlertStyle]; - [alert runModal]; - return; + TableDocument *newTableDocument; + + // Manually open a new document, setting SPAppController as sender to trigger autoconnection + if (newTableDocument = [[NSDocumentController sharedDocumentController] makeUntitledDocumentOfType:@"DocumentType" error:nil]) { + [newTableDocument setShouldAutomaticallyConnect:NO]; + [[NSDocumentController sharedDocumentController] addDocument:newTableDocument]; + [newTableDocument makeWindowControllers]; + [newTableDocument showWindows]; + [newTableDocument initWithConnectionFile:filename]; } - - NSLog(@"s: %@", [spfData description]); - } else { NSLog(@"Only files with the extensions ‘spf’ or ‘sql’ are allowed."); |