diff options
-rw-r--r-- | Interfaces/English.lproj/MainMenu.xib | 9 | ||||
-rw-r--r-- | 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 @@ </object> <object class="NSMenuItem" id="256715652"> <reference key="NSMenu" ref="709725194"/> - <bool key="NSIsHidden">YES</bool> <string type="base64-UTF8" key="NSTitle">U2F2ZSBRdWVyeeKApg</string> <string key="NSKeyEquiv">s</string> <int key="NSKeyEquivModMask">1048576</int> @@ -288,7 +287,7 @@ <reference key="NSOnImage" ref="625762401"/> <reference key="NSMixedImage" ref="315854375"/> </object> - <object class="NSMenuItem" id="283468712"> + <object class="NSMenuItem" id="759865633"> <reference key="NSMenu" ref="709725194"/> <bool key="NSIsHidden">YES</bool> <string type="base64-UTF8" key="NSTitle">U2F2ZSBDb25uZWN0aW9u4oCmA</string> @@ -2599,7 +2598,7 @@ <object class="IBActionConnection" key="connection"> <string key="label">saveConnectionSheet:</string> <reference key="source" ref="63651044"/> - <reference key="destination" ref="283468712"/> + <reference key="destination" ref="759865633"/> </object> <int key="connectionID">964</int> </object> @@ -2828,7 +2827,7 @@ <reference ref="849728981"/> <reference ref="320151386"/> <reference ref="256715652"/> - <reference ref="283468712"/> + <reference ref="759865633"/> </object> <reference key="parent" ref="86447006"/> </object> @@ -3868,7 +3867,7 @@ </object> <object class="IBObjectRecord"> <int key="objectID">963</int> - <reference key="object" ref="283468712"/> + <reference key="object" ref="759865633"/> <reference key="parent" ref="709725194"/> </object> </object> 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; + } } } /** |