Skip to content

Commit

Permalink
Fixed decode methods to return the correct defaults, removed unnecess…
Browse files Browse the repository at this point in the history
…ary containsValueForKey and || with defaults
  • Loading branch information
aparajita committed Apr 24, 2012
1 parent 44521a3 commit 36bfc7c
Show file tree
Hide file tree
Showing 24 changed files with 80 additions and 76 deletions.
4 changes: 1 addition & 3 deletions AppKit/CPButton.j
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,7 @@ var CPButtonImageKey = @"CPButtonImageKey",

_title = [aCoder decodeObjectForKey:CPButtonTitleKey];
_alternateTitle = [aCoder decodeObjectForKey:CPButtonAlternateTitleKey];

if ([aCoder containsValueForKey:CPButtonAllowsMixedStateKey])
_allowsMixedState = [aCoder decodeBoolForKey:CPButtonAllowsMixedStateKey];
_allowsMixedState = [aCoder decodeBoolForKey:CPButtonAllowsMixedStateKey];

[self setImageDimsWhenDisabled:[aCoder decodeObjectForKey:CPButtonImageDimsWhenDisabledKey]];

Expand Down
8 changes: 4 additions & 4 deletions AppKit/CPCollectionView.j
Original file line number Diff line number Diff line change
Expand Up @@ -1001,11 +1001,11 @@ var CPCollectionViewMinItemSizeKey = @"CPCollectionViewMinItemSizeK

_itemSize = CGSizeMakeZero();

_minItemSize = [aCoder decodeSizeForKey:CPCollectionViewMinItemSizeKey] || CGSizeMakeZero();
_maxItemSize = [aCoder decodeSizeForKey:CPCollectionViewMaxItemSizeKey] || CGSizeMakeZero();
_minItemSize = [aCoder decodeSizeForKey:CPCollectionViewMinItemSizeKey];
_maxItemSize = [aCoder decodeSizeForKey:CPCollectionViewMaxItemSizeKey];

_maxNumberOfRows = [aCoder decodeIntForKey:CPCollectionViewMaxNumberOfRowsKey] || 0;
_maxNumberOfColumns = [aCoder decodeIntForKey:CPCollectionViewMaxNumberOfColumnsKey] || 0;
_maxNumberOfRows = [aCoder decodeIntForKey:CPCollectionViewMaxNumberOfRowsKey];
_maxNumberOfColumns = [aCoder decodeIntForKey:CPCollectionViewMaxNumberOfColumnsKey];

_verticalMargin = [aCoder decodeFloatForKey:CPCollectionViewVerticalMarginKey];

Expand Down
2 changes: 1 addition & 1 deletion AppKit/CPImageView.j
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ var CPImageViewImageKey = @"CPImageViewImageKey",
[self setHasShadow:[aCoder decodeBoolForKey:CPImageViewHasShadowKey]];
[self setImageAlignment:[aCoder decodeIntForKey:CPImageViewImageAlignmentKey]];

if ([aCoder decodeBoolForKey:CPImageViewIsEditableKey] || NO)
if ([aCoder decodeBoolForKey:CPImageViewIsEditableKey])
[self setEditable:YES];

[self setNeedsLayout];
Expand Down
23 changes: 11 additions & 12 deletions AppKit/CPMenuItem/CPMenuItem.j
Original file line number Diff line number Diff line change
Expand Up @@ -932,34 +932,33 @@ var CPMenuItemIsSeparatorKey = @"CPMenuItemIsSeparatorKey",
_action = [aCoder decodeObjectForKey:CPMenuItemActionKey];

_isEnabled = DEFAULT_VALUE(CPMenuItemIsEnabledKey, YES);
_isHidden = DEFAULT_VALUE(CPMenuItemIsHiddenKey, NO);
_tag = DEFAULT_VALUE(CPMenuItemTagKey, 0);
_state = DEFAULT_VALUE(CPMenuItemStateKey, CPOffState);
_isHidden = [aCoder decodeBoolForKey:CPMenuItemIsHiddenKey];
_tag = [aCoder decodeIntForKey:CPMenuItemTagKey];
_state = [aCoder decodeIntForKey:CPMenuItemStateKey];

_image = DEFAULT_VALUE(CPMenuItemImageKey, nil);
_alternateImage = DEFAULT_VALUE(CPMenuItemAlternateImageKey, nil);
_image = [aCoder decodeObjectForKey:CPMenuItemImageKey];
_alternateImage = [aCoder decodeObjectForKey:CPMenuItemAlternateImageKey];
// CPImage _onStateImage;
// CPImage _offStateImage;
// CPImage _mixedStateImage;

// This order matters because setSubmenu: needs _menu to be around.
_menu = DEFAULT_VALUE(CPMenuItemMenuKey, nil);
[self setSubmenu:DEFAULT_VALUE(CPMenuItemSubmenuKey, nil)];
_menu = [aCoder decodeObjectForKey:CPMenuItemMenuKey];
[self setSubmenu:[aCoder decodeObjectForKey:CPMenuItemSubmenuKey]];

_keyEquivalent = [aCoder decodeObjectForKey:CPMenuItemKeyEquivalentKey] || @"";
_keyEquivalentModifierMask = [aCoder decodeObjectForKey:CPMenuItemKeyEquivalentModifierMaskKey] || 0;
_keyEquivalentModifierMask = [aCoder decodeIntForKey:CPMenuItemKeyEquivalentModifierMaskKey];

// int _mnemonicLocation;

// BOOL _isAlternate;

// Default is 0.
[self setIndentationLevel:[aCoder decodeIntForKey:CPMenuItemIndentationLevelKey] || 0];
[self setIndentationLevel:[aCoder decodeIntForKey:CPMenuItemIndentationLevelKey]];

// CPString _toolTip;

_representedObject = DEFAULT_VALUE(CPMenuItemRepresentedObjectKey, nil);
_view = DEFAULT_VALUE(CPMenuItemViewKey, nil);
_representedObject = [aCoder decodeObjectForKey:CPMenuItemRepresentedObjectKey];
_view = [aCoder decodeObjectForKey:CPMenuItemViewKey];
}

return self;
Expand Down
2 changes: 1 addition & 1 deletion AppKit/CPObjectController.j
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ var CPObjectControllerContentKey = @"CPObjectControllerCo

[self setObjectClass:objectClass || [CPMutableDictionary class]];
[self setEditable:[aCoder decodeBoolForKey:CPObjectControllerIsEditableKey]];
[self setAutomaticallyPreparesContent:[aCoder decodeBoolForKey:CPObjectControllerAutomaticallyPreparesContentKey] || NO];
[self setAutomaticallyPreparesContent:[aCoder decodeBoolForKey:CPObjectControllerAutomaticallyPreparesContentKey]];
[self setContent:[aCoder decodeObjectForKey:CPObjectControllerContentKey]];

_observedKeys = [[CPCountedSet alloc] init];
Expand Down
9 changes: 6 additions & 3 deletions AppKit/CPRuleEditor/CPPredicateEditor.j
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,13 @@
if (rowType == CPRuleEditorRowTypeCompound)
{
var subrows = [rowItem valueForKey:_subrowsArrayKeyPath],
count = [subrows count];
count = [subrows count];

for (var i = 0; i < count; i++)
{
var subrow = [subrows objectAtIndex:i];
var predicate = [self _predicateFromRowItem:subrow];
var subrow = [subrows objectAtIndex:i],
predicate = [self _predicateFromRowItem:subrow];

[subpredicates addObject:predicate];
}
}
Expand Down Expand Up @@ -484,9 +485,11 @@ var CPPredicateTemplatesKey = @"CPPredicateTemplates";
- (id)initWithCoder:(id)aCoder
{
self = [super initWithCoder:aCoder];

if (self != nil)
{
var nibTemplates = [aCoder decodeObjectForKey:CPPredicateTemplatesKey];

if (nibTemplates != nil)
[self setRowTemplates:nibTemplates];
}
Expand Down
4 changes: 2 additions & 2 deletions AppKit/CPScrollView.j
Original file line number Diff line number Diff line change
Expand Up @@ -1506,8 +1506,8 @@ var CPScrollViewContentViewKey = @"CPScrollViewContentView",
_scrollTimer = nil;
_implementedDelegateMethods = 0;

_scrollerStyle = [aCoder decodeIntForKey:CPScrollViewScrollerStyleKey] || CPScrollerStyleGlobal;
_scrollerKnobStyle = [aCoder decodeIntForKey:CPScrollViewScrollerKnobStyleKey] || CPScrollerKnobStyleDefault;
_scrollerStyle = [aCoder decodeObjectForKey:CPScrollViewScrollerStyleKey] || CPScrollerStyleGlobal;
_scrollerKnobStyle = [aCoder decodeObjectForKey:CPScrollViewScrollerKnobStyleKey] || CPScrollerKnobStyleDefault;

[[CPNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didReceiveDefaultStyleChange:)
Expand Down
8 changes: 4 additions & 4 deletions AppKit/CPStepper.j
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,10 @@ var CPStepperMinValue = @"CPStepperMinValue",
if (self = [super initWithCoder:aCoder])
{
_increment = [aCoder decodeIntForKey:CPStepperIncrement];
_minValue = [aCoder decodeIntForKey:CPStepperMinValue] || 0;
_maxValue = [aCoder decodeIntForKey:CPStepperMaxValue] || 0;
_valueWraps = [aCoder decodeBoolForKey:CPStepperValueWraps] || NO;
_autorepeat = [aCoder decodeBoolForKey:CPStepperAutorepeat] || NO;
_minValue = [aCoder decodeIntForKey:CPStepperMinValue];
_maxValue = [aCoder decodeIntForKey:CPStepperMaxValue];
_valueWraps = [aCoder decodeBoolForKey:CPStepperValueWraps];
_autorepeat = [aCoder decodeBoolForKey:CPStepperAutorepeat];

[self _init];
}
Expand Down
11 changes: 5 additions & 6 deletions AppKit/CPTableView.j
Original file line number Diff line number Diff line change
Expand Up @@ -4782,15 +4782,14 @@ var CPTableViewDataSourceKey = @"CPTableViewDataSourceKey",
_tableColumns = [aCoder decodeObjectForKey:CPTableViewTableColumnsKey] || [];
[_tableColumns makeObjectsPerformSelector:@selector(setTableView:) withObject:self];

if ([aCoder containsValueForKey:CPTableViewRowHeightKey])
_rowHeight = [aCoder decodeFloatForKey:CPTableViewRowHeightKey];
else
_rowHeight = 23.0;
_rowHeight = [aCoder decodeFloatForKey:CPTableViewRowHeightKey] || 23.0;
_intercellSpacing = [aCoder decodeSizeForKey:CPTableViewIntercellSpacingKey];

_intercellSpacing = [aCoder decodeSizeForKey:CPTableViewIntercellSpacingKey] || _CGSizeMake(3.0, 2.0);
if (_CGSizeEqualToSize(_intercellSpacing, _CGSizeMakeZero()))
_intercellSpacing = _CGSizeMake(3.0, 2.0);

[self setGridColor:[aCoder decodeObjectForKey:CPTableViewGridColorKey]];
_gridStyleMask = [aCoder decodeIntForKey:CPTableViewGridStyleMaskKey] || CPTableViewGridNone;
_gridStyleMask = [aCoder decodeIntForKey:CPTableViewGridStyleMaskKey];

_usesAlternatingRowBackgroundColors = [aCoder decodeObjectForKey:CPTableViewUsesAlternatingBackgroundKey];
[self setAlternatingRowBackgroundColors:[aCoder decodeObjectForKey:CPTableViewAlternatingRowColorsKey]];
Expand Down
8 changes: 2 additions & 6 deletions AppKit/CPView.j
Original file line number Diff line number Diff line change
Expand Up @@ -2761,7 +2761,7 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",

_autoresizesSubviews = ![aCoder containsValueForKey:CPViewAutoresizesSubviewsKey] || [aCoder decodeBoolForKey:CPViewAutoresizesSubviewsKey];

_hitTests = ![aCoder containsValueForKey:CPViewHitTestsKey] || [aCoder decodeObjectForKey:CPViewHitTestsKey];
_hitTests = ![aCoder containsValueForKey:CPViewHitTestsKey] || [aCoder decodeBoolForKey:CPViewHitTestsKey];

// DOM SETUP
#if PLATFORM(DOM)
Expand All @@ -2781,18 +2781,14 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
}
#endif

if ([aCoder containsValueForKey:CPViewIsHiddenKey])
[self setHidden:[aCoder decodeBoolForKey:CPViewIsHiddenKey]];
else
_isHidden = NO;
[self setHidden:[aCoder decodeBoolForKey:CPViewIsHiddenKey]];

if ([aCoder containsValueForKey:CPViewOpacityKey])
[self setAlphaValue:[aCoder decodeIntForKey:CPViewOpacityKey]];
else
_opacity = 1.0;

[self setBackgroundColor:[aCoder decodeObjectForKey:CPViewBackgroundColorKey]];

[self setupViewFlags];

_theme = [CPTheme defaultTheme];
Expand Down
4 changes: 2 additions & 2 deletions AppKit/Cib/_CPCibWindowTemplate.j
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ var _CPCibWindowTemplateMinSizeKey = @"_CPCibWindowTemp
_windowTitle = [aCoder decodeObjectForKey:_CPCibWindowTemplateWindowTitleKey];
_windowView = [aCoder decodeObjectForKey:_CPCibWindowTemplateWindowViewKey];

_windowAutorecalculatesKeyViewLoop = !![aCoder decodeObjectForKey:_CPCibWindowTemplateWindowAutorecalculatesKeyViewLoop];
_windowIsFullPlatformWindow = !![aCoder decodeObjectForKey:_CPCibWindowTemplateWindowIsFullPlatformWindowKey];
_windowAutorecalculatesKeyViewLoop = [aCoder decodeBoolForKey:_CPCibWindowTemplateWindowAutorecalculatesKeyViewLoop];
_windowIsFullPlatformWindow = [aCoder decodeBoolForKey:_CPCibWindowTemplateWindowIsFullPlatformWindowKey];
}

return self;
Expand Down
25 changes: 16 additions & 9 deletions Foundation/CPKeyedUnarchiver.j
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ var CPArrayClass = Ni
*/
- (float)decodeFloatForKey:(CPString)aKey
{
return [self decodeObjectForKey:aKey];
var f = [self decodeObjectForKey:aKey];

return f === nil ? 0.0 : f;
}

/*
Expand All @@ -261,7 +263,9 @@ var CPArrayClass = Ni
*/
- (double)decodeDoubleForKey:(CPString)aKey
{
return [self decodeObjectForKey:aKey];
var d = [self decodeObjectForKey:aKey];

return d === nil ? 0.0 : d;
}

/*
Expand All @@ -271,7 +275,9 @@ var CPArrayClass = Ni
*/
- (int)decodeIntForKey:(CPString)aKey
{
return [self decodeObjectForKey:aKey];
var i = [self decodeObjectForKey:aKey];

return i === nil ? 0 : i;
}

/*
Expand All @@ -284,9 +290,9 @@ var CPArrayClass = Ni
var object = [self decodeObjectForKey:aKey];

if (object)
return CPPointFromString(object);
return CGPointFromString(object);
else
return CPPointMake(0.0, 0.0);
return CGPointMakeZero();
}

/*
Expand All @@ -299,9 +305,9 @@ var CPArrayClass = Ni
var object = [self decodeObjectForKey:aKey];

if (object)
return CPRectFromString(object);
return CGRectFromString(object);
else
return CPRectMakeZero();
return CGRectMakeZero();
}

/*
Expand All @@ -314,9 +320,9 @@ var CPArrayClass = Ni
var object = [self decodeObjectForKey:aKey];

if (object)
return CPSizeFromString(object);
return CGSizeFromString(object);

This comment has been minimized.

Copy link
@BlairDuncan

BlairDuncan May 22, 2012

Contributor

Regarding the discussion here:
https://groups.google.com/forum/?fromgroups#!topic/objectivej/adBjkDFwHMg

Not sure why... but this seems to be the culprit. At least it is for me.
When I put it back to return CPSizeFromString(object); nibs work fine again with nib2cib.

This comment has been minimized.

Copy link
@aparajita

aparajita May 22, 2012

Author Contributor

God bless you for tracking this down! It turns out there are bugs in the CGFromString functions. In CGGeometry.j, replace all "parseInt" with "parseFloat" and try again, leaving this line as CGSizeFromString(object).

This comment has been minimized.

Copy link
@BlairDuncan

BlairDuncan May 22, 2012

Contributor

Yes, that works.

else
return CPSizeMake(0.0, 0.0);
return CGSizeMakeZero();
}

/*
Expand Down Expand Up @@ -366,6 +372,7 @@ var CPArrayClass = Ni
return nil;

var objectClass = data.isa;

if (objectClass === CPDataClass)
return data.bytes();

Expand Down
3 changes: 2 additions & 1 deletion Tools/nib2cib/NSBox.j
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
_borderColor = [aCoder decodeObjectForKey:@"NSBorderColor2"] || [CPColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.42];
_fillColor = [aCoder decodeObjectForKey:@"NSFillColor2"] || [CPColor clearColor];

_cornerRadius = [aCoder decodeFloatForKey:@"NSCornerRadius2"] || 0.0;
_cornerRadius = [aCoder decodeFloatForKey:@"NSCornerRadius2"];
_borderWidth = [aCoder decodeFloatForKey:@"NSBorderWidth2"] || 1.0;

_contentMargin = [aCoder decodeSizeForKey:@"NSOffsets"];

_title = [[aCoder decodeObjectForKey:@"NSTitleCell"] objectValue] || @"";
_titlePosition = [aCoder decodeObjectForKey:@"NSTitlePosition"];

if (_titlePosition === undefined)
_titlePosition = CPAtTop;
}
Expand Down
10 changes: 5 additions & 5 deletions Tools/nib2cib/NSLevelIndicator.j
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@
{
_objectValue = [aCoder decodeDoubleForKey:@"NSValue"];

_minValue = [aCoder decodeDoubleForKey:@"NSMinValue"] || 0;
_minValue = [aCoder decodeDoubleForKey:@"NSMinValue"];
_maxValue = [aCoder decodeDoubleForKey:@"NSMaxValue"];
_warningValue = [aCoder decodeDoubleForKey:@"NSWarningValue"];
_criticalValue = [aCoder decodeDoubleForKey:@"NSCriticalValue"];

_levelIndicatorStyle = [aCoder decodeIntForKey:@"NSIndicatorStyle"] || 0;
_levelIndicatorStyle = [aCoder decodeIntForKey:@"NSIndicatorStyle"];

// None of these are included in the XIB if the defaults are used.
_tickMarkPosition = [aCoder decodeIntForKey:@"NSTickMarkPosition"] || 0;
_numberOfTickMarks = [aCoder decodeIntForKey:@"NSNumberOfTickMarks"] || 0;
_numberOfTickMarks = [aCoder decodeIntForKey:@"NSNumberOfMajorTickMarks"] || 0;
_tickMarkPosition = [aCoder decodeIntForKey:@"NSTickMarkPosition"];
_numberOfTickMarks = [aCoder decodeIntForKey:@"NSNumberOfTickMarks"];
_numberOfTickMarks = [aCoder decodeIntForKey:@"NSNumberOfMajorTickMarks"];
}

return self;
Expand Down
4 changes: 2 additions & 2 deletions Tools/nib2cib/NSMenuItem.j
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

if (self)
{
_isSeparator = [aCoder decodeObjectForKey:@"NSIsSeparator"] || NO;
_isSeparator = [aCoder decodeBoolForKey:@"NSIsSeparator"];

_title = [aCoder decodeObjectForKey:"NSTitle"];

Expand Down Expand Up @@ -109,4 +109,4 @@
{
}

@end
@end
2 changes: 1 addition & 1 deletion Tools/nib2cib/NSProgressIndicator.j
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var NSProgressIndicatorSpinningFlag = 1 << 12;
{
var NS_flags = [aCoder decodeIntForKey:@"NSpiFlags"];

_minValue = [aCoder decodeDoubleForKey:@"NSMinValue"] || 0;
_minValue = [aCoder decodeDoubleForKey:@"NSMinValue"];
_maxValue = [aCoder decodeDoubleForKey:@"NSMaxValue"];

_style = (NS_flags & NSProgressIndicatorSpinningFlag) ? CPProgressIndicatorSpinningStyle : CPProgressIndicatorBarStyle;
Expand Down
4 changes: 2 additions & 2 deletions Tools/nib2cib/NSSearchField.j
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@
{
_recentsAutosaveName = [aCoder decodeObjectForKey:@"NSRecentsAutosaveName"];
_maximumRecents = [aCoder decodeIntForKey:@"NSMaximumRecents"];
_sendsWholeSearchString = [aCoder decodeBoolForKey:@"NSSendsWholeSearchString"] ? YES : NO;
_sendsWholeSearchString = [aCoder decodeBoolForKey:@"NSSendsWholeSearchString"];

// These bytes don't seem to be used for anything else but the send immediately flag
_sendsSearchStringImmediately = [aCoder decodeBytesForKey:@"NSSearchFieldFlags"] ? YES: NO;
_sendsSearchStringImmediately = [aCoder decodeBytesForKey:@"NSSearchFieldFlags"] ? YES : NO;
}

return self;
Expand Down
8 changes: 6 additions & 2 deletions Tools/nib2cib/NSSegmentedControl.j
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@
if (self = [super initWithCoder:aCoder])
{
_segments = [aCoder decodeObjectForKey:"NSSegmentImages"];
_selectedSegment = [aCoder decodeIntForKey:"NSSelectedSegment"] || -1;
_selectedSegment = [aCoder decodeObjectForKey:"NSSelectedSegment"];

if (_selectedSegment === nil)
_selectedSegment = -1;

_segmentStyle = [aCoder decodeIntForKey:"NSSegmentStyle"];
_trackingMode = [aCoder decodeIntForKey:"NSTrackingMode"] || CPSegmentSwitchTrackingSelectOne;
_trackingMode = [aCoder decodeIntForKey:"NSTrackingMode"];

if (_trackingMode == CPSegmentSwitchTrackingSelectOne && _selectedSegment == -1)
_selectedSegment = 0;
Expand Down
2 changes: 1 addition & 1 deletion Tools/nib2cib/NSSlider.j
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
_altIncrementValue = [aCoder decodeDoubleForKey:@"NSAltIncValue"];
_isVertical = [aCoder decodeBoolForKey:@"NSVertical"];

_sliderType = [aCoder decodeIntForKey:@"NSSliderType"] || 0;
_sliderType = [aCoder decodeIntForKey:@"NSSliderType"];
}

return self;
Expand Down
2 changes: 1 addition & 1 deletion Tools/nib2cib/NSSplitView.j
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
if (self = [super NS_initWithCoder:aCoder])
{
_isVertical = [aCoder decodeBoolForKey:@"NSIsVertical"];
_isPaneSplitter = [aCoder decodeIntForKey:@"NSDividerStyle"] == 3 ? YES : NO;
_isPaneSplitter = [aCoder decodeIntForKey:@"NSDividerStyle"] == 3;

_autosaveName = [aCoder decodeObjectForKey:@"NSAutosaveName"];
}
Expand Down

0 comments on commit 36bfc7c

Please sign in to comment.