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/TableDocument.m | |
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/TableDocument.m')
-rw-r--r-- | Source/TableDocument.m | 57 |
1 files changed, 35 insertions, 22 deletions
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."); |