From bf49d7b7669fa3f01981ef5893a08c4789fdb6f9 Mon Sep 17 00:00:00 2001 From: Francisco Tolmasky Date: Tue, 19 May 2009 00:41:13 -0700 Subject: [PATCH] Fix for intermittent failures with nib2cib and checkboxes. Reviewed by me. --- Tools/nib2cib/NSButton.j | 63 ++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/Tools/nib2cib/NSButton.j b/Tools/nib2cib/NSButton.j index b3f9e8fd5..d34f40cfb 100644 --- a/Tools/nib2cib/NSButton.j +++ b/Tools/nib2cib/NSButton.j @@ -36,47 +36,10 @@ _CPButtonBezelStyleHeights[CPRoundedBezelStyle] = 18; _CPButtonBezelStyleHeights[CPTexturedRoundedBezelStyle] = 20; _CPButtonBezelStyleHeights[CPHUDBezelStyle] = 20; -@implementation CPRadio (NSCoding) - -- (id)NS_initWithCoder:(CPCoder)aCoder -{ - self = [super NS_initWithCoder:aCoder]; - - if (self) - _radioGroup = [CPRadioGroup new]; - - return self; -} - -@end - @implementation CPButton (NSCoding) - (id)NS_initWithCoder:(CPCoder)aCoder { - if (![self isKindOfClass:[CPRadio class]] && ![self isKindOfClass:[CPCheckBox class]]) - { - // We need to do a bit of magic to determine if this is a checkbox or radio button. - var cell = [aCoder decodeObjectForKey:@"NSCell"], - alternateImage = [cell alternateImage]; - - if ([alternateImage isKindOfClass:[NSButtonImageSource class]]) - { - if ([alternateImage imageName] === @"NSSwitch") - { - CPLog.warn("Detected check box, switching to CPCheckBox"); - - return [[CPCheckBox alloc] NS_initWithCoder:aCoder]; - } - else if ([alternateImage imageName] === @"NSRadioButton") - { - CPLog.warn("Detected radio, switching to CPRadio"); - - return [[CPRadio alloc] NS_initWithCoder:aCoder]; - } - } - } - self = [super NS_initWithCoder:aCoder]; if (self) @@ -87,7 +50,7 @@ _CPButtonBezelStyleHeights[CPHUDBezelStyle] = 20; _title = [cell title]; - if (![self isKindOfClass:[CPCheckBox class]] && ![self isKindOfClass:[CPRadio class]]) + if (![self NS_isCheckBox] && ![self NS_isRadio]) { [self setBordered:[cell isBordered]]; @@ -148,15 +111,39 @@ _CPButtonBezelStyleHeights[CPHUDBezelStyle] = 20; @implementation NSButton : CPButton { + BOOL _isCheckBox @accessors(readonly, getter=NS_isCheckBox); + BOOL _isRadio @accessors(readonly, getter=NS_isRadio); } - (id)initWithCoder:(CPCoder)aCoder { + // We need to do a bit of magic to determine if this is a checkbox or radio button. + var cell = [aCoder decodeObjectForKey:@"NSCell"], + alternateImage = [cell alternateImage]; + + if ([alternateImage isKindOfClass:[NSButtonImageSource class]]) + { + if ([alternateImage imageName] === @"NSSwitch") + _isCheckBox = YES; + + else if ([alternateImage imageName] === @"NSRadioButton") + { + _isRadio = YES; + self._radioGroup = [CPRadioGroup new]; + } + } + return [self NS_initWithCoder:aCoder]; } - (Class)classForKeyedArchiver { + if ([self NS_isCheckBox]) + return [CPCheckBox class]; + + if ([self NS_isRadio]) + return [CPRadio class]; + return [CPButton class]; }