From 29cc05dc4aeb54e8ffa7ca01b35bdfa6a8497434 Mon Sep 17 00:00:00 2001 From: nico Date: Tue, 29 Aug 2000 18:44:33 +0000 Subject: [PATCH] Implemented object value/formatter support git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@7284 72102866-910b-0410-8b05-ffd578937521 --- Source/NSTableView.m | 79 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 10 deletions(-) diff --git a/Source/NSTableView.m b/Source/NSTableView.m index c2c190a67..8a1bd476b 100644 --- a/Source/NSTableView.m +++ b/Source/NSTableView.m @@ -1087,21 +1087,57 @@ byExtendingSelection: (BOOL)flag } - (void) validateEditing -{ +{ if (_textObject) { - [_editedCell setStringValue: [_textObject text]]; + NSFormatter *formatter; + NSString *string; + id newObjectValue; + BOOL validatedOK = YES; - if (_del_editable) + formatter = [_editedCell formatter]; + string = [_textObject text]; + + if (formatter == nil) { - [_delegate tableView: self - setObjectValue: [_editedCell objectValue] - forTableColumn: [_tableColumns objectAtIndex: - _editedColumn] - row: _editedRow]; + newObjectValue = string; + } + else + { + NSString *error; + + if ([formatter getObjectValue: &newObjectValue + forString: string + errorDescription: &error] == NO) + { + if ([_delegate control: self + didFailToFormatString: string + errorDescription: error] == NO) + { + validatedOK = NO; + } + else + { + newObjectValue = string; + } + } + } + if (validatedOK == YES) + { + [_editedCell setObjectValue: newObjectValue]; + + if (_del_editable) + { + NSTableColumn *tb; + + tb = [_tableColumns objectAtIndex: _editedColumn]; + + [_delegate tableView: self setObjectValue: newObjectValue + forTableColumn: tb row: _editedRow]; + } } } -} +} - (void) editColumn: (int) columnIndex row: (int) rowIndex @@ -1586,8 +1622,13 @@ byExtendingSelection: (BOOL)flag } } } - + // Double-click events + + // FIXME: Start editing only if row is selected + if ([self isRowSelected: _clickedRow] == NO) + return; + if ([_delegate respondsToSelector: @selector(tableView:shouldEditTableColumn:row:)]) { @@ -2411,6 +2452,24 @@ byExtendingSelection: (BOOL)flag return YES; } + if ([_delegate respondsToSelector: + @selector(control:isValidObject:)] == YES) + { + NSFormatter *formatter; + id newObjectValue; + + formatter = [_cell formatter]; + + if ([formatter getObjectValue: &newObjectValue + forString: [_textObject text] + errorDescription: NULL] == YES) + { + if ([_delegate control: self + isValidObject: newObjectValue] == NO) + return NO; + } + } + return [_editedCell isEntryAcceptable: [aTextObject text]]; }