From e9f34249920eea69ca0dc116d21c1403c49ec0f4 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 21 Jun 2010 11:38:43 +0000 Subject: =?UTF-8?q?=E2=80=A2=20initial=20preparations=20to=20support=20the?= =?UTF-8?q?=20storage=20of=20the=20entire=20SP=20session=20(all=20windows?= =?UTF-8?q?=20including=20tabs)=20=E2=80=A2=20added=20file=20extension=20'?= =?UTF-8?q?spfs'=20as=20SP=20bundle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- Interfaces/English.lproj/MainMenu.xib | 120 ++++++++++++++++++++++++++++++---- Resources/Info.plist | 20 ++++++ Source/SPAppController.h | 9 ++- Source/SPAppController.m | 23 ++++++- Source/SPDatabaseDocument.m | 76 +++++++++++++++++++-- 5 files changed, 229 insertions(+), 19 deletions(-) diff --git a/Interfaces/English.lproj/MainMenu.xib b/Interfaces/English.lproj/MainMenu.xib index 27b5bfc8..e3bc58af 100644 --- a/Interfaces/English.lproj/MainMenu.xib +++ b/Interfaces/English.lproj/MainMenu.xib @@ -12,6 +12,7 @@ YES + YES @@ -362,6 +363,26 @@ 1005 + + + YES + Save Session + + 2147483647 + + + 1020 + + + + YES + Save Session As… + + 2147483647 + + + 1021 + Save Query… @@ -2705,14 +2726,6 @@ 964 - - - saveConnectionSheet: - - - - 966 - clearRecentDocuments: @@ -2961,6 +2974,30 @@ 1115 + + + saveConnectionSheet: + + + + 1120 + + + + saveConnectionSheet: + + + + 1121 + + + + saveConnectionSheet: + + + + 1122 + @@ -3188,6 +3225,8 @@ + + @@ -4314,6 +4353,16 @@ + + 1116 + + + + + 1118 + + + @@ -4371,6 +4420,8 @@ 111.ImportedFromIB2 1111.IBPluginDependency 1112.IBPluginDependency + 1116.IBPluginDependency + 1118.IBPluginDependency 129.IBPluginDependency 129.ImportedFromIB2 130.IBPluginDependency @@ -4713,6 +4764,8 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -4789,7 +4842,7 @@ com.apple.InterfaceBuilder.CocoaPlugin {{449, 1007}, {197, 53}} - {{106, 685}, {511, 20}} + {{228, 546}, {511, 20}} com.apple.InterfaceBuilder.CocoaPlugin {{506, 836}, {511, 20}} @@ -4925,7 +4978,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{214, 180}, {287, 383}} + {{334, 123}, {287, 423}} com.apple.InterfaceBuilder.CocoaPlugin {{180, 535}, {182, 253}} @@ -5066,7 +5119,7 @@ - 1115 + 1122 @@ -6513,6 +6566,51 @@ ../../Frameworks/Sparkle.framework/Versions/A/Headers/SUUpdater.h + + SPAppController + NSObject + + YES + + YES + donate: + newTab: + newWindow: + openAboutPanel: + openConnectionSheet: + openPreferences: + provideFeedback: + provideTranslationFeedback: + viewKeyboardShortcuts: + visitFAQWebsite: + visitHelpWebsite: + visitWebsite: + + + YES + id + id + id + id + id + id + id + id + id + id + id + id + + + + encodingPopUp + id + + + IBDocumentRelativeSource + ../../Source/SPAppController.h + + SPWindowController NSWindowController diff --git a/Resources/Info.plist b/Resources/Info.plist index 8e9d56cc..474ac750 100644 --- a/Resources/Info.plist +++ b/Resources/Info.plist @@ -24,6 +24,26 @@ NSDocumentClass SPDocumentController + + CFBundleTypeExtensions + + spfs + + CFBundleTypeIconFile + spficon.icns + CFBundleTypeName + Sequel Pro Connection Bundle + CFBundleTypeOSTypes + + connection + + CFBundleTypeRole + Editor + NSDocumentClass + SPDocumentController + LSTypeIsPackage + 1 + CFBundleTypeExtensions diff --git a/Source/SPAppController.h b/Source/SPAppController.h index 0ae75b90..9d9a5564 100644 --- a/Source/SPAppController.h +++ b/Source/SPAppController.h @@ -36,6 +36,8 @@ SPPreferenceController *prefsController; id encodingPopUp; + + NSURL *_sessionURL; } // Window management @@ -62,8 +64,11 @@ // Getters - (SPPreferenceController *)preferenceController; -- (NSArray *) orderedDatabaseConnectionWindows; -- (SPDatabaseDocument *) frontDocument; +- (NSArray *)orderedDatabaseConnectionWindows; +- (SPDatabaseDocument *)frontDocument; +- (NSURL *)sessionURL; + +- (void)setSessionURL:(NSString *)urlString; // Feedback controller delegate methods - (NSMutableDictionary*) anonymizePreferencesForFeedbackReport:(NSMutableDictionary *)preferences; diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 7a3ec334..45deeff9 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -43,6 +43,7 @@ - (id)init { if ((self = [super init])) { + _sessionURL = nil; [NSApp setDelegate:self]; } @@ -294,6 +295,9 @@ } [[self frontDocument] initWithConnectionFile:filename]; + } + else if([[[filename pathExtension] lowercaseString] isEqualToString:@"spfs"]) { + } else { NSLog(@"Only files with the extensions ‘spf’ or ‘sql’ are allowed."); @@ -435,6 +439,23 @@ return nil; } +/** + * Retrieve the session URL. Return nil if no session is opened + */ +- (NSURL *)sessionURL +{ + return _sessionURL; +} + +/** + * Set the global session URL used for Save (As) Session. + */ +- (void)setSessionURL:(NSString *)urlString +{ + if(_sessionURL) [_sessionURL release], _sessionURL = nil; + _sessionURL = [[NSURL fileURLWithPath:urlString] retain]; +} + #pragma mark - #pragma mark Services menu methods @@ -768,7 +789,7 @@ { [prefsController release], prefsController = nil; [aboutController release], aboutController = nil; - + if(_sessionURL) [_sessionURL release], _sessionURL = nil; [super dealloc]; } 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]; -- cgit v1.2.3