From 388ccb95f9cadc161f5bb35f34124effa73ab52d Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 23 Aug 2010 12:54:23 +0000 Subject: =?UTF-8?q?=E2=80=A2=20changed=20TAB=20and=20SHIFT-TAB=20behaviour?= =?UTF-8?q?=20of=20Content=20Window=20table=20-=20now=20it=20selects=20any?= =?UTF-8?q?=20field=20(if=20it's=20editable=20for=20views)=20regardless=20?= =?UTF-8?q?whether=20the=20field=20is=20a=20blob=20-=20if=20user=20tries?= =?UTF-8?q?=20to=20edit=20a=20blob=20field=20the=20field=20editor=20sheet?= =?UTF-8?q?=20will=20occur=20for=20editing=20=E2=80=A2=20after=20cancellat?= =?UTF-8?q?ion=20of=20cell=20editing=20in=20the=20Content=20Window=20table?= =?UTF-8?q?=20preserve=20the=20focus=20on=20the=20table=20=E2=80=A2=20mino?= =?UTF-8?q?r=20code=20cosmetics=20for=20editing=20of=20data=20coming=20fro?= =?UTF-8?q?m=20a=20view=20in=20Content=20Window?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPTableContent.m | 127 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 98 insertions(+), 29 deletions(-) diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 9e50bb67..8f140fce 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -761,13 +761,13 @@ } // Ensure the table is aware of changes - if ([NSThread isMainThread]) { - [tableContentView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES]; - } else { - [tableContentView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:YES]; - [tableContentView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; - } - + if ([NSThread isMainThread]) { + [tableContentView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES]; + } else { + [tableContentView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:YES]; + [tableContentView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; + } + // Clean up the autorelease pool and reset the progress indicator [dataLoadingPool drain]; [dataLoadingIndicator setIndeterminate:YES]; @@ -2631,7 +2631,7 @@ */ - (NSInteger)fieldEditStatusForRow:(NSInteger)rowIndex andColumn:(NSInteger)columnIndex { - NSDictionary *columnDefinition; + NSDictionary *columnDefinition = nil; // Retrieve the column defintion for(id c in cqColumnDefinition) { @@ -2641,6 +2641,9 @@ } } + if(!columnDefinition) + return -2; + // Resolve the original table name for current column if AS was used NSString *tableForColumn = [columnDefinition objectForKey:@"org_table"]; @@ -2649,7 +2652,7 @@ // No table/database name found indicates that the field's column contains data from more than one table as for UNION // or the field data are not bound to any table as in SELECT 1 or if column database is unset - if(!tableForColumn || ![tableForColumn length] || ![dbForColumn length]) + if(!tableForColumn || ![tableForColumn length] || !dbForColumn || ![dbForColumn length]) return -1; // if table and database name are given check if field can be identified unambiguously @@ -3157,10 +3160,12 @@ [tableDocumentInstance startTaskWithDescription:NSLocalizedString(@"Updating field data...", @"updating field task description")]; [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance]; - NSString *fieldIDQueryStringB = [self argumentForRow:rowIndex ofTable:tableForColumn andDatabase:[columnDefinition objectForKey:@"db"]]; + [self storeCurrentDetailsForRestoration]; + + NSString *fieldIDQueryStr = [self argumentForRow:rowIndex ofTable:tableForColumn andDatabase:[columnDefinition objectForKey:@"db"]]; // Check if the IDstring identifies the current field bijectively - NSInteger numberOfPossibleUpdateRows = [[[[mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(1) FROM %@.%@ %@", [[columnDefinition objectForKey:@"db"] backtickQuotedString], [tableForColumn backtickQuotedString], fieldIDQueryStringB]] fetchRowAsArray] objectAtIndex:0] integerValue]; + NSInteger numberOfPossibleUpdateRows = [[[[mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(1) FROM %@.%@ %@", [[columnDefinition objectForKey:@"db"] backtickQuotedString], [tableForColumn backtickQuotedString], fieldIDQueryStr]] fetchRowAsArray] objectAtIndex:0] integerValue]; if(numberOfPossibleUpdateRows == 1) { @@ -3189,7 +3194,7 @@ [mySQLConnection queryString: [NSString stringWithFormat:@"UPDATE %@.%@ SET %@.%@.%@ = %@ %@ LIMIT 1", [[columnDefinition objectForKey:@"db"] backtickQuotedString], [tableForColumn backtickQuotedString], - [[columnDefinition objectForKey:@"db"] backtickQuotedString], [tableForColumn backtickQuotedString], [columnName backtickQuotedString], newObject, fieldIDQueryStringB]]; + [[columnDefinition objectForKey:@"db"] backtickQuotedString], [tableForColumn backtickQuotedString], [columnName backtickQuotedString], newObject, fieldIDQueryStr]]; // Check for errors while UPDATE @@ -3545,6 +3550,8 @@ if (editData) [editData release]; + [tableContentView makeFirstResponder]; + return NO; } @@ -3699,6 +3706,42 @@ #pragma mark - #pragma mark Other methods + +/* + * If user selected a table cell which is a blob field and tried to edit it + * cancel the fieldEditor, display the field editor sheet instead for editing + * and re-enable the fieldEditor after editing. + */ +- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor +{ + + NSString *fieldType; + NSUInteger row, column; + + row = [tableContentView editedRow]; + column = [tableContentView editedColumn]; + + // Check if current edited field is a blob + if ((fieldType = [[tableDataInstance columnWithName:[[NSArrayObjectAtIndex([tableContentView tableColumns], column) headerCell] stringValue]] objectForKey:@"typegrouping"]) + && ([fieldType isEqualToString:@"textdata"] || [fieldType isEqualToString:@"blobdata"])) + { + // Cancel editing + [control abortEditing]; + + // Call the field editor sheet + [self tableView:tableContentView shouldEditTableColumn:NSArrayObjectAtIndex([tableContentView tableColumns], column) row:row]; + + // Reset the field editor + [tableContentView editColumn:column row:row withEvent:nil select:YES]; + + return NO; + + } + + return YES; + +} + /* * Trap the enter, escape, tab and arrow keys, overriding default behaviour and continuing/ending editing, * only within the current row. @@ -3713,19 +3756,16 @@ column = [tableContentView editedColumn]; // Trap tab key + // -- for handling of blob fields look at [self control:textShouldBeginEditing:] if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)] ) { [[control window] makeFirstResponder:control]; if([tablesListInstance tableType] == SPTableTypeView) { - // Check if next column is a blob column or not editable, and skip to the next non-blob column and editable field + // Look for the next editable field if ( column != ( [tableContentView numberOfColumns] - 1 ) ) { i = 1; - while ( - (fieldType = [[tableDataInstance columnWithName:[[NSArrayObjectAtIndex([tableContentView tableColumns], column+i) headerCell] stringValue]] objectForKey:@"typegrouping"]) - && ([fieldType isEqualToString:@"textdata"] || [fieldType isEqualToString:@"blobdata"]) - || [self fieldEditStatusForRow:row andColumn:[NSArrayObjectAtIndex([tableContentView tableColumns], column+i) identifier]] != 1 - ) { + while ([self fieldEditStatusForRow:row andColumn:[NSArrayObjectAtIndex([tableContentView tableColumns], column+i) identifier]] != 1) { i++; // If there are no columns after the latest blob or text column, save the current line. @@ -3738,31 +3778,56 @@ } } else { + // Save the current line if it's the last field in the table if ( column == ( [tableContentView numberOfColumns] - 1 ) ) { [self addRowToDB]; + return YES; } else { + // Select the next field for editing + [tableContentView editColumn:column+1 row:row withEvent:nil select:YES]; + return YES; + } - // Check if next column is a blob column, and skip to the next non-blob column + } + return YES; + } + + // Trap shift-tab key + if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertBacktab:)] ) + { + [[control window] makeFirstResponder:control]; + + if([tablesListInstance tableType] == SPTableTypeView) { + // Look for the next editable field backwards + if ( column > 0 ) { i = 1; - while ( - (fieldType = [[tableDataInstance columnWithName:[[NSArrayObjectAtIndex([tableContentView tableColumns], column+i) headerCell] stringValue]] objectForKey:@"typegrouping"]) - && ([fieldType isEqualToString:@"textdata"] || [fieldType isEqualToString:@"blobdata"]) - ) { + while ([self fieldEditStatusForRow:row andColumn:[NSArrayObjectAtIndex([tableContentView tableColumns], column-i) identifier]] != 1) { i++; - // If there are no columns after the latest blob or text column, save the current line. - if ( (column+i) >= [tableContentView numberOfColumns] ) { - [self addRowToDB]; + // If there are no columns before the latestone, return. + if ( column == i ) { return TRUE; } } - // Edit the column after the blob column - [tableContentView editColumn:column+i row:row withEvent:nil select:YES]; + [tableContentView editColumn:column-i row:row withEvent:nil select:YES]; + } + } else { + + // Save the current line if it's the last field in the table + if ( column < 1 ) { + [self addRowToDB]; + return YES; + } else { + // Select the previous field for editing + [tableContentView editColumn:column-1 row:row withEvent:nil select:YES]; + return YES; + } + } - return TRUE; + return YES; } // Trap enter key @@ -3829,6 +3894,10 @@ [tableContentView reloadData]; } currentlyEditingRow = -1; + + // Preserve the focus + [tableContentView makeFirstResponder]; + return TRUE; } else -- cgit v1.2.3