From 471641c228feb82ceac407ec0e41eaaca664b1a1 Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Mon, 25 Feb 2013 20:09:18 -0500 Subject: [PATCH] Fixed: subviews in cib did not receive view(Will/Did)MoveToSuperview: In Cocoa, viewWillMoveToSuperview: and viewDidMoveToSuperview: are called when views are instantiated from code or from a nib. Previously in Cappuccino, when a view was instantiated from a cib, the _subviews of the view were directly set from the decoded subview array. This short-circuited all of the normal notifications a view receives when added to a superview, including viewWillMoveToSuperview: and viewDidMoveToSuperview:. As a result, some views that override these methods, such as CPSearchField, were not set up correctly when instantiated from a cib. With this commit, subviews instantiated from a cib are manually added to their superview, thus ensuring they go through the same cycle as views instantiated from code, and ensuring that viewWillMoveToSuperview: and viewDidMoveToSuperview: are called. Closes #1699 --- AppKit/CPView.j | 14 +++++++++++++- Foundation/CPArray/_CPArray.j | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/AppKit/CPView.j b/AppKit/CPView.j index cd9c863d0..2fc86c369 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -3045,9 +3045,21 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", _tag = [aCoder containsValueForKey:CPViewTagKey] ? [aCoder decodeIntForKey:CPViewTagKey] : -1; _window = [aCoder decodeObjectForKey:CPViewWindowKey]; - _subviews = [aCoder decodeObjectForKey:CPViewSubviewsKey] || []; _superview = [aCoder decodeObjectForKey:CPViewSuperviewKey]; + // We have to manually add the subviews so that they will receive + // viewWillMoveToSuperview: and viewDidMoveToSuperview: + _subviews = []; + + var subviews = [aCoder decodeObjectForKey:CPViewSubviewsKey] || []; + + for (var i = 0, count = [subviews count]; i < count; ++i) + { + // addSubview won't do anything if the superview is already self, so clear it + subviews[i]._superview = nil; + [self addSubview:subviews[i]]; + } + // FIXME: Should we encode/decode this? _registeredDraggedTypes = [CPSet set]; _registeredDraggedTypesArray = []; diff --git a/Foundation/CPArray/_CPArray.j b/Foundation/CPArray/_CPArray.j index 5154a2400..fc15f5a08 100755 --- a/Foundation/CPArray/_CPArray.j +++ b/Foundation/CPArray/_CPArray.j @@ -623,6 +623,7 @@ var concat = Array.prototype.concat, for (; index < count; ++index) { aFunction([self objectAtIndex:index], index, shouldStopRef); + if (shouldStop) return; } @@ -648,6 +649,7 @@ var concat = Array.prototype.concat, for (; index !== stop; index += increment) { aFunction([self objectAtIndex:index], index, AT_REF(shouldStop)); + if (shouldStop) return; }