aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPAppController.m
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 /Source/SPAppController.m
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…'
Diffstat (limited to 'Source/SPAppController.m')
-rw-r--r--Source/SPAppController.m45
1 files changed, 44 insertions, 1 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)