diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-09-03 13:00:46 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-09-03 13:00:46 +0000 |
commit | 61adeb9f4ad973a93ce35ac4ebf6068f2beac6ca (patch) | |
tree | 81c499d06c5be9773093657b070eda5529d58d6b /Source | |
parent | ca60d2e7bdec4763489e79ff4c457c32cd1f57db (diff) | |
download | sequelpro-61adeb9f4ad973a93ce35ac4ebf6068f2beac6ca.tar.gz sequelpro-61adeb9f4ad973a93ce35ac4ebf6068f2beac6ca.tar.bz2 sequelpro-61adeb9f4ad973a93ce35ac4ebf6068f2beac6ca.zip |
• further progress for CSV import into new table
- added some GUI validations
- in new table mode changed 'type' column into self-learning NSComboBoxCells
- fixed issue for closing sheet if user press RETURN, only close it if 'Import' button is enable
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPFieldMapperController.h | 6 | ||||
-rw-r--r-- | Source/SPFieldMapperController.m | 73 | ||||
-rw-r--r-- | Source/SPTableView.m | 14 |
3 files changed, 80 insertions, 13 deletions
diff --git a/Source/SPFieldMapperController.h b/Source/SPFieldMapperController.h index da5b6ca2..b824e3ed 100644 --- a/Source/SPFieldMapperController.h +++ b/Source/SPFieldMapperController.h @@ -76,6 +76,8 @@ IBOutlet id advancedReplaceView; IBOutlet id advancedUpdateView; + IBOutlet NSComboBoxCell *typeComboxBox; + id theDelegate; id customQueryInstance; id fieldMappingImportArray; @@ -91,6 +93,8 @@ NSMutableArray *fieldMappingGlobalValues; NSMutableArray *fieldMappingGlobalValuesSQLMarked; NSMutableArray *fieldMappingTableDefaultValues; + NSMutableArray *defaultFieldTypesForComboBox; + NSNumber *doImport; NSNumber *doNotImport; @@ -106,6 +110,7 @@ BOOL showAdvancedView; BOOL targetTableHasPrimaryKey; BOOL newTableMode; + BOOL addGlobalSheetIsOpen; NSString *primaryKeyField; NSNumber *lastDisabledCSVFieldcolumn; @@ -142,6 +147,7 @@ - (BOOL)importIntoNewTable; - (NSString*)onupdateString; - (NSString*)importHeaderString; +- (BOOL)canBeClosed; // IBAction methods - (IBAction)changeTableTarget:(id)sender; diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m index b9f41935..dbdf3d31 100644 --- a/Source/SPFieldMapperController.m +++ b/Source/SPFieldMapperController.m @@ -61,6 +61,7 @@ fieldMappingOperatorOptions = [[NSMutableArray alloc] init]; fieldMappingOperatorArray = [[NSMutableArray alloc] init]; fieldMappingGlobalValues = [[NSMutableArray alloc] init]; + defaultFieldTypesForComboBox = [[NSMutableArray alloc] init]; fieldMappingGlobalValuesSQLMarked = [[NSMutableArray alloc] init]; fieldMappingArray = nil; @@ -73,12 +74,11 @@ doNotImportString = @" "; isEqualString = @"="; newTableMode = NO; + addGlobalSheetIsOpen = NO; prefs = [NSUserDefaults standardUserDefaults]; tablesListInstance = [theDelegate valueForKeyPath:@"tablesListInstance"]; - [fieldMapperTableView setDelegate:self]; - [fieldMapperTableView setDataSource:self]; } @@ -88,6 +88,10 @@ - (void)awakeFromNib { + [fieldMapperTableView setDelegate:self]; + [fieldMapperTableView setDataSource:self]; + + // Set source path // Note: [fileSourcePath setURL:[NSURL fileWithPath:sourcePath]] does NOT work // if Sequel Pro runs localized. Reason unknown, it seems to be a NSPathControl bug. @@ -129,6 +133,20 @@ } + [defaultFieldTypesForComboBox setArray:[NSArray arrayWithObjects: + @"varchar(255)", + @"char(65)", + @"text", + @"longtext", + @"int(11)", + @"bigint", + @"date", + @"datetime", + @"time", + @"timestamp", + nil + ]]; + [importFieldNamesHeaderSwitch setState:importFieldNamesHeader]; [addRemainingDataSwitch setState:NO]; @@ -172,6 +190,7 @@ if (mySQLConnection) [mySQLConnection release]; if (sourcePath) [sourcePath release]; if (fieldMappingTableColumnNames) [fieldMappingTableColumnNames release]; + if (defaultFieldTypesForComboBox) [defaultFieldTypesForComboBox release]; if (fieldMappingTableTypes) [fieldMappingTableTypes release]; if (fieldMappingArray) [fieldMappingArray release]; if (fieldMappingButtonOptions) [fieldMappingButtonOptions release]; @@ -324,6 +343,11 @@ return @""; } +- (BOOL)canBeClosed +{ + return [importButton isEnabled]; +} + #pragma mark - #pragma mark IBAction methods @@ -409,6 +433,10 @@ newTableMode = YES; + [importMethodPopup selectItemWithTitle:@"INSERT"]; + [[importMethodPopup itemWithTitle:@"UPDATE"] setEnabled:NO]; + [[importMethodPopup itemWithTitle:@"REPLACE"] setEnabled:NO]; + [tableTargetPopup setHidden:YES]; [newTableNameTextField setHidden:NO]; [newTableNameLabel setHidden:NO]; @@ -703,10 +731,14 @@ - (IBAction)addGlobalSourceVariable:(id)sender { + + addGlobalSheetIsOpen = YES; + [NSApp beginSheet:globalValuesSheet modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:nil]; + [self addGlobalValue:nil]; } @@ -931,6 +963,7 @@ - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo { if ([sheet respondsToSelector:@selector(orderOut:)]) [sheet orderOut:nil]; + addGlobalSheetIsOpen = NO; if (sheet == globalValuesSheet) [self updateFieldMappingButtonCell]; } @@ -1206,11 +1239,8 @@ else if ([[aTableColumn identifier] isEqualToString:@"type"]) { if(newTableMode) { - NSTextFieldCell *b = [[[NSTextFieldCell alloc] initTextCell:[fieldMappingTableTypes objectAtIndex:rowIndex]] autorelease]; - [b setEditable:YES]; - [b setFont:[NSFont systemFontOfSize:12]]; - [aTableColumn setDataCell:b]; - return b; + [aTableColumn setDataCell:typeComboxBox]; + return [fieldMappingTableTypes objectAtIndex:rowIndex]; } else { NSTokenFieldCell *b = [[[NSTokenFieldCell alloc] initTextCell:[fieldMappingTableTypes objectAtIndex:rowIndex]] autorelease]; [b setEditable:NO]; @@ -1218,7 +1248,8 @@ [b setWraps:NO]; [b setFont:[NSFont systemFontOfSize:9]]; [b setDelegate:self]; - return b; + [aTableColumn setDataCell:b]; + return [fieldMappingTableTypes objectAtIndex:rowIndex]; } } @@ -1280,6 +1311,7 @@ - (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { + if(aTableView == globalValuesTableView) return YES; if(!newTableMode) return NO; @@ -1354,6 +1386,8 @@ else if (newTableMode && [[aTableColumn identifier] isEqualToString:@"type"]) { if([(NSString*)anObject length]) { [fieldMappingTableTypes replaceObjectAtIndex:rowIndex withObject:anObject]; + if(![defaultFieldTypesForComboBox containsObject:anObject]) + [defaultFieldTypesForComboBox insertObject:anObject atIndex:0]; } } @@ -1397,13 +1431,15 @@ - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command { - if(!newTableMode) return NO; + if(!newTableMode || addGlobalSheetIsOpen) return NO; NSUInteger row, column; row = [fieldMapperTableView editedRow]; column = [fieldMapperTableView editedColumn]; + BOOL isCellComplex = ([[fieldMapperTableView preparedCellAtColumn:column row:row] isKindOfClass:[NSComboBoxCell class]]) ? YES : NO; + // Trap tab key // -- for handling of blob fields and to check if it's editable look at [[self delegate] control:textShouldBeginEditing:] if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)] ) @@ -1441,6 +1477,8 @@ else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertNewline:)] ) { + if(isCellComplex && newTableMode) return NO; + // If newTableNameTextField is active enter key closes the sheet if(control == newTableNameTextField) { NSButton *b = [[[NSButton alloc] init] autorelease]; @@ -1459,6 +1497,8 @@ else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(moveDown:)] ) { + if(isCellComplex) return NO; + NSUInteger newRow = row+1; if (newRow>=[self numberOfRowsInTableView:fieldMapperTableView]) return YES; //check if we're already at the end of the list @@ -1473,6 +1513,8 @@ else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(moveUp:)] ) { + if(isCellComplex) return NO; + if (row==0) return YES; //already at the beginning of the list NSUInteger newRow = row-1; @@ -1517,4 +1559,17 @@ } +#pragma mark - +#pragma mark NSComboBox delegates + +- (id)comboBoxCell:(NSComboBoxCell *)aComboBoxCell objectValueForItemAtIndex:(NSInteger)index +{ + return [defaultFieldTypesForComboBox objectAtIndex:index]; +} + +- (NSInteger)numberOfItemsInComboBoxCell:(NSComboBoxCell *)aComboBoxCell +{ + return [defaultFieldTypesForComboBox count]; +} + @end diff --git a/Source/SPTableView.m b/Source/SPTableView.m index c19678db..7e212884 100644 --- a/Source/SPTableView.m +++ b/Source/SPTableView.m @@ -94,10 +94,16 @@ // ENTER or RETURN closes the SPFieldMapperController sheet by sending an object with the tag 1 if([[[[self delegate] class] description] isEqualToString:@"SPFieldMapperController"]) { - NSButton *b = [[[NSButton alloc] init] autorelease]; - [b setTag:1]; - [[self delegate] closeSheet:b]; - return; + if([[self delegate] canBeClosed]) { + NSButton *b = [[[NSButton alloc] init] autorelease]; + [b setTag:1]; + [[self delegate] closeSheet:b]; + return; + } else { + [super keyDown:theEvent]; + return; + } + } if (![[[[self delegate] class] description] isEqualToString:@"SPCustomQuery"] && |