aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPFieldMapperController.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-09-03 13:00:46 +0000
committerBibiko <bibiko@eva.mpg.de>2010-09-03 13:00:46 +0000
commit61adeb9f4ad973a93ce35ac4ebf6068f2beac6ca (patch)
tree81c499d06c5be9773093657b070eda5529d58d6b /Source/SPFieldMapperController.m
parentca60d2e7bdec4763489e79ff4c457c32cd1f57db (diff)
downloadsequelpro-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/SPFieldMapperController.m')
-rw-r--r--Source/SPFieldMapperController.m73
1 files changed, 64 insertions, 9 deletions
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