From f805b6bfa69ece0337f936ec9fe1daa31291514d Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Sun, 24 Feb 2013 23:08:44 +0000 Subject: [PATCH] Fixes #1409. Improve CPTabView decoding to fix tab selection errors. This is an improved fix to the corrupted tab view state bug partially addressed by 0f347be. Without either fix, NSTabView is converted to a CPTabView where tab view item views are subviews of the NSTabView, while in Cappuccino the selected view item is supposed to be a subview of a CPBox. Without this fix, CPTabView decoding called addSubview: in initWithCoder: which can cause the superview of a view to become set, only to later be overwritten when the superview ivar is decoded. This fix removes the tab item view as a subview from the tab view before encoding it in nib2cib, and then makes sure not to call addSubview: while still in the initWithCoder stage, but rather later in awakeFromCib. --- AppKit/CPTabView.j | 27 +++++++++++++-------------- Tools/nib2cib/NSTabViewItem.j | 6 ++++++ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/AppKit/CPTabView.j b/AppKit/CPTabView.j index 7d9d943fe..c1959e439 100644 --- a/AppKit/CPTabView.j +++ b/AppKit/CPTabView.j @@ -508,13 +508,8 @@ var CPTabViewItemsKey = "CPTabViewItemsKey", [self setDelegate:[aCoder decodeObjectForKey:CPTabViewDelegateKey]]; - var selected = [aCoder decodeObjectForKey:CPTabViewSelectedItemKey]; - if (selected) - [self selectTabViewItem:selected]; - - [self setTabViewType:[aCoder decodeIntForKey:CPTabViewTypeKey]]; - - [self setNeedsLayout]; + self.selectOnAwake = [aCoder decodeObjectForKey:CPTabViewSelectedItemKey]; + _type = [aCoder decodeIntForKey:CPTabViewTypeKey]; } return self; @@ -522,13 +517,17 @@ var CPTabViewItemsKey = "CPTabViewItemsKey", - (void)awakeFromCib { - // This is a quick and dirty fix of the tab view item we decode and install in _box - // having a different _superview decoded later in the decoding process - e.g. the - // CPTabView itself as is the case when we're coming from an xib. This solution could - // probably be improved by fixing this in nib2cib instead, but the _box doesn't yet - // exist then so it's not totally clear what to change the superview to at that stage. - if ([_box contentView]) - _box._contentView._superview = _box; + if (self.selectOnAwake) + { + [self selectTabViewItem:self.selectOnAwake]; + delete self.selectOnAwake; + } + + var type = _type; + _type = nil; + [self setTabViewType:type]; + + [self setNeedsLayout]; } - (void)encodeWithCoder:(CPCoder)aCoder diff --git a/Tools/nib2cib/NSTabViewItem.j b/Tools/nib2cib/NSTabViewItem.j index 5962968f0..07a34237c 100644 --- a/Tools/nib2cib/NSTabViewItem.j +++ b/Tools/nib2cib/NSTabViewItem.j @@ -41,6 +41,12 @@ return self; } +- (void)awakeFromNib +{ + if ([_view superview]) + [_view removeFromSuperview]; +} + @end @implementation NSTabViewItem : CPTabViewItem