From a93c10b794f3cc446abd119196067e1c9c4bcf28 Mon Sep 17 00:00:00 2001 From: Mathieu Monney Date: Mon, 26 Oct 2015 15:37:02 +0100 Subject: [PATCH 1/3] Fixed: default selection of a CPTabView The selected tab item view is now loaded correctly after awakeFromCib, which wasn't the case before. --- AppKit/CPTabView.j | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/AppKit/CPTabView.j b/AppKit/CPTabView.j index 12899624b..822619650 100644 --- a/AppKit/CPTabView.j +++ b/AppKit/CPTabView.j @@ -789,7 +789,13 @@ var CPTabViewItemsKey = "CPTabViewItemsKey", var idx = [self indexOfTabViewItem:_selectedTabViewItem]; if (idx !== CPNotFound) + { + // Temporarily set the selected item to not selected. + // It allows the initial selection to be made correctly. + _selectedTabViewItem = nil; + [self selectTabViewItemAtIndex:idx]; + } } var type = _type; From 08aa591c65cf02775c83bf71e89d429b665bc5be Mon Sep 17 00:00:00 2001 From: cacaodev Date: Wed, 23 Dec 2015 13:15:41 +0100 Subject: [PATCH 2/3] NEW CPArray -arrayByApplyingBlock:(Function/*element, index*/)aBlock Test for CPArray -arrayByApplyingBlock: --- Foundation/CPArray/_CPArray.j | 15 +++++++++++++++ Foundation/CPArray/_CPJavaScriptArray.j | 14 +++++++++++++- Tests/Foundation/CPArrayTest.j | 17 +++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Foundation/CPArray/_CPArray.j b/Foundation/CPArray/_CPArray.j index 5ba2124ba..35ba86d76 100755 --- a/Foundation/CPArray/_CPArray.j +++ b/Foundation/CPArray/_CPArray.j @@ -880,6 +880,21 @@ Returns a hash for the object. Unlike Cocoa, the hash value does not take conten return join.call([self _javaScriptArrayCopy], aString); } +/* @ignore */ +- (CPArray)arrayByApplyingBlock:(Function/*element, index*/)aFunction +{ + var result = [], + count = [self count]; + + for (var idx = 0; idx < count; idx++) + { + var obj = aFunction([self objectAtIndex:idx], idx); + [result addObject:obj]; + } + + return result; +} + // Creating a description of the array /*! diff --git a/Foundation/CPArray/_CPJavaScriptArray.j b/Foundation/CPArray/_CPJavaScriptArray.j index d0ed91782..6d36a8586 100644 --- a/Foundation/CPArray/_CPJavaScriptArray.j +++ b/Foundation/CPArray/_CPJavaScriptArray.j @@ -233,6 +233,19 @@ var concat = Array.prototype.concat, return join.call(self, aString); } +- (CPArray)arrayByApplyingBlock:(Function/*element, index*/)aFunction +{ + var result = []; + + for (var idx = 0; idx < self.length; idx++) + { + var obj = aFunction(self[idx], idx); + result.push(obj); + } + + return result; +} + - (void)insertObject:(id)anObject atIndex:(CPUInteger)anIndex { if (anIndex > self.length || anIndex < 0) @@ -335,7 +348,6 @@ var concat = Array.prototype.concat, [super addObjectsFromArray:anArray]; } - - (id)copy { return slice.call(self, 0); diff --git a/Tests/Foundation/CPArrayTest.j b/Tests/Foundation/CPArrayTest.j index 3b113fe00..828b70efe 100644 --- a/Tests/Foundation/CPArrayTest.j +++ b/Tests/Foundation/CPArrayTest.j @@ -705,6 +705,23 @@ [self assert:[1, [CPNull null], "3"] equals:anArray]; } +- (void)testArrayByApplyingBlock +{ + var arr = @[@"a", @"b", @"c", @"d"]; + + var mapped = [arr arrayByApplyingBlock:function(obj, idx) + { + return obj + "_" + idx; + }]; + + [self assert:[mapped count] equals:[arr count]]; + + [arr enumerateObjectsUsingBlock:function(obj, idx, stop) + { + [self assert:mapped[idx] equals:(obj + "_" + idx)]; + }]; +} + @end @implementation AlwaysEqual : CPObject From 8c67eee4c816e0251440614b835bd89f529499ad Mon Sep 17 00:00:00 2001 From: cacaodev Date: Sat, 16 Jan 2016 18:28:04 +0100 Subject: [PATCH 3/3] (CPArray)arrayByApplyingBlock: documentation --- Foundation/CPArray/_CPArray.j | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Foundation/CPArray/_CPArray.j b/Foundation/CPArray/_CPArray.j index 35ba86d76..7607aa480 100755 --- a/Foundation/CPArray/_CPArray.j +++ b/Foundation/CPArray/_CPArray.j @@ -880,7 +880,11 @@ Returns a hash for the object. Unlike Cocoa, the hash value does not take conten return join.call([self _javaScriptArrayCopy], aString); } -/* @ignore */ +/*! + Returns an Array formed by applying a function to the objects in the receiver. + @param aFunction a function taking two arguments: (element, index). + @return an Array containing the transformed elements. +*/ - (CPArray)arrayByApplyingBlock:(Function/*element, index*/)aFunction { var result = [],