From f86f79972a0960772f46356bb3949757e82f796e Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 9 Sep 2010 22:00:24 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Structure=20editing=20-=20fixed=20issue=20w?= =?UTF-8?q?hile=20drag&drop=20an=20auto=5Finc=20field=20>=20ignore=20DEFAU?= =?UTF-8?q?LT=20-=20fixed=20several=20keyboard=20navigation=20issues=20-?= =?UTF-8?q?=20further=20code=20improvements=20-=20fixed=20encoding=20editi?= =?UTF-8?q?ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/DBView.xib | 310 +++++++++++++++++++++++++++++++++++- Source/SPTableStructure.h | 2 + Source/SPTableStructure.m | 119 ++++++++------ 3 files changed, 380 insertions(+), 51 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 347fc01b..e5b93be2 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -23,7 +23,7 @@ YES - + YES @@ -1487,7 +1487,7 @@ 133120 - 100679935 + -1241497345 129 @@ -14748,6 +14748,14 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 7483 + + + encodingPopupCell + + + + 7496 + @@ -23306,7 +23314,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{125, 253}, {943, 549}} + {{-19, 172}, {943, 549}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -23617,7 +23625,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{339, 775}, {694, 4}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{339, 775}, {694, 4}} + {{339, 727}, {694, 6}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -23657,7 +23665,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 - 7495 + 7497 @@ -28930,6 +28938,298 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + + YES + + SPTableStructure + NSObject + + YES + + YES + addField: + closeKeySheet: + closeSheet: + copyField: + reloadTable: + removeField: + resetAutoIncrement: + unhideIndexesView: + + + YES + id + id + id + id + id + id + id + id + + + + YES + + YES + addField: + closeKeySheet: + closeSheet: + copyField: + reloadTable: + removeField: + resetAutoIncrement: + unhideIndexesView: + + + YES + + addField: + id + + + closeKeySheet: + id + + + closeSheet: + id + + + copyField: + id + + + reloadTable: + id + + + removeField: + id + + + resetAutoIncrement: + id + + + unhideIndexesView: + id + + + + + YES + + YES + addFieldButton + addIndexButton + chooseKeyButton + collationPopupCell + copyFieldButton + databaseDataInstance + editTableButton + encodingPopupCell + extendedTableInfoInstance + indexesController + indexesShowButton + indexesTableView + keySheet + refreshIndexesButton + reloadFieldsButton + removeFieldButton + removeIndexButton + resetAutoIncrementLine + resetAutoIncrementSheet + resetAutoIncrementValue + structureGrabber + tableDataInstance + tableDocumentInstance + tableInfoInstance + tableSourceView + tablesIndexesSplitView + tablesListInstance + + + YES + id + id + id + id + id + id + id + id + id + id + NSButton + id + id + id + id + id + id + id + id + id + id + id + id + id + id + NSSplitView + id + + + + YES + + YES + addFieldButton + addIndexButton + chooseKeyButton + collationPopupCell + copyFieldButton + databaseDataInstance + editTableButton + encodingPopupCell + extendedTableInfoInstance + indexesController + indexesShowButton + indexesTableView + keySheet + refreshIndexesButton + reloadFieldsButton + removeFieldButton + removeIndexButton + resetAutoIncrementLine + resetAutoIncrementSheet + resetAutoIncrementValue + structureGrabber + tableDataInstance + tableDocumentInstance + tableInfoInstance + tableSourceView + tablesIndexesSplitView + tablesListInstance + + + YES + + addFieldButton + id + + + addIndexButton + id + + + chooseKeyButton + id + + + collationPopupCell + id + + + copyFieldButton + id + + + databaseDataInstance + id + + + editTableButton + id + + + encodingPopupCell + id + + + extendedTableInfoInstance + id + + + indexesController + id + + + indexesShowButton + NSButton + + + indexesTableView + id + + + keySheet + id + + + refreshIndexesButton + id + + + reloadFieldsButton + id + + + removeFieldButton + id + + + removeIndexButton + id + + + resetAutoIncrementLine + id + + + resetAutoIncrementSheet + id + + + resetAutoIncrementValue + id + + + structureGrabber + id + + + tableDataInstance + id + + + tableDocumentInstance + id + + + tableInfoInstance + id + + + tableSourceView + id + + + tablesIndexesSplitView + NSSplitView + + + tablesListInstance + id + + + + + IBDocumentRelativeSource + ../../Source/SPTableStructure.h + + + YES diff --git a/Source/SPTableStructure.h b/Source/SPTableStructure.h index 74905e5e..0be1082b 100644 --- a/Source/SPTableStructure.h +++ b/Source/SPTableStructure.h @@ -54,6 +54,8 @@ IBOutlet NSSplitView *tablesIndexesSplitView; IBOutlet NSButton *indexesShowButton; + IBOutlet id encodingPopupCell; + id databaseDataInstance; MCPConnection *mySQLConnection; diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m index ce21b705..2b4db263 100644 --- a/Source/SPTableStructure.m +++ b/Source/SPTableStructure.m @@ -159,17 +159,17 @@ NSArray *encodings = [databaseDataInstance getDatabaseCharacterSetEncodings]; if (([encodings count] > 0) && ([tableDataInstance tableEncoding])) { NSString *selectedTitle = @""; - [[[[tableSourceView tableColumns] objectAtIndex:10] dataCell] removeAllItems]; - [[[[tableSourceView tableColumns] objectAtIndex:10] dataCell] addItemWithTitle:@""]; + [encodingPopupCell removeAllItems]; + [encodingPopupCell addItemWithTitle:@""]; // Populate encoding popup button for (NSDictionary *encoding in encodings) { NSString *menuItemTitle = (![encoding objectForKey:@"DESCRIPTION"]) ? [encoding objectForKey:@"CHARACTER_SET_NAME"] : [NSString stringWithFormat:@"%@ (%@)", [encoding objectForKey:@"DESCRIPTION"], [encoding objectForKey:@"CHARACTER_SET_NAME"]]; - [[[[tableSourceView tableColumns] objectAtIndex:10] dataCell] addItemWithTitle:menuItemTitle]; + [encodingPopupCell addItemWithTitle:menuItemTitle]; } } else { - [[[[tableSourceView tableColumns] objectAtIndex:10] dataCell] addItemWithTitle:NSLocalizedString(@"Not available", @"not available label")]; + [encodingPopupCell addItemWithTitle:NSLocalizedString(@"Not available", @"not available label")]; } // Process all the fields to normalise keys and add additional information @@ -343,7 +343,7 @@ NSInteger insertIndex = ([tableSourceView numberOfSelectedRows] == 0 ? [tableSourceView numberOfRows] : [tableSourceView selectedRow] + 1); [tableFields insertObject:[NSMutableDictionary - dictionaryWithObjects:[NSArray arrayWithObjects:@"", @"INT", @"", @"0", @"0", @"0", ([prefs boolForKey:SPNewFieldsAllowNulls]) ? @"1" : @"0", @"", [prefs stringForKey:SPNullValue], @"None", @"", @"", @"", nil] + dictionaryWithObjects:[NSArray arrayWithObjects:@"", @"INT", @"", @"0", @"0", @"0", ([prefs boolForKey:SPNewFieldsAllowNulls]) ? @"1" : @"0", @"", [prefs stringForKey:SPNullValue], @"None", @"", [NSNumber numberWithInt:0], [NSNumber numberWithInt:0], nil] forKeys:[NSArray arrayWithObjects:@"name", @"type", @"length", @"unsigned", @"zerofill", @"binary", @"null", @"Key", @"default", @"Extra", @"comment", @"encoding", @"collation", nil]] atIndex:insertIndex]; @@ -745,7 +745,7 @@ closes the keySheet NSString *fieldEncoding = @""; if([[theRow objectForKey:@"encoding"] integerValue] > 0) { - NSString *enc = [[[[[tableSourceView tableColumns] objectAtIndex:10] dataCell] itemAtIndex:[[theRow objectForKey:@"encoding"] integerValue]] title]; + NSString *enc = [[encodingPopupCell itemAtIndex:[[theRow objectForKey:@"encoding"] integerValue]] title]; NSInteger start = [enc rangeOfString:@"("].location+1; NSInteger end = [enc length] - start - 1; fieldEncoding = [enc substringWithRange:NSMakeRange(start, end)]; @@ -1254,7 +1254,7 @@ returns a dictionary containing enum/set field names as key and possible values if([[tableColumn identifier] isEqualToString:@"collation"]) { if([[[tableFields objectAtIndex:rowIndex] objectForKey:@"encoding"] integerValue] > 0) { - NSString *enc = [[[[[tableSourceView tableColumns] objectAtIndex:10] dataCell] itemAtIndex:[[[tableFields objectAtIndex:rowIndex] objectForKey:@"encoding"] integerValue]] title]; + NSString *enc = [[encodingPopupCell itemAtIndex:[[[tableFields objectAtIndex:rowIndex] objectForKey:@"encoding"] integerValue]] title]; NSInteger start = [enc rangeOfString:@"("].location+1; NSInteger end = [enc length] - start - 1; collations = [databaseDataInstance getDatabaseCollationsForEncoding:[enc substringWithRange:NSMakeRange(start, end)]]; @@ -1281,8 +1281,8 @@ returns a dictionary containing enum/set field names as key and possible values - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { - // Make sure that the drag operation is for the right table view - if (aTableView!=tableSourceView) return; + // Make sure that the drag operation is for the right table view + if (aTableView != tableSourceView) return; if (!isEditingRow) { [oldRow setDictionary:[tableFields objectAtIndex:rowIndex]]; @@ -1298,7 +1298,13 @@ returns a dictionary containing enum/set field names as key and possible values } } - [[tableFields objectAtIndex:rowIndex] setObject:(anObject) ? anObject : @"" forKey:[aTableColumn identifier]]; + if([[aTableColumn identifier] isEqualToString:@"type"]) { + if(anObject && [(NSString*)anObject length] && ![(NSString*)anObject hasPrefix:@"--"]) + [[tableFields objectAtIndex:rowIndex] setObject:[(NSString*)anObject uppercaseString] forKey:@"type"]; + } + else + [[tableFields objectAtIndex:rowIndex] setObject:(anObject) ? anObject : @"" forKey:[aTableColumn identifier]]; + } /** @@ -1394,7 +1400,7 @@ would result in a position change. NSString *fieldEncoding = @""; if([[originalRow objectForKey:@"encoding"] integerValue] > 0) { - NSString *enc = [[[[[tableSourceView tableColumns] objectAtIndex:10] dataCell] itemAtIndex:[[originalRow objectForKey:@"encoding"] integerValue]] title]; + NSString *enc = [[encodingPopupCell itemAtIndex:[[originalRow objectForKey:@"encoding"] integerValue]] title]; NSInteger start = [enc rangeOfString:@"("].location+1; NSInteger end = [enc length] - start - 1; fieldEncoding = [enc substringWithRange:NSMakeRange(start, end)]; @@ -1430,17 +1436,19 @@ would result in a position change. BOOL isTimestampType = [[[originalRow objectForKey:@"type"] lowercaseString] isEqualToString:@"timestamp"]; - // Add the default value - if ([[originalRow objectForKey:@"default"] isEqualToString:[prefs objectForKey:SPNullValue]]) { - if ([[originalRow objectForKey:@"null"] integerValue] == 1) { - [queryString appendString:(isTimestampType) ? @" NULL DEFAULT NULL" : @" DEFAULT NULL"]; + // Add the default value, skip it for auto_increment + if([originalRow objectForKey:@"Extra"] && ![[originalRow objectForKey:@"Extra"] isEqualToString:@"auto_increment"]) { + if ([[originalRow objectForKey:@"default"] isEqualToString:[prefs objectForKey:SPNullValue]]) { + if ([[originalRow objectForKey:@"null"] integerValue] == 1) { + [queryString appendString:(isTimestampType) ? @" NULL DEFAULT NULL" : @" DEFAULT NULL"]; + } + } + else if (isTimestampType && ([[[originalRow objectForKey:@"default"] uppercaseString] isEqualToString:@"CURRENT_TIMESTAMP"]) ) { + [queryString appendString:@" DEFAULT CURRENT_TIMESTAMP"]; + } + else { + [queryString appendFormat:@" DEFAULT '%@'", [mySQLConnection prepareString:[originalRow objectForKey:@"default"]]]; } - } - else if (isTimestampType && ([[[originalRow objectForKey:@"default"] uppercaseString] isEqualToString:@"CURRENT_TIMESTAMP"]) ) { - [queryString appendString:@" DEFAULT CURRENT_TIMESTAMP"]; - } - else { - [queryString appendFormat:@" DEFAULT '%@'", [mySQLConnection prepareString:[originalRow objectForKey:@"default"]]]; } // Any column comments @@ -1533,41 +1541,57 @@ would result in a position change. column = [tableSourceView editedColumn]; // Trap the tab key, selecting the next item in the line - if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)] ) + if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)] && [tableSourceView numberOfColumns] - 1 == column) { //save current line [[control window] makeFirstResponder:control]; - if ( column == 9 ) { - if ( [self addRowToDB] && [textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)] ) { - if ( row < ([tableSourceView numberOfRows] - 1) ) { - [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:row+1] byExtendingSelection:NO]; - [tableSourceView editColumn:0 row:row+1 withEvent:nil select:YES]; - } else { - [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO]; - [tableSourceView editColumn:0 row:0 withEvent:nil select:YES]; - } + + if ( [self addRowToDB] && [textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)] ) { + if ( row < ([tableSourceView numberOfRows] - 1) ) { + [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:row+1] byExtendingSelection:NO]; + [tableSourceView editColumn:0 row:row+1 withEvent:nil select:YES]; + } else { + [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO]; + [tableSourceView editColumn:0 row:0 withEvent:nil select:YES]; } - } else { - if ( column == 2 ) { - [tableSourceView editColumn:column+6 row:row withEvent:nil select:YES]; + } + return YES; + + } + + // Trap shift-tab key + else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertBacktab:)] && column < 1) + { + if ( [self addRowToDB] && [textView methodForSelector:command] == [textView methodForSelector:@selector(insertBacktab:)] ) { + [[control window] makeFirstResponder:control]; + if ( row > 0) { + [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:row-1] byExtendingSelection:NO]; + [tableSourceView editColumn:([tableFields count]-1) row:row-1 withEvent:nil select:YES]; } else { - [tableSourceView editColumn:column+1 row:row withEvent:nil select:YES]; + [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:([tableFields count]-1)] byExtendingSelection:NO]; + [tableSourceView editColumn:([tableFields count]-1) row:([tableSourceView numberOfRows]-1) withEvent:nil select:YES]; } } - return TRUE; + return YES; + } // Trap the enter key, triggering a save - } else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertNewline:)] ) { + // Suppress enter for non-text fields to allow selecting of chosen items from comboboxes or popups + if(![[[[[[tableSourceView tableColumns] objectAtIndex:column] dataCell] class] description] isEqualToString:@"NSTextFieldCell"]) + return YES; + [[control window] makeFirstResponder:control]; [self addRowToDB]; - return TRUE; + [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO]; + [tableSourceView makeFirstResponder]; + return YES; + + } // Trap escape, aborting the edit and reverting the row - } - else if ( [[control window] methodForSelector:command] == [[control window] methodForSelector:@selector(_cancelKey:)] || - [textView methodForSelector:command] == [textView methodForSelector:@selector(complete:)] ) + else if ( [[control window] methodForSelector:command] == [[control window] methodForSelector:@selector(cancelOperation:)] ) { [control abortEditing]; if ( isEditingRow && !isEditingNewRow ) { @@ -1580,9 +1604,11 @@ would result in a position change. [tableSourceView reloadData]; } currentlyEditingRow = -1; - return TRUE; + [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO]; + [tableSourceView makeFirstResponder]; + return YES; } else { - return FALSE; + return NO; } } @@ -1591,10 +1617,11 @@ would result in a position change. * Modify cell display by disabling table cells when a view is selected, meaning structure/index * is uneditable. */ -- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { +- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex +{ - //make sure that the message is from the right table view - if (tableView!=tableSourceView) return; + //make sure that the message is from the right table view + if (tableView != tableSourceView) return; [aCell setEnabled:([tablesListInstance tableType] == SPTableTypeTable)]; } -- cgit v1.2.3