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 --- Interfaces/English.lproj/MainMenu.xib | 9 ++++--- Source/TableDocument.m | 44 +++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/Interfaces/English.lproj/MainMenu.xib b/Interfaces/English.lproj/MainMenu.xib index bc93e9cb..fec8e62a 100644 --- a/Interfaces/English.lproj/MainMenu.xib +++ b/Interfaces/English.lproj/MainMenu.xib @@ -280,7 +280,6 @@ - YES U2F2ZSBRdWVyeeKApg s 1048576 @@ -288,7 +287,7 @@ - + YES U2F2ZSBDb25uZWN0aW9u4oCmA @@ -2599,7 +2598,7 @@ saveConnectionSheet: - + 964 @@ -2828,7 +2827,7 @@ - + @@ -3868,7 +3867,7 @@ 963 - + 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