discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView fix


From: Andreas Höschler
Subject: Re: NSTableView fix
Date: Thu, 30 Aug 2007 10:10:38 +0200

Hi all,

please ignore my NSTableView and NSControl fix for now. They don't play nice together. The NSControl fix causes entering decimal numbers in NSTableView cells to do not work any longer. I need to have another look into that.

On MacOSX we can indeed access validated values (-> NSNumber) in controlTextDidChange. However, I see that this raises a bunch of problems with NSCalendarDate and other formatters. I (of course) don't know how Apple has solved this problem, just that they did.

Regards,

  Andreas



On Aug 29, 2007, at 6:00 PM, Andreas Höschler wrote:

NSTableView
Check whether delegate responds to control:didFailToFormatString:errorDescription: before sending message and a bunch of other important fixes.

- (void)validateEditing
{
  if (_textObject)
    {
      NSFormatter *formatter;
      NSString *string;
      id newObjectValue = nil; // <----
      BOOL validatedOK = YES;

      formatter = [_editedCell formatter];
      string = AUTORELEASE ([[_textObject text] copy]);

      if (formatter == nil)
        {
          newObjectValue = string;
        }
      else
        {
          NSString *error;
        
          if ([formatter getObjectValue:&newObjectValue
                         forString:string
                         errorDescription: &error] == NO)
            {
SEL sel = @selector(control:didFailToFormatString:errorDescription:); // <----- if ([_delegate respondsToSelector:sel] && [_delegate control:self didFailToFormatString:string errorDescription:error] == NO) // <----
               {
                validatedOK = NO;
               }
             else
               {
// newObjectValue = string; // <---- bad idea; newObjectValue is expected to be a NSNumber, NSCalendarDate,...
               }
if ([string length] > 0 && newObjectValue == nil) validatedOK = NO; // <----
            }
        }
      if (validatedOK == YES)
        {
          [_editedCell setObjectValue: newObjectValue];
        
          if (_dataSource_editable)
            {
              NSTableColumn *tb;
        
              tb = [_tableColumns objectAtIndex: _editedColumn];
        
              [self _setObjectValue: newObjectValue
                    forTableColumn: tb
                    row: _editedRow];

              //[_dataSource tableView: self  setObjectValue: newObjectValue
              //         forTableColumn: tb  row: _editedRow];
            }
        }
    }
}

I'm no expert in this area, but how about the alternative below? The following functional differences are intentional; any others may be unintentional:

1. Doesn't assume newObjectValue is valid after getObjectValue:forString:errorDescription: returns NO.

2. Doesn't override delegate's decision in control:didFailToFormatString:errorDescription: when [string length] > 0.

3. Doesn't use [string length] == 0 as indicator of empty string (http://lists.apple.com/archives/cocoa-dev/2004/Jul/msg00166.html).

4. Doesn't use comparisons to Boolean constants (http://c-faq.com/bool/bool2.html).

-Tim


- (void)validateEditing
{
  if (_textObject)
    {
      NSFormatter *formatter = [_editedCell formatter];
      NSString *string = AUTORELEASE ([[_textObject text] copy]);
      id newObjectValue = string;
      BOOL validatedOK = YES;

      if (formatter != nil)
        {
          NSString *error;

          validatedOK = [formatter getObjectValue:&newObjectValue
                                        forString:string
                                 errorDescription:&error];

          if (!validatedOK)
            {
              newObjectValue = nil;

if ([_delegate respondsToSelector:@selector(control:didFailToFormatString:errorDescrip tion:)])
                {
validatedOK = [_delegate control:self didFailToFormatString:string errorDescription:error];
                }
              else if ([string isEqualToString:@""])
                {
                  validatedOK = YES;
                }
            }
        }

      if (validatedOK)
        {
          [_editedCell setObjectValue: newObjectValue];
        
          if (_dataSource_editable)
            {
              NSTableColumn *tb;
        
              tb = [_tableColumns objectAtIndex: _editedColumn];
        
              [self _setObjectValue: newObjectValue
                    forTableColumn: tb
                    row: _editedRow];
            }
        }
    }
}





_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnustep





reply via email to

[Prev in Thread] Current Thread [Next in Thread]