From e23211c9c7406bee071e02b52da06c9e8896f7d4 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 6 Sep 2010 10:32:11 +0000 Subject: =?UTF-8?q?=E2=80=A2=20CSV=20Import=20Mapper=20sheet:=20-=20added?= =?UTF-8?q?=20keyboard=20shortcut=20=E2=8C=98T=20to=20show=20available=20t?= =?UTF-8?q?ables=20list=20-=20added=20chance=20to=20add=20a=20new=20column?= =?UTF-8?q?s=20to=20an=20existing=20table=20(=E2=8C=98=E2=8C=A5A)=20-=20ad?= =?UTF-8?q?ded=20chance=20to=20remove=20currently=20new=20added=20columns?= =?UTF-8?q?=20(=E2=8C=98=E2=8C=AB)=20-=20context=20menu;=20to=20remove=20a?= =?UTF-8?q?ll=20new=20columns=20one=20can=20reselect=20the=20table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note: New columns will be added after pressing 'Import' and before the import process starts; if an error occurred the sheet keeps open to give the user the chance to correct errors whereby successfully created new columns won't be editable anymore. --- Interfaces/English.lproj/DataMigrationDialog.xib | 764 ++++++++++++++++++++++- Source/SPFieldMapperController.h | 3 + Source/SPFieldMapperController.m | 238 +++++-- 3 files changed, 948 insertions(+), 57 deletions(-) diff --git a/Interfaces/English.lproj/DataMigrationDialog.xib b/Interfaces/English.lproj/DataMigrationDialog.xib index 2d3b9172..c5f721c7 100644 --- a/Interfaces/English.lproj/DataMigrationDialog.xib +++ b/Interfaces/English.lproj/DataMigrationDialog.xib @@ -12,7 +12,8 @@ YES - + + YES @@ -51,7 +52,7 @@ {3.40282e+38, 3.40282e+38} {522, 348} - + 274 YES @@ -152,7 +153,7 @@ - 264 + 265 {{400, 51}, {226, 32}} YES @@ -170,6 +171,46 @@ 25 + + + 265 + {{552, 1}, {226, 32}} + + YES + + 67239424 + 134217728 + AddNewColumn_Dummy_Button + + + -2038284033 + 402653313 + + a + 200 + 25 + + + + + 265 + {{556, 1}, {226, 32}} + + YES + + 67239424 + 134217728 + RemoveNewColumn_Dummy_Button + + + -2038284033 + 268435585 + +  + 200 + 25 + + {{1, 1}, {522, 39}} @@ -661,9 +702,9 @@ 109199615 - 129 + 268435585 - + t 400 75 @@ -1051,6 +1092,29 @@ 2322 + + YES + + YES + Apple HTML pasteboard type + Apple PDF pasteboard type + Apple PICT pasteboard type + Apple PNG pasteboard type + Apple URL pasteboard type + CorePasteboardFlavorType 0x6D6F6F76 + NSColor pasteboard type + NSFilenamesPboardType + NSStringPboardType + NeXT Encapsulated PostScript v1.2 pasteboard type + NeXT RTFD pasteboard type + NeXT Rich Text Format v1.0 pasteboard type + NeXT TIFF v4.0 pasteboard type + NeXT font pasteboard type + NeXT ruler pasteboard type + WebURLsWithTitlesPboardType + public.url + + {400, 14} @@ -1469,6 +1533,7 @@ {522, 348} + {{0, 0}, {1280, 778}} {522, 370} @@ -1911,6 +1976,26 @@ Add Column to Target Table… + a + 1572864 + 2147483647 + + + + + + Remove New Column: + CA + 1048576 + 2147483647 + + + + + + YES + YES + Edit Field Type for Column: 2147483647 @@ -1931,7 +2016,7 @@ {269, 120} {269, 120} - + 256 YES @@ -2087,7 +2172,6 @@ {269, 120} - {{0, 0}, {1280, 778}} {269, 142} @@ -2809,6 +2893,46 @@ 487 + + + addNewColumn: + + + + 489 + + + + editColumn: + + + + 490 + + + + removeNewColumn: + + + + 492 + + + + addNewColumn: + + + + 496 + + + + removeNewColumn: + + + + 500 + @@ -2899,6 +3023,8 @@ YES + + Header Box (Box) @@ -3785,6 +3911,8 @@ + + Context Menu @@ -3854,7 +3982,7 @@ - New Table Info + New Table Info Sheet 458 @@ -3972,6 +4100,46 @@ + + 488 + + + + + 491 + + + + + 493 + + + YES + + + + Push Button (AddNewColumn_Dummy_Button) + + + 494 + + + + + 497 + + + YES + + + + Push Button (RemoveNewColumn_Dummy_Button) + + + 498 + + + @@ -4186,6 +4354,12 @@ 485.IBPluginDependency 485.ImportedFromIB2 486.IBPluginDependency + 488.IBPluginDependency + 491.IBPluginDependency + 493.IBPluginDependency + 494.IBPluginDependency + 497.IBPluginDependency + 498.IBPluginDependency 56.IBPluginDependency 57.IBPluginDependency 89.IBPluginDependency @@ -4204,9 +4378,9 @@ YES com.apple.InterfaceBuilder.CocoaPlugin - {{76, 229}, {522, 348}} + {{94, 522}, {522, 348}} com.apple.InterfaceBuilder.CocoaPlugin - {{76, 229}, {522, 348}} + {{94, 522}, {522, 348}} {{387, 725}, {432, 282}} @@ -4329,7 +4503,7 @@ ToolTip - Choose database table in which the data will be inserted + Choose database table in which the data will be inserted (⌘T) com.apple.InterfaceBuilder.CocoaPlugin @@ -4439,7 +4613,7 @@ SPTableView com.apple.InterfaceBuilder.CocoaPlugin - {{295, 465}, {284, 53}} + {{276, 527}, {303, 93}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -4515,6 +4689,12 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin {{169, 564}, {465, 20}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -4544,7 +4724,7 @@ - 487 + 500 @@ -7350,6 +7530,564 @@ + + YES + + SPFieldMapperController + NSWindowController + + YES + + YES + addGlobalSourceVariable: + addGlobalValue: + addNewColumn: + advancedCheckboxValidation: + changeFieldAlignment: + changeHasHeaderCheckbox: + changeImportMethod: + changeTableTarget: + closeGlobalValuesSheet: + closeInfoSheet: + closeSheet: + goBackToFileChooser: + insertNULLValue: + newTable: + newTableInfo: + openAdvancedSheet: + removeGlobalValue: + removeNewColumn: + setAllTypesTo: + stepRow: + + + YES + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + + + + YES + + YES + addGlobalSourceVariable: + addGlobalValue: + addNewColumn: + advancedCheckboxValidation: + changeFieldAlignment: + changeHasHeaderCheckbox: + changeImportMethod: + changeTableTarget: + closeGlobalValuesSheet: + closeInfoSheet: + closeSheet: + goBackToFileChooser: + insertNULLValue: + newTable: + newTableInfo: + openAdvancedSheet: + removeGlobalValue: + removeNewColumn: + setAllTypesTo: + stepRow: + + + YES + + addGlobalSourceVariable: + id + + + addGlobalValue: + id + + + addNewColumn: + id + + + advancedCheckboxValidation: + id + + + changeFieldAlignment: + id + + + changeHasHeaderCheckbox: + id + + + changeImportMethod: + id + + + changeTableTarget: + id + + + closeGlobalValuesSheet: + id + + + closeInfoSheet: + id + + + closeSheet: + id + + + goBackToFileChooser: + id + + + insertNULLValue: + id + + + newTable: + id + + + newTableInfo: + id + + + openAdvancedSheet: + id + + + removeGlobalValue: + id + + + removeNewColumn: + id + + + setAllTypesTo: + id + + + stepRow: + id + + + + + YES + + YES + addGlobalValueButton + addNewColumnMenuItem + addRemainingDataSwitch + advancedBox + advancedButton + advancedInsertView + advancedLabel + advancedReplaceView + advancedUpdateView + alignByPopup + alignByPopupLabel + customQueryInstance + databaseDataInstance + delayedCheckBox + delayedReplaceCheckBox + fieldMapperTableScrollView + fieldMapperTableView + fieldMappingImportArray + fileSourcePath + globalValuesSheet + globalValuesTableView + highPriorityCheckBox + ignoreCheckBox + ignoreUpdateCheckBox + importButton + importFieldNamesHeaderSwitch + importMethodLabel + importMethodPopup + insertNULLValueButton + lowPriorityCheckBox + lowPriorityReplaceCheckBox + lowPriorityUpdateCheckBox + matchingNameMenuItem + newTableButton + newTableInfoEncodingPopup + newTableInfoEnginePopup + newTableInfoWindow + newTableNameInfoButton + newTableNameLabel + newTableNameTextField + onupdateCheckBox + onupdateTextView + recordCountLabel + removeGlobalValueButton + replaceAfterSavingCheckBox + rowDownButton + rowUpButton + setAllTypesToMenuItem + skipexistingRowsCheckBox + tableTargetPopup + tablesListInstance + theDelegate + typeComboxBox + + + YES + NSButton + NSMenuItem + id + id + id + id + id + id + id + NSPopUpButton + id + id + id + id + id + id + SPTableView + id + NSPathControl + id + NSTableView + id + id + id + id + id + id + NSPopUpButton + NSButton + id + id + id + NSMenuItem + NSButton + id + id + id + NSButton + NSTextField + NSTextField + id + SPTextView + id + NSButton + id + id + id + NSMenuItem + id + NSPopUpButton + id + id + NSComboBoxCell + + + + YES + + YES + addGlobalValueButton + addNewColumnMenuItem + addRemainingDataSwitch + advancedBox + advancedButton + advancedInsertView + advancedLabel + advancedReplaceView + advancedUpdateView + alignByPopup + alignByPopupLabel + customQueryInstance + databaseDataInstance + delayedCheckBox + delayedReplaceCheckBox + fieldMapperTableScrollView + fieldMapperTableView + fieldMappingImportArray + fileSourcePath + globalValuesSheet + globalValuesTableView + highPriorityCheckBox + ignoreCheckBox + ignoreUpdateCheckBox + importButton + importFieldNamesHeaderSwitch + importMethodLabel + importMethodPopup + insertNULLValueButton + lowPriorityCheckBox + lowPriorityReplaceCheckBox + lowPriorityUpdateCheckBox + matchingNameMenuItem + newTableButton + newTableInfoEncodingPopup + newTableInfoEnginePopup + newTableInfoWindow + newTableNameInfoButton + newTableNameLabel + newTableNameTextField + onupdateCheckBox + onupdateTextView + recordCountLabel + removeGlobalValueButton + replaceAfterSavingCheckBox + rowDownButton + rowUpButton + setAllTypesToMenuItem + skipexistingRowsCheckBox + tableTargetPopup + tablesListInstance + theDelegate + typeComboxBox + + + YES + + addGlobalValueButton + NSButton + + + addNewColumnMenuItem + NSMenuItem + + + addRemainingDataSwitch + id + + + advancedBox + id + + + advancedButton + id + + + advancedInsertView + id + + + advancedLabel + id + + + advancedReplaceView + id + + + advancedUpdateView + id + + + alignByPopup + NSPopUpButton + + + alignByPopupLabel + id + + + customQueryInstance + id + + + databaseDataInstance + id + + + delayedCheckBox + id + + + delayedReplaceCheckBox + id + + + fieldMapperTableScrollView + id + + + fieldMapperTableView + SPTableView + + + fieldMappingImportArray + id + + + fileSourcePath + NSPathControl + + + globalValuesSheet + id + + + globalValuesTableView + NSTableView + + + highPriorityCheckBox + id + + + ignoreCheckBox + id + + + ignoreUpdateCheckBox + id + + + importButton + id + + + importFieldNamesHeaderSwitch + id + + + importMethodLabel + id + + + importMethodPopup + NSPopUpButton + + + insertNULLValueButton + NSButton + + + lowPriorityCheckBox + id + + + lowPriorityReplaceCheckBox + id + + + lowPriorityUpdateCheckBox + id + + + matchingNameMenuItem + NSMenuItem + + + newTableButton + NSButton + + + newTableInfoEncodingPopup + id + + + newTableInfoEnginePopup + id + + + newTableInfoWindow + id + + + newTableNameInfoButton + NSButton + + + newTableNameLabel + NSTextField + + + newTableNameTextField + NSTextField + + + onupdateCheckBox + id + + + onupdateTextView + SPTextView + + + recordCountLabel + id + + + removeGlobalValueButton + NSButton + + + replaceAfterSavingCheckBox + id + + + rowDownButton + id + + + rowUpButton + id + + + setAllTypesToMenuItem + NSMenuItem + + + skipexistingRowsCheckBox + id + + + tableTargetPopup + NSPopUpButton + + + tablesListInstance + id + + + theDelegate + id + + + typeComboxBox + NSComboBoxCell + + + + + IBDocumentRelativeSource + ../../Source/SPFieldMapperController.h + + + YES diff --git a/Source/SPFieldMapperController.h b/Source/SPFieldMapperController.h index 484ce53d..15295070 100644 --- a/Source/SPFieldMapperController.h +++ b/Source/SPFieldMapperController.h @@ -114,6 +114,7 @@ NSString *isEqualString; NSInteger numberOfImportColumns; + NSMutableIndexSet *toBeEditedRowIndexes; BOOL fieldMappingImportArrayIsPreview; BOOL importFieldNamesHeader; @@ -181,6 +182,8 @@ - (IBAction)newTableInfo:(id)sender; - (IBAction)closeInfoSheet:(id)sender; - (IBAction)addNewColumn:(id)sender; +- (IBAction)removeNewColumn:(id)sender; +// - (IBAction)editColumn:(id)sender; - (IBAction)setAllTypesTo:(id)sender; // Others diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m index 2b262be6..7df1ea81 100644 --- a/Source/SPFieldMapperController.m +++ b/Source/SPFieldMapperController.m @@ -75,6 +75,7 @@ isEqualString = @"="; newTableMode = NO; addGlobalSheetIsOpen = NO; + toBeEditedRowIndexes = [[NSMutableIndexSet alloc] init]; prefs = [NSUserDefaults standardUserDefaults]; @@ -94,10 +95,12 @@ - (void)awakeFromNib { - [fieldMapperTableView setDelegate:self]; - [fieldMapperTableView setDataSource:self]; + // Set Context Menu [[[fieldMapperTableView menu] itemAtIndex:0] setHidden:YES]; [[[fieldMapperTableView menu] itemAtIndex:1] setHidden:YES]; + [[[fieldMapperTableView menu] itemAtIndex:2] setHidden:NO]; + [[[fieldMapperTableView menu] itemAtIndex:3] setHidden:NO]; + // [[[fieldMapperTableView menu] itemAtIndex:4] setHidden:NO]; // Set source path // Note: [fileSourcePath setURL:[NSURL fileWithPath:sourcePath]] does NOT work @@ -128,7 +131,7 @@ [tableTargetPopup addItemsWithTitles:allTableNames]; // Select either the currently selected table, or the first item in the list, or if no table in db switch to "New Table" mode - if ([[theDelegate valueForKeyPath:@"tableDocumentInstance"] table] != nil + if ([[theDelegate valueForKeyPath:@"tableDocumentInstance"] table] != nil && ![[tablesListInstance tableName] isEqualToString:@""] && [allTableNames containsObject:[tablesListInstance tableName]]) { [tableTargetPopup selectItemWithTitle:[tablesListInstance tableName]]; @@ -143,16 +146,16 @@ } [defaultFieldTypesForComboBox setArray:[NSArray arrayWithObjects: - @"varchar(255)", - @"char(65)", - @"text", - @"longtext", - @"int(11)", - @"bigint", - @"date", - @"datetime", - @"time", - @"timestamp", + @"VARCHAR(255)", + @"CHAR(63)", + @"TEXT", + @"LONGTEXT", + @"INT(11)", + @"BIGINT", + @"DATE", + @"DATETIME", + @"TIME", + @"TIMESTAMP", nil ]]; @@ -209,6 +212,7 @@ if (fieldMappingGlobalValuesSQLMarked) [fieldMappingGlobalValuesSQLMarked release]; if (fieldMappingTableDefaultValues) [fieldMappingTableDefaultValues release]; if (primaryKeyField) [primaryKeyField release]; + if (toBeEditedRowIndexes) [toBeEditedRowIndexes release]; [super dealloc]; } @@ -372,7 +376,7 @@ [prefs setObject:[newTableInfoEnginePopup titleOfSelectedItem] forKey:SPLastImportIntoNewTableType]; [prefs setObject:[newTableInfoEncodingPopup titleOfSelectedItem] forKey:SPLastImportIntoNewTableEncoding]; } - + [NSApp endSheet:[sender window] returnCode:[sender tag]]; [[sender window] orderOut:self]; } @@ -380,8 +384,45 @@ - (IBAction)closeSheet:(id)sender { + // Try to add new columns first + if(!newTableMode && [toBeEditedRowIndexes count] && [sender tag] == 1) { + [[self window] endEditingFor:nil]; + + NSUInteger currentIndex = [toBeEditedRowIndexes firstIndex]; + + while (currentIndex != NSNotFound) { + + NSMutableString *createString = [NSMutableString string]; + + [createString appendFormat:@"ALTER TABLE %@ ADD %@ %@", + [[tableTargetPopup titleOfSelectedItem] backtickQuotedString], + [[fieldMappingTableColumnNames objectAtIndex:currentIndex] backtickQuotedString], + [fieldMappingTableTypes objectAtIndex:currentIndex]]; + + [mySQLConnection queryString:createString]; + + if ([mySQLConnection queryErrored]) { + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error adding new column", @"error adding new column message") + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to add the new column '%@' by\n\n%@.\n\nMySQL said: %@", @"error adding new column informative message"), [fieldMappingTableColumnNames objectAtIndex:currentIndex], createString, [mySQLConnection getLastErrorMessage]]]; + + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:nil contextInfo:nil]; + return; + } else { + [toBeEditedRowIndexes removeIndex:currentIndex]; + } + + currentIndex = [toBeEditedRowIndexes indexGreaterThanIndex:currentIndex]; + } + + + } + // Try to create the new TABLE - if(newTableMode && [sender tag] == 1) { + else if(newTableMode && [sender tag] == 1) { [[self window] endEditingFor:nil]; @@ -406,10 +447,10 @@ [mySQLConnection queryString:createString]; if ([mySQLConnection queryErrored]) { - NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error adding new table", @"error adding new table message") - defaultButton:NSLocalizedString(@"OK", @"OK button") - alternateButton:nil - otherButton:nil + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error adding new table", @"error adding new table message") + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to add the new table '%@' by\n\n%@.\n\nMySQL said: %@", @"error adding new table informative message"), [newTableNameTextField stringValue], createString, [mySQLConnection getLastErrorMessage]]]; [alert setAlertStyle:NSCriticalAlertStyle]; @@ -434,6 +475,9 @@ NSArray *allTableNames = [tablesListInstance allTableNames]; NSInteger i; + // Remove all indexes for new columns + [toBeEditedRowIndexes removeAllIndexes]; + // Is Refresh List chosen? if([tableTargetPopup selectedItem] == [tableTargetPopup itemAtIndex:1]) { [tableTargetPopup removeAllItems]; @@ -448,7 +492,7 @@ } // Select either the currently selected table, or the first item in the list, or if no table in db switch to "New Table" mode - if ([[theDelegate valueForKeyPath:@"tableDocumentInstance"] table] != nil + if ([[theDelegate valueForKeyPath:@"tableDocumentInstance"] table] != nil && ![[tablesListInstance tableName] isEqualToString:@""] && [allTableNames containsObject:[tablesListInstance tableName]]) { [tableTargetPopup selectItemWithTitle:[tablesListInstance tableName]]; @@ -718,8 +762,12 @@ { newTableMode = YES; + // Set Context Menu [[[fieldMapperTableView menu] itemAtIndex:0] setHidden:NO]; - [[[fieldMapperTableView menu] itemAtIndex:1] setHidden:NO]; + [[[fieldMapperTableView menu] itemAtIndex:1] setHidden:YES]; + [[[fieldMapperTableView menu] itemAtIndex:2] setHidden:YES]; + [[[fieldMapperTableView menu] itemAtIndex:3] setHidden:YES]; + // [[[fieldMapperTableView menu] itemAtIndex:4] setHidden:YES]; [importMethodPopup selectItemWithTitle:@"INSERT"]; [[importMethodPopup itemWithTitle:@"UPDATE"] setEnabled:NO]; @@ -739,14 +787,14 @@ for(id h in NSArrayObjectAtIndex(fieldMappingImportArray, 0)) { [fieldMappingTableColumnNames addObject:h]; [fieldMappingTableDefaultValues addObject:@""]; - [fieldMappingTableTypes addObject:@"varchar(255)"]; + [fieldMappingTableTypes addObject:@"VARCHAR(255)"]; } } else { NSInteger i = 0; for(id h in NSArrayObjectAtIndex(fieldMappingImportArray, 0)) { [fieldMappingTableColumnNames addObject:[NSString stringWithFormat:@"col_%ld", i++]]; [fieldMappingTableDefaultValues addObject:@""]; - [fieldMappingTableTypes addObject:@"varchar(255)"]; + [fieldMappingTableTypes addObject:@"VARCHAR(255)"]; } } @@ -771,11 +819,71 @@ [self validateImportButton]; } +/* + * Add new column to the selected table (processed after pressing 'Import' button) + */ - (IBAction)addNewColumn:(id)sender { - + + [fieldMappingOperatorArray addObject:doNotImport]; + [fieldMappingTableColumnNames addObject:NSLocalizedString(@"New Column Name", @"new column name placeholder string")]; + [fieldMappingTableTypes addObject:@"VARCHAR(255)"]; + [fieldMappingTableDefaultValues addObject:@""]; + + NSInteger newIndex = [fieldMappingTableTypes count]-1; + + [fieldMappingArray addObject:[NSNumber numberWithInteger:newIndex]]; + [toBeEditedRowIndexes addIndex:newIndex]; + + [fieldMapperTableView reloadData]; + + [fieldMapperTableView editColumn:2 row:newIndex withEvent:nil select:YES]; + +} + + +/* + * Remove currently new added column + */ +- (IBAction)removeNewColumn:(id)sender +{ + + NSInteger toBeRemovedIndex = [fieldMapperTableView selectedRow]; + + if(![toBeEditedRowIndexes containsIndex:toBeRemovedIndex]) { + NSBeep(); + return; + } + + [fieldMappingOperatorArray removeObjectAtIndex:toBeRemovedIndex]; + [fieldMappingTableColumnNames removeObjectAtIndex:toBeRemovedIndex]; + [fieldMappingTableTypes removeObjectAtIndex:toBeRemovedIndex]; + [fieldMappingTableDefaultValues removeObjectAtIndex:toBeRemovedIndex]; + + [fieldMappingArray removeObjectAtIndex:toBeRemovedIndex]; + [toBeEditedRowIndexes removeIndex:toBeRemovedIndex]; + + // Renumber indexes greater than toBeRemovedIndex + NSInteger currentIndex = [toBeEditedRowIndexes firstIndex]; + while(currentIndex != NSNotFound) { + if(currentIndex > toBeRemovedIndex) { + [toBeEditedRowIndexes addIndex:currentIndex-1]; + [toBeEditedRowIndexes removeIndex:currentIndex]; + } + currentIndex = [toBeEditedRowIndexes indexGreaterThanIndex:currentIndex]; + } + + [fieldMapperTableView reloadData]; + } +// - (IBAction)editColumn:(id)sender +// { +// toBeEditedRowIndexes = [fieldMapperTableView selectedRow]; +// [fieldMapperTableView reloadData]; +// [fieldMapperTableView editColumn:3 row:[fieldMapperTableView selectedRow] withEvent:nil select:YES]; +// } + /* * Set all table target field types to that one of the current selected type */ @@ -795,26 +903,29 @@ [type release]; } +/* + * Show sheet to set up encoding and engine for the new to be created table + */ - (IBAction)newTableInfo:(id)sender { [[self window] endEditingFor:nil]; - + // Populate the table type (engine) popup button [newTableInfoEnginePopup removeAllItems]; - + NSArray *engines = [databaseDataInstance getDatabaseStorageEngines]; - + // Add default menu item [newTableInfoEnginePopup addItemWithTitle:@"Default"]; [[newTableInfoEnginePopup menu] addItem:[NSMenuItem separatorItem]]; - + for (NSDictionary *engine in engines) { [newTableInfoEnginePopup addItemWithTitle:[engine objectForKey:@"Engine"]]; } - + [newTableInfoEnginePopup selectItemWithTitle:[prefs objectForKey:SPLastImportIntoNewTableType]]; - + // Populate the table encoding popup button with a default menu item [newTableInfoEncodingPopup removeAllItems]; [newTableInfoEncodingPopup addItemWithTitle:@"Default"]; @@ -846,7 +957,7 @@ [newTableInfoEncodingPopup selectItemWithTitle:[prefs objectForKey:SPLastImportIntoNewTableEncoding]]; } - + [NSApp beginSheet:newTableInfoWindow modalForWindow:[self window] modalDelegate:self @@ -1270,11 +1381,29 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { + NSInteger row = [fieldMapperTableView selectedRow]; + + // Hide/display Remove New Column menu item + [[[fieldMapperTableView menu] itemAtIndex:3] setHidden:([toBeEditedRowIndexes containsIndex:row]) ? NO : YES]; + if (newTableMode && [menuItem action] == @selector(setAllTypesTo:)) { - NSInteger row = [fieldMapperTableView selectedRow]; - NSMenuItem *setAllItem = [[fieldMapperTableView menu] itemAtIndex:0]; - NSString *orgTitle = [[setAllItem title] substringToIndex:[[setAllItem title] rangeOfString:@":"].location]; - [setAllItem setTitle:[NSString stringWithFormat:@"%@: %@", orgTitle, [fieldMappingTableTypes objectAtIndex:row]]]; + NSString *orgTitle = [[menuItem title] substringToIndex:[[menuItem title] rangeOfString:@":"].location]; + [menuItem setTitle:[NSString stringWithFormat:@"%@: %@", orgTitle, [fieldMappingTableTypes objectAtIndex:row]]]; + } + else if (!newTableMode && [menuItem action] == @selector(editColumn:)) { + NSString *orgTitle = [[menuItem title] substringToIndex:[[menuItem title] rangeOfString:@":"].location]; + [menuItem setTitle:[NSString stringWithFormat:@"%@: %@", orgTitle, [fieldMappingTableColumnNames objectAtIndex:row]]]; + } + else if (!newTableMode && [menuItem action] == @selector(removeNewColumn:)) { + if([toBeEditedRowIndexes containsIndex:row]) { + NSString *orgTitle = [[menuItem title] substringToIndex:[[menuItem title] rangeOfString:@":"].location]; + [menuItem setTitle:[NSString stringWithFormat:@"%@: %@", orgTitle, [fieldMappingTableColumnNames objectAtIndex:row]]]; + return YES; + } else { + NSString *orgTitle = [[menuItem title] substringToIndex:[[menuItem title] rangeOfString:@":"].location]; + [menuItem setTitle:[NSString stringWithFormat:@"%@:", orgTitle]]; + return NO; + } } return YES; @@ -1369,6 +1498,13 @@ if(aTableView == fieldMapperTableView) { if ([[aTableColumn identifier] isEqualToString:@"target_field"]) { + if([toBeEditedRowIndexes containsIndex:rowIndex]) { + NSTextFieldCell *b = [[[NSTextFieldCell alloc] initTextCell:[fieldMappingTableColumnNames objectAtIndex:rowIndex]] autorelease]; + [b setEditable:YES]; + [b setFont:[NSFont systemFontOfSize:12]]; + [aTableColumn setDataCell:b]; + return b; + } if(newTableMode) { NSTextFieldCell *b = [[[NSTextFieldCell alloc] initTextCell:[fieldMappingTableColumnNames objectAtIndex:rowIndex]] autorelease]; [b setEditable:YES]; @@ -1385,6 +1521,10 @@ } else if ([[aTableColumn identifier] isEqualToString:@"type"]) { + if([toBeEditedRowIndexes containsIndex:rowIndex]) { + [aTableColumn setDataCell:typeComboxBox]; + return [fieldMappingTableTypes objectAtIndex:rowIndex]; + } if(newTableMode) { [aTableColumn setDataCell:typeComboxBox]; return [fieldMappingTableTypes objectAtIndex:rowIndex]; @@ -1460,6 +1600,8 @@ { if(aTableView == globalValuesTableView) return YES; + if([toBeEditedRowIndexes containsIndex:rowIndex]) return YES; + if(!newTableMode) return NO; return YES; @@ -1524,17 +1666,23 @@ } - else if (newTableMode && [[aTableColumn identifier] isEqualToString:@"target_field"]) { - if([(NSString*)anObject length]) { - [fieldMappingTableColumnNames replaceObjectAtIndex:rowIndex withObject:anObject]; + else if ([[aTableColumn identifier] isEqualToString:@"target_field"]) { + if(newTableMode || [toBeEditedRowIndexes containsIndex:rowIndex]) { + if([(NSString*)anObject length]) { + [fieldMappingTableColumnNames replaceObjectAtIndex:rowIndex withObject:anObject]; + } } } - 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]; + else if ([[aTableColumn identifier] isEqualToString:@"type"]) { + if(newTableMode || [toBeEditedRowIndexes containsIndex:rowIndex]) { + if([(NSString*)anObject length]) { + [fieldMappingTableTypes replaceObjectAtIndex:rowIndex withObject:anObject]; + if(![defaultFieldTypesForComboBox containsObject:anObject]) + [defaultFieldTypesForComboBox insertObject:anObject atIndex:0]; + } + } else { + } } @@ -1578,7 +1726,7 @@ - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command { - if(!newTableMode || addGlobalSheetIsOpen) return NO; + if((!newTableMode || addGlobalSheetIsOpen) && ![toBeEditedRowIndexes containsIndex:[fieldMapperTableView selectedRow]]) return NO; NSUInteger row, column; @@ -1667,6 +1815,8 @@ [[control window] makeFirstResponder:control]; + if(![toBeEditedRowIndexes containsIndex:newRow]) return NO; + [fieldMapperTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:newRow] byExtendingSelection:NO]; [fieldMapperTableView editColumn:column row:newRow withEvent:nil select:YES]; return YES; -- cgit v1.2.3