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/SPDataImport.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/SPDataImport.m')
-rw-r--r-- | Source/SPDataImport.m | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/Source/SPDataImport.m b/Source/SPDataImport.m index 34c535c0..cb9c1bb8 100644 --- a/Source/SPDataImport.m +++ b/Source/SPDataImport.m @@ -51,7 +51,6 @@ #import "SPThreadAdditions.h" #import <SPMySQL/SPMySQL.h> -#import <UniversalDetector/UniversalDetector.h> #define SP_FILE_READ_ERROR_STRING NSLocalizedString(@"File read error", @"File read error title (Import Dialog)") @@ -420,18 +419,12 @@ [tableDocumentInstance setQueryMode:SPImportExportQueryMode]; // Determine the file encoding. The first item in the encoding menu is "Autodetect"; if - // this is selected, attempt to detect the encoding of the file (using first 2.5MB). + // this is selected, attempt to detect the encoding of the file if (![importEncodingPopup indexOfSelectedItem]) { - SPFileHandle *detectorFileHandle = [SPFileHandle fileHandleForReadingAtPath:filename]; - if (detectorFileHandle) { - UniversalDetector *fileEncodingDetector = [[UniversalDetector alloc] init]; - [fileEncodingDetector analyzeData:[detectorFileHandle readDataOfLength:2500000]]; - sqlEncoding = [fileEncodingDetector encoding]; - [fileEncodingDetector release]; - if ([SPMySQLConnection mySQLCharsetForStringEncoding:sqlEncoding]) { - connectionEncodingToRestore = [mySQLConnection encoding]; - [mySQLConnection queryString:[NSString stringWithFormat:@"SET NAMES '%@'", [SPMySQLConnection mySQLCharsetForStringEncoding:sqlEncoding]]]; - } + sqlEncoding = [[NSFileManager defaultManager] detectEncodingforFileAtPath:filename]; + if ([SPMySQLConnection mySQLCharsetForStringEncoding:sqlEncoding]) { + connectionEncodingToRestore = [mySQLConnection encoding]; + [mySQLConnection queryString:[NSString stringWithFormat:@"SET NAMES '%@'", [SPMySQLConnection mySQLCharsetForStringEncoding:sqlEncoding]]]; } // Otherwise, get the encoding to use from the menu @@ -782,15 +775,9 @@ [tableDocumentInstance setQueryMode:SPImportExportQueryMode]; // Determine the file encoding. The first item in the encoding menu is "Autodetect"; if - // this is selected, attempt to detect the encoding of the file (using first 2.5MB). + // this is selected, attempt to detect the encoding of the file. if (![importEncodingPopup indexOfSelectedItem]) { - SPFileHandle *detectorFileHandle = [SPFileHandle fileHandleForReadingAtPath:filename]; - if (detectorFileHandle) { - UniversalDetector *fileEncodingDetector = [[UniversalDetector alloc] init]; - [fileEncodingDetector analyzeData:[detectorFileHandle readDataOfLength:2500000]]; - csvEncoding = [fileEncodingDetector encoding]; - [fileEncodingDetector release]; - } + csvEncoding = [[NSFileManager defaultManager] detectEncodingforFileAtPath:filename]; // Otherwise, get the encoding to use from the menu } else { |