aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableDocument.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-08-20 12:52:56 +0000
committerBibiko <bibiko@eva.mpg.de>2009-08-20 12:52:56 +0000
commit264035f847d3f5fef8d2f56a2e18f48c6df4d316 (patch)
tree6273f4d542658b3b7dfedfd77153f121e264a096 /Source/TableDocument.m
parentbe6b947b45c4e7e883c6369316feebfa01ef75c8 (diff)
downloadsequelpro-264035f847d3f5fef8d2f56a2e18f48c6df4d316.tar.gz
sequelpro-264035f847d3f5fef8d2f56a2e18f48c6df4d316.tar.bz2
sequelpro-264035f847d3f5fef8d2f56a2e18f48c6df4d316.zip
• activated "Save Query…" menu item (⌘S)
- saves the Custom Query editor content by using a selected encoding to a SQL file
Diffstat (limited to 'Source/TableDocument.m')
-rw-r--r--Source/TableDocument.m44
1 files changed, 37 insertions, 7 deletions
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;
+ }
}
}
/**