diff options
-rw-r--r-- | Source/SPDataImport.h | 4 | ||||
-rw-r--r-- | Source/SPDataImport.m | 69 |
2 files changed, 33 insertions, 40 deletions
diff --git a/Source/SPDataImport.h b/Source/SPDataImport.h index 0d23b104..add9c5b4 100644 --- a/Source/SPDataImport.h +++ b/Source/SPDataImport.h @@ -133,15 +133,13 @@ typedef enum { // Import methods - (void)importFile; -- (void)importFileSheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo; - (void)importFromClipboard; -- (void)importFromClipboardSheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo; - (void)importSQLFile:(NSString *)filename; - (void)startSQLImportProcessWithFile:(NSString *)filename; - (void)importCSVFile:(NSString *)filename; - (IBAction)changeFormat:(id)sender; - (BOOL)buildFieldMappingArrayWithData:(NSArray *)importData isPreview:(BOOL)dataIsPreviewData ofSoureFile:(NSString*)filename; -- (void)fieldMapperDidEndSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo; + - (NSString *)mappedValueStringForRowArray:(NSArray *)csvRowArray; - (NSString *)mappedUpdateSetStatementStringForRowArray:(NSArray *)csvRowArray; diff --git a/Source/SPDataImport.m b/Source/SPDataImport.m index cb9c1bb8..e1e314db 100644 --- a/Source/SPDataImport.m +++ b/Source/SPDataImport.m @@ -280,56 +280,51 @@ [openPanel setAccessoryView:importView]; [openPanel setDelegate:self]; + if ([prefs valueForKey:@"importFormatPopupValue"]) { [importFormatPopup selectItemWithTitle:[prefs valueForKey:@"importFormatPopupValue"]]; [self changeFormat:self]; } - - // Show openPanel - [openPanel beginSheetForDirectory:[prefs objectForKey:@"openPath"] - file:[lastFilename lastPathComponent] - modalForWindow:[tableDocumentInstance parentWindow] - modalDelegate:self - didEndSelector:@selector(importFileSheetDidEnd:returnCode:contextInfo:) - contextInfo:nil]; -} -/** - * Callback for when the import sheet is closed - */ -- (void)importFileSheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo -{ + if (lastFilename && [lastFilename lastPathComponent]) { + [openPanel setNameFieldStringValue:[lastFilename lastPathComponent]]; + } - // Ensure text inputs are completed, preventing dead character entry - [sheet makeFirstResponder:nil]; + [openPanel setDirectoryURL:[NSURL URLWithString:[prefs objectForKey:@"openPath"]]]; - // Save values to preferences - [prefs setObject:[(NSOpenPanel*)sheet directory] forKey:@"openPath"]; - [prefs setObject:[[importFormatPopup selectedItem] title] forKey:@"importFormatPopupValue"]; - - // Close NSOpenPanel sheet - [sheet orderOut:self]; + [openPanel beginSheetModalForWindow:[tableDocumentInstance parentWindow] completionHandler:^(NSInteger returnCode) { + // Ensure text inputs are completed, preventing dead character entry + [openPanel makeFirstResponder:nil]; - // Check if the user canceled - if (returnCode != NSOKButton) - return; + // Save values to preferences + [prefs setObject:[[openPanel directoryURL] path] forKey:@"openPath"]; + [prefs setObject:[[importFormatPopup selectedItem] title] forKey:@"importFormatPopupValue"]; - // Reset progress cancelled from any previous runs - progressCancelled = NO; + // Close NSOpenPanel sheet + [openPanel orderOut:self]; - if(lastFilename) [lastFilename release]; lastFilename = nil; - lastFilename = [[NSString stringWithString:[[(NSOpenPanel*)sheet URL] path]] retain]; + // Check if the user canceled + if (returnCode != NSOKButton) return; - NSString *importFileName = [NSString stringWithString:lastFilename]; - if (lastFilename == nil || ![lastFilename length]) { - NSBeep(); - return; - } + // Reset progress cancelled from any previous runs + progressCancelled = NO; - if (importFileName == nil) return; + if (lastFilename) [lastFilename release]; lastFilename = nil; - // Begin the import process - [NSThread detachNewThreadWithName:@"SPDataImport background import task" target:self selector:@selector(_importBackgroundProcess:) object:importFileName]; + lastFilename = [[NSString stringWithString:[[openPanel URL] path]] retain]; + + NSString *importFileName = [NSString stringWithString:lastFilename]; + + if (lastFilename == nil || ![lastFilename length]) { + NSBeep(); + return; + } + + if (importFileName == nil) return; + + // Begin the import process + [NSThread detachNewThreadWithName:@"SPDataImport background import task" target:self selector:@selector(_importBackgroundProcess:) object:importFileName]; + }]; } /** |