diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-06-24 13:35:22 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-06-24 13:35:22 +0000 |
commit | ca64d295c058dcd3d5308cce56379401e6658434 (patch) | |
tree | 31f75babd1032ee0e5b7df5e6916b596c7ca1f46 | |
parent | cc24661e6566d5f35e092642fe1fd435b49ad385 (diff) | |
download | sequelpro-ca64d295c058dcd3d5308cce56379401e6658434.tar.gz sequelpro-ca64d295c058dcd3d5308cce56379401e6658434.tar.bz2 sequelpro-ca64d295c058dcd3d5308cce56379401e6658434.zip |
• initial support for open a spfs session file (works rudimentary - fine-tuning comes soon)
• added constant "SPBundleFileExtension"
-rw-r--r-- | Source/SPAppController.m | 98 | ||||
-rw-r--r-- | Source/SPConstants.h | 1 | ||||
-rw-r--r-- | Source/SPConstants.m | 1 | ||||
-rw-r--r-- | Source/SPDatabaseDocument.m | 2 | ||||
-rw-r--r-- | Source/SPWindowController.h | 1 | ||||
-rw-r--r-- | Source/SPWindowController.m | 13 |
6 files changed, 113 insertions, 3 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 405cdc01..7d44ee0c 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -298,8 +298,102 @@ [[self frontDocument] initWithConnectionFile:filename]; } - else if([[[filename pathExtension] lowercaseString] isEqualToString:@"spfs"]) { - + else if([[[filename pathExtension] lowercaseString] isEqualToString:SPBundleFileExtension]) { + + NSError *readError = nil; + NSString *convError = nil; + NSPropertyListFormat format; + NSDictionary *spfs = nil; + NSData *pData = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/info.plist", filename] options:NSUncachedRead error:&readError]; + + spfs = [[NSPropertyListSerialization propertyListFromData:pData + mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain]; + + if(!spfs || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || 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]; + if (spfs) [spfs release]; + return; + } + + + if([spfs objectForKey:@"windows"] && [[spfs objectForKey:@"windows"] isKindOfClass:[NSArray class]]) { + + NSFileManager *fileManager = [NSFileManager defaultManager]; + + for(NSDictionary *window in [[[spfs objectForKey:@"windows"] reverseObjectEnumerator] allObjects]) { + + static NSPoint cascadeLocation = {.x = 0, .y = 0}; + + // Create a new window controller, and set up a new connection view within it. + SPWindowController *newWindowController = [[SPWindowController alloc] initWithWindowNibName:@"MainWindow"]; + NSWindow *newWindow = [newWindowController window]; + + // Cascading defaults to on - retrieve the window origin automatically assigned by cascading, + // and convert to a top left point. + NSPoint topLeftPoint = [newWindow frame].origin; + topLeftPoint.y += [newWindow frame].size.height; + + // The first window should use autosaving; subsequent windows should cascade. + // So attempt to set the frame autosave name; this will succeed for the very + // first window, and fail for others. + BOOL usedAutosave = [newWindow setFrameAutosaveName:@"DBView"]; + if (!usedAutosave) { + [newWindow setFrameUsingName:@"DBView"]; + } + + // Cascade according to the statically stored cascade location. + cascadeLocation = [newWindow cascadeTopLeftFromPoint:cascadeLocation]; + + // Set the window controller as the window's delegate + [newWindow setDelegate:newWindowController]; + + usleep(1000); + + // Show the window + [newWindowController showWindow:self]; + + for(NSDictionary *tab in [window objectForKey:@"tabs"]) { + + NSString *fileName = nil; + BOOL isBundleFile = NO; + + if([[tab objectForKey:@"isAbsolutePath"] boolValue]) + fileName = [tab objectForKey:@"path"]; + else { + fileName = [NSString stringWithFormat:@"%@/Contents/%@", filename, [tab objectForKey:@"path"]]; + isBundleFile = YES; + } + + if([fileManager fileExistsAtPath:fileName]) { + + if(newWindowController) { + + if ([[newWindowController window] isMiniaturized]) [[newWindowController window] deminiaturize:self]; + [newWindowController addNewConnection:self]; + + [[self frontDocument] initWithConnectionFile:fileName]; + [[self frontDocument] setIsSavedInBundle:isBundleFile]; + } + + } else { + NSLog(@"Bundle file “%@” does not exists", fileName); + NSBeep(); + } + } + + [newWindowController selectTabAtIndex:[[window objectForKey:@"selectedTabIndex"] intValue]]; + [[NSApp delegate] setSessionURL:filename]; + + } + } + [spfs release]; } else { NSLog(@"Only files with the extensions ‘spf’ or ‘sql’ are allowed."); diff --git a/Source/SPConstants.h b/Source/SPConstants.h index 0eafec7a..e6932900 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -196,6 +196,7 @@ extern NSString *SPQueryFavortiesPasteboardDragType; // File extensions extern NSString *SPFileExtensionDefault; extern NSString *SPFileExtensionSQL; +extern NSString *SPBundleFileExtension; // Filenames extern NSString *SPHTMLPrintTemplate; diff --git a/Source/SPConstants.m b/Source/SPConstants.m index 93553d78..5580cbe7 100644 --- a/Source/SPConstants.m +++ b/Source/SPConstants.m @@ -44,6 +44,7 @@ NSString *SPContentFilterPasteboardDragType = @"SPContentFilterPasteboard"; // File extensions NSString *SPFileExtensionDefault = @"spf"; +NSString *SPBundleFileExtension = @"spfs"; NSString *SPFileExtensionSQL = @"sql"; // Filenames diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 85cc2bfb..53a18913 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -2827,7 +2827,7 @@ return; } - [panel setAllowedFileTypes:[NSArray arrayWithObjects:@"spfs", nil]]; + [panel setAllowedFileTypes:[NSArray arrayWithObjects:SPBundleFileExtension, nil]]; // Update accessory button states [self validateSaveConnectionAccessory:nil]; diff --git a/Source/SPWindowController.h b/Source/SPWindowController.h index 88b3e3a2..1f3945cc 100644 --- a/Source/SPWindowController.h +++ b/Source/SPWindowController.h @@ -47,5 +47,6 @@ - (IBAction)selectNextDocumentTab:(id)sender; - (IBAction)selectPreviousDocumentTab:(id)sender; - (NSArray *)documents; +- (void)selectTabAtIndex:(NSInteger)index; @end diff --git a/Source/SPWindowController.m b/Source/SPWindowController.m index 89879b0f..4c25ece2 100644 --- a/Source/SPWindowController.m +++ b/Source/SPWindowController.m @@ -291,6 +291,19 @@ return documentsArray; } +/** + * Select tab at index. + */ +- (void)selectTabAtIndex:(NSInteger)index +{ + if([[tabBar cells] count] > 0 && [[tabBar cells] count] > index) { + [tabView selectTabViewItemAtIndex:index]; + } else if([[tabBar cells] count]) { + [tabView selectTabViewItemAtIndex:0]; + } + +} + #pragma mark - #pragma mark Tab view delegate methods |