diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-06-21 11:38:43 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-06-21 11:38:43 +0000 |
commit | e9f34249920eea69ca0dc116d21c1403c49ec0f4 (patch) | |
tree | 12e1198bd8f1f0fe65fc78a1d707f5f7385a9bef /Source/SPDatabaseDocument.m | |
parent | 43410663ca0338c8203c30156bd5391bb1f8fb37 (diff) | |
download | sequelpro-e9f34249920eea69ca0dc116d21c1403c49ec0f4.tar.gz sequelpro-e9f34249920eea69ca0dc116d21c1403c49ec0f4.tar.bz2 sequelpro-e9f34249920eea69ca0dc116d21c1403c49ec0f4.zip |
• initial preparations to support the storage of the entire SP session (all windows including tabs)
• added file extension 'spfs' as SP bundle
Note: The idea is to save inside the given spfs bundle a file 'Info.list' which contains the entire structure (which window, which tabs, selected items, etc.; each single connection is saved as separate spf file - if untitled inside the bundle in the sub-folder 'Contents' or if not the absolute path to a already saved spf file). This should insure that the user can open a single spf file in SP or as part of a spfs bundle session without loosing having two different spf file for the same connection. - Comments are welcome
Diffstat (limited to 'Source/SPDatabaseDocument.m')
-rw-r--r-- | Source/SPDatabaseDocument.m | 76 |
1 files changed, 71 insertions, 5 deletions
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index d76479b3..b463be93 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -2706,7 +2706,6 @@ #pragma mark - #pragma mark Menu methods - /** * Saves SP session or if Custom Query tab is active the editor's content as SQL file * If sender == nil then the call came from [self writeSafelyToURL:ofType:forSaveOperation:error] @@ -2797,8 +2796,36 @@ contextInfo = @"saveSPFfileAndClose"; else contextInfo = @"saveSPFfile"; + } + // Save Session or Save Session As… + else if (sender == nil || [sender tag] == 1020 || [sender tag] == 1021) + { + // Load accessory nib each time. + // Note that the top-level objects aren't released automatically, but are released when the panel ends. + if(![NSBundle loadNibNamed:@"SaveSPFAccessory" owner:self]) { + NSLog(@"SaveSPFAccessory accessory dialog could not be loaded."); + return; + } - } else { + [panel setAllowedFileTypes:[NSArray arrayWithObjects:@"spfs", nil]]; + + // Update accessory button states + [self validateSaveConnectionAccessory:nil]; + + // TODO note: it seems that one has problems with a NSSecureTextField + // inside an accessory view - ask HansJB + [[saveConnectionEncryptString cell] setControlView:saveConnectionAccessory]; + [panel setAccessoryView:saveConnectionAccessory]; + + // Set file name + if([[NSApp delegate] sessionURL]) + filename = [[[NSApp delegate] sessionURL] description]; + else + filename = [NSString stringWithFormat:@"%@", @"session"]; + + contextInfo = @"saveSession"; + } + else { return; } @@ -2874,6 +2901,47 @@ if(contextInfo == @"saveSPFfileAndClose") [self closeAndDisconnect]; } + + // Save all open windows including all tabs as session + else if(contextInfo == @"saveSession") { + + // Sub-folder 'Contents' will contain all untitled connection as single window or tab. + // info.plist will contain the opened structure (windows and tabs for each window). Each connection + // is linked to a saved spf file either in 'Contents' for unTitled ones or already saved spf files. + + NSFileManager *fileManager = [NSFileManager defaultManager]; + + [fileManager createDirectoryAtPath:fileName withIntermediateDirectories:TRUE attributes:nil error:&error]; + + if(error != nil) { + NSAlert *errorAlert = [NSAlert alertWithError:error]; + [errorAlert runModal]; + return; + } + + [fileManager createDirectoryAtPath:[NSString stringWithFormat:@"%@/Contents", fileName] withIntermediateDirectories:TRUE attributes:nil error:&error]; + + if(error != nil) { + NSAlert *errorAlert = [NSAlert alertWithError:error]; + [errorAlert runModal]; + return; + } + + NSString *content = @"HALLO"; + [content writeToFile:[NSString stringWithFormat:@"%@/info.plist", fileName] + atomically:YES + encoding:NSUTF8StringEncoding + error:&error]; + + if(error != nil) { + NSAlert *errorAlert = [NSAlert alertWithError:error]; + [errorAlert runModal]; + return; + } + + [[NSApp delegate] setSessionURL:fileName]; + + } } } @@ -2886,7 +2954,7 @@ NSMutableDictionary *spfDocData_temp = [NSMutableDictionary dictionary]; if(fileName == nil) - fileName = [[self fileURL] path]; //[[[self fileURL] absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + fileName = [[self fileURL] path]; // Store save panel settings or take them from spfDocData if(!saveInBackground) { @@ -3004,7 +3072,6 @@ [spfdata setObject:[spfDocData_temp objectForKey:@"encrypted"] forKey:@"encrypted"]; - // if([[spfDocData_temp objectForKey:@"save_password"] boolValue]) [spfdata setObject:[spfDocData_temp objectForKey:@"auto_connect"] forKey:@"auto_connect"]; if([[self keyChainID] length]) @@ -3033,7 +3100,6 @@ } [connection setObject:aString forKey:@"type"]; - if([[spfDocData_temp objectForKey:@"save_password"] boolValue]) { NSString *pw = [self keychainPasswordForConnection:nil]; if(![pw length]) pw = [connectionController password]; |