diff options
author | mltownsend <mltownsend@gmail.com> | 2009-01-04 20:18:00 +0000 |
---|---|---|
committer | mltownsend <mltownsend@gmail.com> | 2009-01-04 20:18:00 +0000 |
commit | 164cbbd373ab8bff9c592f4e0b41dd1bcc33bab1 (patch) | |
tree | 43b9256f2dd59f5ad7f114c67488dcb839b1049e /Source | |
parent | 59d5ba6ad98d2424752c3e78103262160281fe52 (diff) | |
download | sequelpro-164cbbd373ab8bff9c592f4e0b41dd1bcc33bab1.tar.gz sequelpro-164cbbd373ab8bff9c592f4e0b41dd1bcc33bab1.tar.bz2 sequelpro-164cbbd373ab8bff9c592f4e0b41dd1bcc33bab1.zip |
Added cancel button to the import/export progress sheet. Also added importing on a separate thread.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/TableDump.h | 15 | ||||
-rw-r--r-- | Source/TableDump.m | 67 |
2 files changed, 47 insertions, 35 deletions
diff --git a/Source/TableDump.h b/Source/TableDump.h index 22b123af..c8648eb4 100644 --- a/Source/TableDump.h +++ b/Source/TableDump.h @@ -94,6 +94,7 @@ NSString *savePath; NSString *openPath; NSUserDefaults *prefs; + BOOL progressCancelled; } //IBAction methods @@ -101,15 +102,13 @@ - (IBAction)selectTables:(id)sender; - (IBAction)closeSheet:(id)sender; - (IBAction)stepRow:(id)sender; -//- (IBAction)chooseDumpType:(id)sender; - +- (IBAction)cancelProgressBar:(id)sender; //export methods //- (IBAction)saveDump:(id)sender; - (void)exportFile:(int)tag; - (void)savePanelDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo; //import methods -//- (IBAction)openDump:(id)sender; - (void)importFile; - (IBAction)changeFormat:(id)sender; - (IBAction)changeTable:(id)sender; @@ -139,16 +138,6 @@ //additional methods - (void)setConnection:(CMMCPConnection *)theConnection; -//tableView datasource methods -- (int)numberOfRowsInTableView:(NSTableView *)aTableView; -- (id)tableView:(NSTableView *)aTableView - objectValueForTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex; -- (void)tableView:(NSTableView *)aTableView - setObjectValue:(id)anObject - forTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex; - //last but not least - (id)init; - (void)dealloc; diff --git a/Source/TableDump.m b/Source/TableDump.m index 442ec84a..dd2b91c0 100644 --- a/Source/TableDump.m +++ b/Source/TableDump.m @@ -294,7 +294,10 @@ NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, NSLocalizedString(@"Couldn't write to file. Be sure that you have the necessary privileges.", @"message of panel when file cannot be written")); } - + if (progressCancelled) + { + progressCancelled = NO; + } // Export finished Growl notification [[SPGrowlController sharedGrowlController] notifyWithTitle:@"Export Finished" description:[NSString stringWithFormat:NSLocalizedString(@"Finished exporting to %@",@"description for finished exporting growl notification"), [[sheet filename] lastPathComponent]] @@ -342,29 +345,18 @@ [fieldMappingTableView reloadData]; } -- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo -/* - reads mysql-dumpfile - */ +- (void)importBackgroundProcess:(NSString*)filename { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *dumpFile; NSError **errorStr; NSMutableString *errors = [NSMutableString string]; NSString *fileType = [[importFormatPopup selectedItem] title]; - - [sheet orderOut:self]; - - if ( returnCode != NSOKButton ) - return; - - //save path to preferences - [prefs setObject:[sheet directory] forKey:@"openPath"]; - //load file into string - dumpFile = [NSString stringWithContentsOfFile:[sheet filename] + dumpFile = [NSString stringWithContentsOfFile:filename encoding:[CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance encoding] cString]] error:errorStr]; - + if ( !dumpFile ) { NSBeginAlertSheet(NSLocalizedString(@"Error", @"Title of error alert"), NSLocalizedString(@"OK", @"OK button"), @@ -442,6 +434,7 @@ //////////////// } else if ( [fileType isEqualToString:@"CSV"] ) { + //NSLog(@"CSV Import..."); //import csv file int code; NSPopUpButtonCell *buttonCell = [[NSPopUpButtonCell alloc] init]; @@ -474,7 +467,12 @@ [singleProgressBar setUsesThreadedAnimation:NO]; [singleProgressBar setIndeterminate:NO]; - + if (progressCancelled) { + progressCancelled = NO; + //NSLog(@"Progress Cancelled... cleaning up"); + [pool release]; + return; + } CMMCPResult *theResult; int i; theResult = (CMMCPResult *) [mySQLConnection listTables]; @@ -608,8 +606,25 @@ // Import finished Growl notification [[SPGrowlController sharedGrowlController] notifyWithTitle:@"Import Finished" - description:[NSString stringWithFormat:NSLocalizedString(@"Finished importing %@",@"description for finished importing growl notification"), [[sheet filename] lastPathComponent]] + description:[NSString stringWithFormat:NSLocalizedString(@"Finished importing %@",@"description for finished importing growl notification"), [filename lastPathComponent]] notificationName:@"Import Finished"]; + [pool release]; +} +- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo +/* + reads mysql-dumpfile + */ +{ + [sheet orderOut:self]; + + if ( returnCode != NSOKButton ) + return; + + //save path to preferences + [prefs setObject:[sheet directory] forKey:@"openPath"]; + + [NSThread detachNewThreadSelector:@selector(importBackgroundProcess:) toTarget:self withObject:[sheet filename]]; + } - (void)setupFieldMappingArray @@ -1120,12 +1135,16 @@ return TRUE; } + - (NSArray *)arrayForCSV:(NSString *)csv terminatedBy:(NSString *)terminated enclosedBy:(NSString *)enclosed escapedBy:(NSString *)escaped lineEnds:(NSString *)lineEnds /* loads a csv string into an array */ { + + //NSLog(@"In arrayForCSV..."); + NSMutableString *tempTerminated, *tempLineEnds; NSMutableArray *tempArray = [NSMutableArray array]; NSMutableArray *tempRowArray = [NSMutableArray array]; @@ -1166,7 +1185,7 @@ scanner = [NSScanner scannerWithString:csv]; [scanner setCharactersToBeSkipped:nil]; - while ( ![scanner isAtEnd] ) { + while ( ![scanner isAtEnd] && !progressCancelled) { [tempString setString:@""]; br = NO; @@ -1197,12 +1216,11 @@ // Skip blank lines if (![tempString length]) continue; - // Add the line to the array [linesArray addObject:[NSString stringWithString:tempString]]; } - for ( x = 0 ; x < [linesArray count] ; x++ ) { + for ( x = 0 ; x < [linesArray count] && !progressCancelled; x++ ) { //separate fields [tempRowArray removeAllObjects]; @@ -1258,6 +1276,7 @@ } //add row to tempArray [tempArray addObject:[NSArray arrayWithArray:tempRowArray]]; + //NSLog(@"tempArray count: %d", [tempArray count]); } return [NSArray arrayWithArray:tempArray]; @@ -1477,7 +1496,7 @@ [fileHandle writeData:[infoString dataUsingEncoding:connectionEncoding]]; // Loop through the selected tables - for ( i = 0 ; i < [selectedTables count] ; i++ ) { + for ( i = 0 ; i < [selectedTables count] && !progressCancelled; i++ ) { // Update the progress text and reset the progress bar to indeterminate status tableName = [selectedTables objectAtIndex:i]; @@ -1891,5 +1910,9 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn [super dealloc]; } +- (IBAction)cancelProgressBar:(id)sender +{ + progressCancelled = YES; +} @end |