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 | |
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
-rw-r--r-- | Interfaces/English.lproj/DataMigrationDialog.xib | 147 | ||||
-rw-r--r-- | Source/SPFieldMapperController.h | 6 | ||||
-rw-r--r-- | Source/SPFieldMapperController.m | 73 | ||||
-rw-r--r-- | Source/SPTableView.m | 14 |
4 files changed, 199 insertions, 41 deletions
diff --git a/Interfaces/English.lproj/DataMigrationDialog.xib b/Interfaces/English.lproj/DataMigrationDialog.xib index 97194022..2d707c4d 100644 --- a/Interfaces/English.lproj/DataMigrationDialog.xib +++ b/Interfaces/English.lproj/DataMigrationDialog.xib @@ -12,7 +12,8 @@ </object> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="13"/> + <integer value="161"/> + <integer value="42"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -407,11 +408,11 @@ <reference key="NSBackgroundColor" ref="646298629"/> <reference key="NSTextColor" ref="186205954"/> </object> - <object class="NSTextFieldCell" key="NSDataCell" id="950341880"> - <int key="NSCellFlags">337772096</int> + <object class="NSTextFieldCell" key="NSDataCell" id="823052477"> + <int key="NSCellFlags">67239488</int> <int key="NSCellFlags2">272761856</int> <string key="NSContents">Text</string> - <reference key="NSSupport" ref="219022499"/> + <reference key="NSSupport" ref="26"/> <reference key="NSControlView" ref="678921094"/> <reference key="NSBackgroundColor" ref="19028295"/> <reference key="NSTextColor" ref="263116164"/> @@ -1446,7 +1447,7 @@ <string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string> <string key="NSWindowContentMinSize">{311, 186}</string> <object class="NSView" key="NSWindowView" id="803374494"> - <nil key="NSNextResponder"/> + <reference key="NSNextResponder"/> <int key="NSvFlags">274</int> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -1764,6 +1765,7 @@ </object> </object> <string key="NSFrameSize">{311, 186}</string> + <reference key="NSSuperview"/> </object> <string key="NSScreenRect">{{0, 0}, {1280, 1002}}</string> <string key="NSMinSize">{311, 208}</string> @@ -1773,6 +1775,78 @@ <object class="NSUserDefaultsController" id="443551699"> <bool key="NSSharedInstance">YES</bool> </object> + <object class="NSComboBoxCell" id="530703452"> + <int key="NSCellFlags">338820672</int> + <int key="NSCellFlags2">272761856</int> + <string key="NSContents"/> + <reference key="NSSupport" ref="26"/> + <reference key="NSBackgroundColor" ref="105487286"/> + <reference key="NSTextColor" ref="263116164"/> + <int key="NSVisibleItemCount">9</int> + <bool key="NSHasVerticalScroller">YES</bool> + <bool key="NSUsesDataSource">YES</bool> + <bool key="NSCompletes">YES</bool> + <nil key="NSDataSource"/> + <object class="NSComboTableView" key="NSTableView" id="80897582"> + <reference key="NSNextResponder"/> + <int key="NSvFlags">274</int> + <string key="NSFrameSize">{15, 0}</string> + <reference key="NSSuperview"/> + <reference key="NSWindow"/> + <bool key="NSEnabled">YES</bool> + <object class="NSMutableArray" key="NSTableColumns"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSTableColumn"> + <integer value="0" key="NSIdentifier"/> + <double key="NSWidth">12</double> + <double key="NSMinWidth">10</double> + <double key="NSMaxWidth">1000</double> + <object class="NSTableHeaderCell" key="NSHeaderCell"> + <int key="NSCellFlags">75628032</int> + <int key="NSCellFlags2">0</int> + <string key="NSContents"/> + <object class="NSFont" key="NSSupport"> + <string key="NSName">LucidaGrande</string> + <double key="NSSize">12</double> + <int key="NSfFlags">16</int> + </object> + <object class="NSColor" key="NSBackgroundColor"> + <int key="NSColorSpace">3</int> + <bytes key="NSWhite">MC4zMzMzMzI5ODU2AA</bytes> + </object> + <reference key="NSTextColor" ref="746040121"/> + </object> + <object class="NSTextFieldCell" key="NSDataCell"> + <int key="NSCellFlags">338820672</int> + <int key="NSCellFlags2">1024</int> + <reference key="NSSupport" ref="26"/> + <reference key="NSControlView" ref="80897582"/> + <bool key="NSDrawsBackground">YES</bool> + <reference key="NSBackgroundColor" ref="518286732"/> + <reference key="NSTextColor" ref="263116164"/> + </object> + <int key="NSResizingMask">3</int> + <bool key="NSIsResizeable">YES</bool> + <reference key="NSTableView" ref="80897582"/> + </object> + </object> + <double key="NSIntercellSpacingWidth">3</double> + <double key="NSIntercellSpacingHeight">2</double> + <reference key="NSBackgroundColor" ref="518286732"/> + <reference key="NSGridColor" ref="406268685"/> + <double key="NSRowHeight">16</double> + <string key="NSAction">tableViewAction:</string> + <int key="NSTvFlags">-767524864</int> + <reference key="NSDelegate" ref="530703452"/> + <reference key="NSTarget" ref="530703452"/> + <int key="NSColumnAutoresizingStyle">1</int> + <int key="NSDraggingSourceMaskForLocal">15</int> + <int key="NSDraggingSourceMaskForNonLocal">0</int> + <bool key="NSAllowsTypeSelect">YES</bool> + <int key="NSTableViewDraggingDestinationStyle">0</int> + </object> + <bool key="NSButtonBordered">NO</bool> + </object> </object> <object class="IBObjectContainer" key="IBDocument.Objects"> <object class="NSMutableArray" key="connectionRecords"> @@ -2339,27 +2413,27 @@ </object> <object class="IBConnectionRecord"> <object class="IBOutletConnection" key="connection"> - <string key="label">dataSource</string> - <reference key="source" ref="678921094"/> - <reference key="destination" ref="1001"/> + <string key="label">fieldMapperTableView</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="678921094"/> </object> - <int key="connectionID">410</int> + <int key="connectionID">413</int> </object> <object class="IBConnectionRecord"> <object class="IBOutletConnection" key="connection"> - <string key="label">delegate</string> - <reference key="source" ref="678921094"/> - <reference key="destination" ref="1001"/> + <string key="label">typeComboxBox</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="530703452"/> </object> - <int key="connectionID">411</int> + <int key="connectionID">418</int> </object> <object class="IBConnectionRecord"> <object class="IBOutletConnection" key="connection"> - <string key="label">fieldMapperTableView</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="678921094"/> + <string key="label">dataSource</string> + <reference key="source" ref="530703452"/> + <reference key="destination" ref="1001"/> </object> - <int key="connectionID">413</int> + <int key="connectionID">419</int> </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> @@ -2837,16 +2911,11 @@ <reference key="object" ref="221439252"/> <object class="NSMutableArray" key="children"> <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="950341880"/> + <reference ref="823052477"/> </object> <reference key="parent" ref="678921094"/> </object> <object class="IBObjectRecord"> - <int key="objectID">149</int> - <reference key="object" ref="950341880"/> - <reference key="parent" ref="221439252"/> - </object> - <object class="IBObjectRecord"> <int key="objectID">157</int> <reference key="object" ref="148795893"/> <object class="NSMutableArray" key="children"> @@ -3320,6 +3389,17 @@ <reference key="object" ref="696977787"/> <reference key="parent" ref="426092195"/> </object> + <object class="IBObjectRecord"> + <int key="objectID">416</int> + <reference key="object" ref="530703452"/> + <reference key="parent" ref="0"/> + <string key="objectName">Combo Box Cell for new table types</string> + </object> + <object class="IBObjectRecord"> + <int key="objectID">417</int> + <reference key="object" ref="823052477"/> + <reference key="parent" ref="221439252"/> + </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -3356,7 +3436,6 @@ <string>140.IBPluginDependency</string> <string>141.IBPluginDependency</string> <string>144.IBPluginDependency</string> - <string>149.IBPluginDependency</string> <string>15.IBAttributePlaceholdersKey</string> <string>15.IBPluginDependency</string> <string>15.ImportedFromIB2</string> @@ -3469,6 +3548,9 @@ <string>405.IBPluginDependency</string> <string>406.IBPluginDependency</string> <string>41.IBPluginDependency</string> + <string>416.IBPluginDependency</string> + <string>417.CustomClassName</string> + <string>417.IBPluginDependency</string> <string>42.CustomClassName</string> <string>42.IBPluginDependency</string> <string>42.ImportedFromIB2</string> @@ -3500,9 +3582,9 @@ <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{749, 497}, {522, 348}}</string> + <string>{{742, 423}, {522, 348}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{749, 497}, {522, 348}}</string> + <string>{{742, 423}, {522, 348}}</string> <integer value="1"/> <string>{{387, 725}, {432, 282}}</string> <boolean value="NO"/> @@ -3536,7 +3618,6 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <object class="NSMutableDictionary"> <string key="NS.key.0">ToolTip</string> <object class="IBToolTipAttribute" key="NS.object.0"> @@ -3729,6 +3810,9 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>NSSecureTextFieldCell</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>SPTableView</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <integer value="1"/> @@ -3774,7 +3858,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">413</int> + <int key="maxID">419</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -4598,6 +4682,7 @@ <string>tableTargetPopup</string> <string>tablesListInstance</string> <string>theDelegate</string> + <string>typeComboxBox</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -4645,6 +4730,7 @@ <string>NSPopUpButton</string> <string>id</string> <string>id</string> + <string>NSComboBoxCell</string> </object> </object> <object class="NSMutableDictionary" key="toOneOutletInfosByName"> @@ -4695,6 +4781,7 @@ <string>tableTargetPopup</string> <string>tablesListInstance</string> <string>theDelegate</string> + <string>typeComboxBox</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -4874,6 +4961,10 @@ <string key="name">theDelegate</string> <string key="candidateClassName">id</string> </object> + <object class="IBToOneOutletInfo"> + <string key="name">typeComboxBox</string> + <string key="candidateClassName">NSComboBoxCell</string> + </object> </object> </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> 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"] && |