From 264035f847d3f5fef8d2f56a2e18f48c6df4d316 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 20 Aug 2009 12:52:56 +0000 Subject: =?UTF-8?q?=E2=80=A2=20activated=20"Save=20Query=E2=80=A6"=20menu?= =?UTF-8?q?=20item=20(=E2=8C=98S)=20-=20saves=20the=20Custom=20Query=20edi?= =?UTF-8?q?tor=20content=20by=20using=20a=20selected=20encoding=20to=20a?= =?UTF-8?q?=20SQL=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/TableDocument.m | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'Source/TableDocument.m') diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 341e149a..ea1b418a 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -1730,17 +1730,24 @@ NSSavePanel *panel = [NSSavePanel savePanel]; NSString *filename; + NSString *contextInfo; [panel setAllowsOtherFileTypes:NO]; [panel setCanSelectHiddenExtension:YES]; if( [sender tag] == 0 ) { - // Custom Query tab is active thus save the editor's content as SQL file + // Save the editor's content as SQL file [panel setAccessoryView:encodingAccessoryView]; - [panel setMessage:NSLocalizedString(@"Save SQL file", @"Save SQL file")]; + // [panel setMessage:NSLocalizedString(@"Save SQL file", @"Save SQL file")]; [panel setAllowedFileTypes:[NSArray arrayWithObjects:@"sql", nil]]; - filename = [NSString stringWithString:@""]; + if(![prefs stringForKey:@"lastSqlFileName"]) { + [prefs setObject:@"" forKey:@"lastSqlFileName"]; + [prefs synchronize]; + } + + filename = [prefs stringForKey:@"lastSqlFileName"]; + contextInfo = @"saveSQLfile"; // If no lastSqlFileEncoding in prefs set it to UTF-8 if(![prefs integerForKey:@"lastSqlFileEncoding"]) { @@ -1758,6 +1765,7 @@ // [panel setMessage:NSLocalizedString(@"Save Sequel Pro session", @"Save Sequel Pro session")]; [panel setAllowedFileTypes:[NSArray arrayWithObjects:@"spf", nil]]; filename = [NSString stringWithFormat:@"%@", [self name]]; + contextInfo = @"saveSPFfile"; } else { return; @@ -1768,17 +1776,39 @@ modalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(saveConnectionPanelDidEnd:returnCode:contextInfo:) - contextInfo:NULL]; + contextInfo:contextInfo]; } - (void)saveConnectionPanelDidEnd:(NSSavePanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo { if ( returnCode ) { + NSString *fileName = [panel filename]; - NSLog(@"save as: '%@'", fileName); - - [prefs setInteger:[[encodingPopUp selectedItem] tag] forKey:@"lastSqlFileEncoding"]; + NSError *error = nil; + // Save file as SQL file by using the chosen encoding + if(contextInfo == @"saveSQLfile") { + + [prefs setInteger:[[encodingPopUp selectedItem] tag] forKey:@"lastSqlFileEncoding"]; + [prefs setObject:[fileName lastPathComponent] forKey:@"lastSqlFileName"]; + [prefs synchronize]; + + NSString *content = [NSString stringWithString:[[[customQueryInstance valueForKeyPath:@"textView"] textStorage] string]]; + [content writeToFile:fileName + atomically:YES + encoding:[[encodingPopUp selectedItem] tag] + error:&error]; + + if(error != nil) { + NSAlert *errorAlert = [NSAlert alertWithError:error]; + [errorAlert runModal]; + } + return; + } + else if(contextInfo == @"saveSPFfile") { + NSLog(@"Save SPF file"); + return; + } } } /** -- cgit v1.2.3