diff options
author | rowanbeentje <rowan@beent.je> | 2013-09-08 20:37:21 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2013-09-08 20:37:21 +0000 |
commit | 207386000afff61ec1b661a17fa9747bf7fb4407 (patch) | |
tree | 4bb62890e27e1c443efa82cad1a3225265f68c19 /Source/SPDatabaseDocument.m | |
parent | f800cc92469c2615fe5fb6cc351a24b1cfd6e944 (diff) | |
download | sequelpro-207386000afff61ec1b661a17fa9747bf7fb4407.tar.gz sequelpro-207386000afff61ec1b661a17fa9747bf7fb4407.tar.bz2 sequelpro-207386000afff61ec1b661a17fa9747bf7fb4407.zip |
Allow opened SQL files to be saved back to the original file, addressing Issue #1805:
- Add new menu item for "Save Query", making the existing item "Save Query As" as an alternate
- Track the opened SQL file and used encoding to be able to easily save the same file again
- Standardise encoding detection to use the UniversalDetector framework and use that for opened SQL files where the encoding menu is not used
Diffstat (limited to 'Source/SPDatabaseDocument.m')
-rw-r--r-- | Source/SPDatabaseDocument.m | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 3a887662..85246443 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -138,6 +138,8 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase"; @implementation SPDatabaseDocument #ifndef SP_CODA /* ivars */ +@synthesize sqlFileURL; +@synthesize sqlFileEncoding; @synthesize parentWindowController; @synthesize parentTabViewItem; #endif @@ -215,6 +217,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase"; queryEditorInitString = nil; #ifndef SP_CODA + sqlFileURL = nil; spfFileURL = nil; spfSession = nil; spfPreferences = [[NSMutableDictionary alloc] init]; @@ -2791,7 +2794,15 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase"; [panel setCanSelectHiddenExtension:YES]; // Save Query… - if( sender != nil && [sender tag] == 1006 ) { + if( sender != nil && ([sender tag] == 1006 || [sender tag] == 1008)) { + + // If Save was invoked, check whether the file was previously opened, and if so save without the panel + if ([sender tag] == 1006 && [[[self sqlFileURL] path] length]) { + NSError *error = nil; + NSString *content = [NSString stringWithString:[[[customQueryInstance valueForKeyPath:@"textView"] textStorage] string]]; + [content writeToURL:sqlFileURL atomically:YES encoding:sqlFileEncoding error:&error]; + return; + } // Save the editor's content as SQL file [panel setAccessoryView:[SPEncodingPopupAccessory encodingAccessory:[prefs integerForKey:SPLastSQLFileEncoding] @@ -6273,6 +6284,7 @@ static NSString *SPAlterDatabaseAction = @"SPAlterDatabase"; #endif if (queryEditorInitString) [queryEditorInitString release]; #ifndef SP_CODA + if (sqlFileURL) [sqlFileURL release]; if (spfFileURL) [spfFileURL release]; if (spfPreferences) [spfPreferences release]; if (spfSession) [spfSession release]; |