From bbd632fa349acee55f6377a6baa57591f2432f61 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Wed, 17 Dec 2008 16:49:31 -0800 Subject: [PATCH 1/9] Add missing method to CPDictionary. --- Foundation/CPDictionary.j | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index 2bad7cfeb..842e1db06 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -408,6 +408,23 @@ } */ +/*! + Take all the key/value pairs in aDictionary and apply them to this dictionary. +*/ +- (void)setValuesForKeysWithDictionary:(CPDictionary)aDictionary +{ + if (!aDictionary) + return; + + var allKeys = [aDictionary allKeys]; + + for (var i=0, count = [allKeys count]; i Date: Wed, 17 Dec 2008 16:50:53 -0800 Subject: [PATCH 2/9] Fixed documentation for dragView: --- AppKit/CPView.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPView.j b/AppKit/CPView.j index 50a677535..f330dfd15 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -1317,7 +1317,7 @@ setBoundsOrigin: /*! Initiates a drag operation from the receiver to another view that accepts dragged data. @param aView the view to be dragged - @param aLocation the lower-left corner coordinate of aView + @param aLocation the top-left corner coordinate of aView @param mouseOffset the distance from the mouseDown: location and the current location @param anEvent the mouseDown: that triggered the drag @param aPastebaord the pasteboard that holds the drag data From 508e8b04a197b095878ec973f02ef2b1cd464945 Mon Sep 17 00:00:00 2001 From: Bailey Carlson Date: Wed, 17 Dec 2008 18:02:17 -0800 Subject: [PATCH 3/9] Add CPSet to Foundation. Thanks Bailey and Nabil. --- Foundation/CPSet.j | 416 ++++++++++++++++++++++++++++++++++++++++ Foundation/Foundation.j | 1 + 2 files changed, 417 insertions(+) create mode 100644 Foundation/CPSet.j diff --git a/Foundation/CPSet.j b/Foundation/CPSet.j new file mode 100644 index 000000000..94d46f765 --- /dev/null +++ b/Foundation/CPSet.j @@ -0,0 +1,416 @@ +/* + * CPSet.j + * Foundation + * + * Created by Bailey Carlson + * Extended by Ross Boucher + * Extended by Nabil Elisa + * + * TODO: Needs to implement CPCoding, CPCopying, CPEnumerator. + */ + +@import "CPObject.j" +@import "CPArray.j" +@import "CPNumber.j" +//import "CPEnumerator.j" + + +@implementation CPSet : CPObject +{ + Object _contents; + unsigned _count; +} + +/* + Creates and returns an empty set. +*/ ++ (id)set +{ + return [[self alloc] init]; +} + +/* + Creates and returns a set containing a uniqued collection of those objects contained in a given array. + @param anArray array containing the objects to add to the new set. If the same object appears more than once objects, it is added only once to the returned set. +*/ ++ (id)setWithArray:(CPArray)array +{ + return [[self alloc] initWithArray:array]; +} + +/* + Creates and returns a set that contains a single given object. + @param anObject The object to add to the new set. +*/ ++ (id)setWithObject:(id)anObject +{ + return [[self alloc] initWithArray:[anObject]]; +} + +/* + Creates and returns a set containing a specified number of objects from a given array of objects. + @param objects A array of objects to add to the new set. If the same object appears more than once objects, it is added only once to the returned set. + @param count The number of objects from objects to add to the new set. +*/ ++ (id)setWithObjects:(id)objects count:(unsigned)count +{ + return [[self alloc] initWithObjects:objects count:count]; +} + +/* + Creates and returns a set containing the objects in a given argument list. + @param anObject The first object to add to the new set. + @param ... A comma-separated list of objects, ending with nil, to add to the new set. If the same object appears more than once objects, it is added only once to the returned set. +*/ ++ (id)setWithObjects:(id)anObject, ... +{ + var set = [[self alloc] init], + argLength = arguments.length, + i = 2; + + for(; i < argLength && (argument = arguments[i]) != nil; ++i) + [set addObject:argument]; + + return set; +} + +/* + Creates and returns a set containing the objects from another set. + @param aSet A set containing the objects to add to the new set. +*/ ++ (id)setWithSet:(CPSet)set +{ + return [[self alloc] initWithSet:set]; +} + +/* + Basic initializer, returns an empty set +*/ +- (id)init +{ + if (self = [super init]) + { + _count = 0; + _contents = {}; + } + + return self; +} + +/* + Initializes a newly allocated set with the objects that are contained in a given array. + @param array An array of objects to add to the new set. If the same object appears more than once in array, it is represented only once in the returned set. +*/ +- (id)initWithArray:(CPArray)array +{ + if (self = [self init]) + { + for (var i = 0; i 0; i--) + { + // If the sets share at least one item, they intersect + if ([self containsObject:items[i]]) + return YES; + } + + return NO; +} + +/* + Compares the receiver to another set. + @param set The set with which to compare the receiver. +*/ +- (BOOL)isEqualToSet:(CPSet)set +{ + // If both are subsets of each other, they are equal + return [self isSubsetOfSet:set] && [set isSubsetOfSet:self]; +} + +/* + Returns a Boolean value that indicates whether every object in the receiver is also present in another given set. + @param set The set with which to compare the receiver. +*/ +- (BOOL)isSubsetOfSet:(CPSet)set +{ + var items = [self allObjects]; + for (var i = 0; i < items.length; i++) + { + // If at least one item is not in both sets, self isn't a subset + if (![set containsObject:items[i]]) + return NO; + } + + return YES; +} + +/* + Sends to each object in the receiver a message specified by a given selector. + @param aSelector A selector that specifies the message to send to the members of the receiver. The method must not take any arguments. It should not have the side effect of modifying the receiver. This value must not be NULL. +*/ +- (void)makeObjectsPerformSelector:(SEL)aSelector +{ + [self makeObjectsPerformSelector:aSelector withObject:nil]; +} + +/* + Sends to each object in the receiver a message specified by a given selector. + @param aSelector A selector that specifies the message to send to the receiver's members. The method must take a single argument of type id. The method should not, as a side effect, modify the receiver. The value must not be NULL. + @param anObject The object to pass as an argument to the method specified by aSelector. +*/ +- (void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)argument +{ + var items = [self allObjects]; + for (var i = 0; i < items.length; i++) + { + [items[i] performSelector:aSelector withObject:argument]; + } +} + +/* + Determines whether the receiver contains an object equal to a given object, and returns that object if it is present. + @param anObject The object for which to test for membership of the receiver. +*/ +- (id)member:(id)object +{ + if ([self containsObject:object]) + return object; + + return nil; +} + +//- (CPEnumerator)objectEnumerator; + + +// Mutable Set Methods +/* + Returns an initialized set with a given initial capacity. + @param numItems, only present for compatability +*/ +- (id)initWithCapacity:(unsigned)numItems +{ + // Only here for compatability with Cocoa + self = [self init]; + return self; +} + +/* + Creates and returns a set with a given initial capacity. + @param numItems, only present for compatability +*/ ++ (id)setWithCapacity:(unsigned)numItems +{ + return [[self alloc] initWithCapacity:numItems]; +} + +/* + Empties the receiver, then adds to the receiver each object contained in another given set. + @param set The set whose members replace the receiver's content. +*/ +- (void)setSet:(CPSet)set +{ + [self removeAllObjects]; + [self addObjectsFromArray:[set allObjects]]; +} + +/* + Adds a given object to the receiver. + @param anObject The object to add to the receiver. +*/ +- (void)addObject:(id)anObject +{ + _contents[[anObject hash]] = anObject; + _count++; +} + +/* + Adds to the receiver each object contained in a given array that is not already a member. + @param array An array of objects to add to the receiver. +*/ +- (void)addObjectsFromArray:(CPArray)array +{ + for (var i = 0, count = array.length; i < count; i++) + { + [self addObject:array[i]]; + } +} + +/* + Removes a given object from the receiver. + @param anObject The object to remove from the receiver. +*/ +- (void)removeObject:(id)anObject +{print("removing: "+anObject); + if ([self containsObject:anObject]) + { + delete _contents[[anObject hash]]; + _count--; + } +} + +/* + Empties the receiver of all of its members. +*/ +- (void)removeAllObjects +{ + _contents = {}; + _count = 0; +} + +/* + Removes from the receiver each object that isn’t a member of another given set. + @param set The set with which to perform the intersection. +*/ +- (void)intersectSet:(CPSet)set +{ + var items = [self allObjects]; + for (var i = 0, count = items.length; i < count; i++) + { + if (![set containsObject:items[i]]) + [self removeObject:items[i]]; + } +} + +/* + Removes from the receiver each object contained in another given set that is present in the receiver. + @param set The set of objects to remove from the receiver. +*/ +- (void)minusSet:(CPSet)set +{ + var items = [set allObjects]; + for (var i = 0; i < items.length; i++) + { + if ([self containsObject:items[i]]) + [self removeObject:items[i]]; + } +} + +/* + Adds to the receiver each object contained in another given set + @param set The set of objects to add to the receiver. +*/ +- (void)unionSet:(CPSet)set +{ + var items = [set allObjects]; + for (var i = 0, count = items.length; i < count; i++) + { + [self addObject:items[i]]; + } +} + +@end + + +@implementation CPMutableSet : CPSet +@end + diff --git a/Foundation/Foundation.j b/Foundation/Foundation.j index 172d879a3..0fbdad3c3 100755 --- a/Foundation/Foundation.j +++ b/Foundation/Foundation.j @@ -45,6 +45,7 @@ @import "CPPropertyListSerialization.j" @import "CPRange.j" @import "CPRunLoop.j" +@import "CPSet.j" @import "CPSortDescriptor.j" @import "CPString.j" @import "CPTimer.j" From 69b16852801ba7b2f57cc29ed7fab6879717360f Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Wed, 17 Dec 2008 18:07:37 -0800 Subject: [PATCH 4/9] Fix for http://cappuccino.lighthouseapp.com/projects/16499/tickets/170-appkitcptextfieldj-textfieldbackground-argreturn-types-are-incorrect [#170 state:resolved milestone:0.6.1] --- AppKit/CPTextField.j | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j index e71c71f78..a6f128cd5 100644 --- a/AppKit/CPTextField.j +++ b/AppKit/CPTextField.j @@ -297,7 +297,7 @@ var _CPTextFieldSquareBezelColor = nil, Sets the background color, which is shown for non-bezeled text fields with drawsBackground set to YES @param aColor The background color */ -- (void)setTextFieldBackgroundColor:(BOOL)aColor +- (void)setTextFieldBackgroundColor:(CPColor)aColor { if (_textFieldBackgroundColor == aColor) return; @@ -310,7 +310,7 @@ var _CPTextFieldSquareBezelColor = nil, /*! Returns the background color. */ -- (BOOL)textFieldBackgroundColor +- (CPColor)textFieldBackgroundColor { return _textFieldBackgroundColor; } From 7ad1c682498f87b847835d079454005f65542e1d Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Wed, 17 Dec 2008 18:11:23 -0800 Subject: [PATCH 5/9] incorrect method name --- Foundation/CPDictionary.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index 842e1db06..5d6293892 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -411,7 +411,7 @@ /*! Take all the key/value pairs in aDictionary and apply them to this dictionary. */ -- (void)setValuesForKeysWithDictionary:(CPDictionary)aDictionary +- (void)addEntriesFromDictionary:(CPDictionary)aDictionary { if (!aDictionary) return; From 8fa5217318ae91caeb79b9c34dce458c96332217 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Wed, 17 Dec 2008 18:21:03 -0800 Subject: [PATCH 6/9] Fix for a few errors francisco noticed. --- Foundation/CPSet.j | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Foundation/CPSet.j b/Foundation/CPSet.j index 94d46f765..2ba0b995d 100644 --- a/Foundation/CPSet.j +++ b/Foundation/CPSet.j @@ -165,8 +165,8 @@ var array = []; for (var property in _contents) { - //if (_contents.hasOwnProperty(property)) - array.push(_contents[property]); + if (_contents.hasOwnProperty(property)) + array.push(_contents[property]); } return array; @@ -234,7 +234,7 @@ - (BOOL)isEqualToSet:(CPSet)set { // If both are subsets of each other, they are equal - return [self isSubsetOfSet:set] && [set isSubsetOfSet:self]; + return self === set || ([self count] === [set count] && [set isSubsetOfSet:self]); } /* @@ -350,7 +350,7 @@ @param anObject The object to remove from the receiver. */ - (void)removeObject:(id)anObject -{print("removing: "+anObject); +{ if ([self containsObject:anObject]) { delete _contents[[anObject hash]]; From bc30541b9ca675dae4b8d733afe1008b1d82dda6 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Wed, 17 Dec 2008 18:21:29 -0800 Subject: [PATCH 7/9] Add 2 missing methods on CPDictionary. [#157 state:resolved milestone:0.6.1] --- Foundation/CPDictionary.j | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index 5d6293892..2ddd993e8 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -359,6 +359,17 @@ { dictionary_removeValue(self, aKey); } + +/*! + Removes each entry in allKeys from the receiver. + @param allKeys an array of keys that will be removed from the dictionary +*/ +- (void)removeObjectsForKeys:(CPArray)allKeys +{ + for (var i=0, count = allKeys.length; i Date: Wed, 17 Dec 2008 18:39:55 -0800 Subject: [PATCH 8/9] typo --- Foundation/CPDictionary.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index 2ddd993e8..e9700718c 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -432,7 +432,7 @@ for (var i=0, count = [allKeys count]; i Date: Wed, 17 Dec 2008 18:44:00 -0800 Subject: [PATCH 9/9] another typo. silly me. --- Foundation/CPDictionary.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index e9700718c..62f12dfb9 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -432,7 +432,7 @@ for (var i=0, count = [allKeys count]; i