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; } 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 diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index 2bad7cfeb..62f12dfb9 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 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 === set || ([self count] === [set count] && [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 +{ + 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"