aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-09-26 11:44:19 +0000
committerBibiko <bibiko@eva.mpg.de>2009-09-26 11:44:19 +0000
commit0dbc2fe46d3f496b2e6e7be784352767572b6df1 (patch)
tree1eb58bdb36c184574a59d3ec0449dd328b9ead5f
parentd14a032b6d2ea3c75f46b977e62afc958ae29db2 (diff)
downloadsequelpro-0dbc2fe46d3f496b2e6e7be784352767572b6df1.tar.gz
sequelpro-0dbc2fe46d3f496b2e6e7be784352767572b6df1.tar.bz2
sequelpro-0dbc2fe46d3f496b2e6e7be784352767572b6df1.zip
• if the user chose to open a SQL file which is larger than 1MB SP asks for confirmation, furthermore if a connection is available the user can choose 'Import' instead of loading it into the Query Editor for cases that an user invoked 'Open…' accidentally instead of 'Import…'
-rw-r--r--Source/SPAppController.m45
-rw-r--r--Source/TableDump.h5
-rw-r--r--Source/TableDump.m5
3 files changed, 52 insertions, 3 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index b9e32dd1..94a732b9 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -27,6 +27,7 @@
#import "SPAppController.h"
#import "TableDocument.h"
#import "SPPreferenceController.h"
+#import "TableDump.h"
#import "SPEncodingPopupAccessory.h"
#import <Sparkle/Sparkle.h>
@@ -161,8 +162,10 @@
}
- (void)openConnectionPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
- if ( returnCode )
+ if ( returnCode ) {
+ [panel orderOut:self];
[self application:nil openFiles:[panel filenames]];
+ }
encodingPopUp = nil;
}
@@ -179,6 +182,46 @@
// Opens a sql file and insert its content into the Custom Query editor
if([[[filename pathExtension] lowercaseString] isEqualToString:@"sql"]) {
+ // Check size and NSFileType
+ NSDictionary *attr = [[NSFileManager defaultManager] fileAttributesAtPath:filename traverseLink:YES];
+ if(attr)
+ {
+ NSNumber *filesize = [attr objectForKey:NSFileSize];
+ NSString *filetype = [attr objectForKey:NSFileType];
+ if(filetype == NSFileTypeRegular && filesize)
+ {
+ // Ask for confirmation if file content is larger than 1MB
+ if([filesize unsignedLongValue] > 1000000)
+ {
+ NSAlert *alert = [[NSAlert alloc] init];
+ [alert addButtonWithTitle:NSLocalizedString(@"OK", @"OK button")];
+ [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"cancel button")];
+
+ // Show 'Import' button only if there's a connection available
+ if ([[[NSDocumentController sharedDocumentController] documents] count])
+ [alert addButtonWithTitle:NSLocalizedString(@"Import", @"import button")];
+
+
+ [alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Do you really want to load a SQL file with %.1f MB of data into the Query Editor?", @"message of panel asking for confirmation for loading large text into the query editor"),
+ [filesize unsignedLongValue]/1048576.0]];
+ [alert setHelpAnchor:filename];
+ [alert setMessageText:NSLocalizedString(@"Warning",@"warning")];
+ [alert setAlertStyle:NSWarningAlertStyle];
+
+ NSUInteger returnCode = [alert runModal];
+
+ [alert release];
+
+ if(returnCode == NSAlertSecondButtonReturn) return; // Cancel
+ else if(returnCode == NSAlertThirdButtonReturn) { // Import
+ // begin import process
+ [[[[NSDocumentController sharedDocumentController] currentDocument] valueForKeyPath:@"tableDumpInstance"] startSQLImportProcessWithFile:filename];
+ return;
+ }
+ }
+ }
+ }
+
// if encodingPopUp is defined the filename comes from an openPanel and
// the encodingPopUp contains the chosen encoding; otherwise autodetect encoding
if(encodingPopUp)
diff --git a/Source/TableDump.h b/Source/TableDump.h
index de659fa2..dd9ffd6c 100644
--- a/Source/TableDump.h
+++ b/Source/TableDump.h
@@ -119,8 +119,9 @@
// Import methods
- (void)importFile;
-- (void) importSQLFile:(NSString *)filename;
-- (void) importCSVFile:(NSString *)filename;
+- (void)importSQLFile:(NSString *)filename;
+- (void)startSQLImportProcessWithFile:(NSString *)filename;
+- (void)importCSVFile:(NSString *)filename;
- (IBAction)changeFormat:(id)sender;
- (IBAction)changeTable:(id)sender;
- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo;
diff --git a/Source/TableDump.m b/Source/TableDump.m
index 994b45bc..6a55610d 100644
--- a/Source/TableDump.m
+++ b/Source/TableDump.m
@@ -948,6 +948,11 @@
[NSThread detachNewThreadSelector:@selector(importBackgroundProcess:) toTarget:self withObject:[sheet filename]];
}
+- (void)startSQLImportProcessWithFile:(NSString *)filename
+{
+ [importFormatPopup selectItemWithTitle:@"SQL"];
+ [NSThread detachNewThreadSelector:@selector(importBackgroundProcess:) toTarget:self withObject:filename];
+}
/*
* Sets up the fieldMapping array to be shown in the tableView
*/