Ignore:
Timestamp:
Nov 29, 2009, 2:17:11 AM (12 years ago)
Author:
livings124
Message:

add a bit more safety to the message log code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/MessageWindowController.m

    r9620 r9623  
    122122            [fLevelButton selectItemAtIndex: LEVEL_DEBUG];
    123123            break;
     124        default: //safety
     125            [[NSUserDefaults standardUserDefaults] setInteger: TR_MSG_ERR forKey: @"MessageLevel"];
     126            [fLevelButton selectItemAtIndex: LEVEL_ERROR];
    124127    }
    125128   
     
    192195        [fMessageTable reloadData];
    193196        if (shouldScroll)
    194             [fMessageTable scrollRowToVisible: [fDisplayedMessages count]-1];
     197            [fMessageTable scrollRowToVisible: [fMessageTable numberOfRows]-1];
    195198    }
    196199   
     
    242245        fAttributes = [[[[column dataCell] attributedStringValue] attributesAtIndex: 0 effectiveRange: NULL] retain];
    243246   
    244     const CGFloat count = floorf([[[fDisplayedMessages objectAtIndex: row] objectForKey: @"Message"] sizeWithAttributes: fAttributes].width
    245                                 / [column width]);
     247    NSString * message = [[fDisplayedMessages objectAtIndex: row] objectForKey: @"Message"];
     248    const CGFloat count = floorf([message sizeWithAttributes: fAttributes].width / [column width]);
    246249    return [tableView rowHeight] * (count + 1.0);
    247250}
     
    307310            level = TR_MSG_DBG;
    308311            break;
     312        default:
     313            NSAssert1(NO, @"Unknown message log level: %d", [fLevelButton indexOfSelectedItem]);
    309314    }
    310315   
     
    329334   
    330335    [fMessageTable reloadData];
    331     [fMessageTable deselectAll: self];
    332336   
    333337    if ([fDisplayedMessages count] > 0)
    334         [fMessageTable scrollRowToVisible: [fDisplayedMessages count]-1];
     338    {
     339        [fMessageTable deselectAll: self];
     340        [fMessageTable scrollRowToVisible: [fMessageTable numberOfRows]-1];
     341    }
    335342   
    336343    [fLock unlock];
     
    402409- (NSString *) stringForMessage: (NSDictionary *) message
    403410{
    404     NSString * level;
    405     switch ([[message objectForKey: @"Level"] integerValue])
     411    NSString * levelString;
     412    const NSInteger level = [[message objectForKey: @"Level"] integerValue];
     413    switch (level)
    406414    {
    407415        case TR_MSG_ERR:
    408             level = NSLocalizedString(@"Error", "Message window -> level");
     416            levelString = NSLocalizedString(@"Error", "Message window -> level");
    409417            break;
    410418        case TR_MSG_INF:
    411             level = NSLocalizedString(@"Info", "Message window -> level");
     419            levelString = NSLocalizedString(@"Info", "Message window -> level");
    412420            break;
    413421        case TR_MSG_DBG:
    414             level = NSLocalizedString(@"Debug", "Message window -> level");
     422            levelString = NSLocalizedString(@"Debug", "Message window -> level");
    415423            break;
    416424        default:
    417             level = @"";
     425            NSAssert1(NO, @"Unknown message log level: %d", level);
    418426    }
    419427   
    420428    return [NSString stringWithFormat: @"%@ %@ [%@] %@: %@", [message objectForKey: @"Date"],
    421             [message objectForKey: @"File"], level,
     429            [message objectForKey: @"File"], levelString,
    422430            [message objectForKey: @"Name"], [message objectForKey: @"Message"], nil];
    423431}
Note: See TracChangeset for help on using the changeset viewer.