From af062da99d221cd4ffdd96ea7750c25e4990a2dc Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Tue, 30 Jun 2009 20:48:32 +0800 Subject: [PATCH 1/2] Fix for selection being lost when changing the number of segments. Reviewed by tolmasky. Signed-off-by: Francisco Ryan Tolmasky I --- AppKit/CPSegmentedControl.j | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/AppKit/CPSegmentedControl.j b/AppKit/CPSegmentedControl.j index 611dc584c..90bf96be0 100644 --- a/AppKit/CPSegmentedControl.j +++ b/AppKit/CPSegmentedControl.j @@ -119,13 +119,13 @@ CPSegmentSwitchTrackingMomentary = 2; } else if (aCount < _segments.length) { - for (var index = aCount; index < _segments.length; ++index) - _segments[index] = nil; + _segments.length = aCount; + _themeStates.length = aCount; } - - if (_selectedSegment < _segments.length) + + if (_selectedSegment >= _segments.length) _selectedSegment = -1; - + [self tileWithChangedSegment:0]; } From b8046c479f4c6439a1ad6871c33887fedf437fad Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Sat, 4 Jul 2009 06:49:55 -0700 Subject: [PATCH 2/2] Fix for creating outlets and actions that don't exist in interface builder. Reviewed by me. --- AppKit/Cib/_CPCibConnector.j | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/AppKit/Cib/_CPCibConnector.j b/AppKit/Cib/_CPCibConnector.j index 6ddd6ce05..52b3a1a50 100644 --- a/AppKit/Cib/_CPCibConnector.j +++ b/AppKit/Cib/_CPCibConnector.j @@ -60,26 +60,38 @@ var _CPCibConnectorSourceKey = @"_CPCibConnectorSourceKey", - (void)establishConnection { - var selectorName = _label; - - if (![selectorName hasSuffix:@":"]) + var selectorName = _label, + selectorNameLength = [selectorName length]; + + if (selectorNameLength && selectorName[selectorNameLength - 1] !== ':') selectorName += ':'; var selector = CPSelectorFromString(selectorName); + // Not having a selector is a fatal error. if (!selector) [CPException raise:CPInvalidArgumentException reason:@"-[" + [self className] + ' ' + _cmd + @"] selector " + selectorName + @" does not exist."]; + // If the destination doesn't respond to this selector, warn but don't die. + if (_destination && ![_destination respondsToSelector:selector]) + { + CPLog.warn(@"Could not connect the action " + selector + @" to target of class " + [_destination className]); + + return; + } + + // Not being able to set the action is a fatal error. if ([_source respondsToSelector:@selector(setAction:)]) objj_msgSend(_source, @selector(setAction:), selector); - + else [CPException raise:CPInvalidArgumentException reason:@"-[" + [self className] + ' ' + _cmd + @"] " + [_source description] + " does not respond to setAction:"]; + // Not being able to set the target is a fatal error. if ([_source respondsToSelector:@selector(setTarget:)]) objj_msgSend(_source, @selector(setTarget:), _destination); @@ -97,7 +109,18 @@ var _CPCibConnectorSourceKey = @"_CPCibConnectorSourceKey", - (void)establishConnection { - [_source setValue:_destination forKey:_label]; + try + { + [_source setValue:_destination forKey:_label]; + } + catch (anException) + { + if ([anException name] === CPUndefinedKeyException) + CPLog.warn(@"Could not connect the outlet " + _label + @" of target of class " + [_source className]); + + else + throw anException; + } } @end