diff --git a/AppKit/CPApplication.j b/AppKit/CPApplication.j index 72f88a420..717d02993 100644 --- a/AppKit/CPApplication.j +++ b/AppKit/CPApplication.j @@ -298,6 +298,11 @@ CPRunContinuesResponse = -1002; [CPPlatform terminateApplication]; } +- (void)activateIgnoringOtherApps:(BOOL)shouldIgnoreOtherApps +{ + [CPPlatform activateIgnoringOtherApps:shouldIgnoreOtherApps]; +} + /*! Calls \c -finishLaunching method which results in starting the main event loop. diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index b59710e75..2dbab4bfe 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -250,11 +250,11 @@ /*! Returns \c YES if the collection view is - selected, and \c NO otherwise. + selectable, and \c NO otherwise. */ -- (BOOL)isSelected +- (BOOL)isSelectable { - return _isSelected; + return _isSelectable; } /*! @@ -675,6 +675,7 @@ var CPCollectionViewMinItemSizeKey = @"CPCollectionViewMinItemSizeKey", CPCollectionViewMaxItemSizeKey = @"CPCollectionViewMaxItemSizeKey", CPCollectionViewVerticalMarginKey = @"CPCollectionViewVerticalMarginKey", + CPCollectionViewSelectableKey = @"CPCollectionViewSelectableKey", CPCollectionViewBackgroundColorsKey = @"CPCollectionViewBackgroundColorsKey"; @@ -695,7 +696,10 @@ var CPCollectionViewMinItemSizeKey = @"CPCollectionViewMinItemSizeKey", _minItemSize = [aCoder decodeSizeForKey:CPCollectionViewMinItemSizeKey] || CGSizeMakeZero(); _maxItemSize = [aCoder decodeSizeForKey:CPCollectionViewMaxItemSizeKey] || CGSizeMakeZero(); + _verticalMargin = [aCoder decodeFloatForKey:CPCollectionViewVerticalMarginKey]; + + _isSelectable = [aCoder decodeBoolForKey:CPCollectionViewSelectableKey]; [self setBackgroundColors:[aCoder decodeObjectForKey:CPCollectionViewBackgroundColorsKey]]; @@ -704,7 +708,6 @@ var CPCollectionViewMinItemSizeKey = @"CPCollectionViewMinItemSizeKey", _selectionIndexes = [CPIndexSet indexSet]; _allowsEmptySelection = YES; - _isSelectable = YES; } return self; @@ -716,10 +719,12 @@ var CPCollectionViewMinItemSizeKey = @"CPCollectionViewMinItemSizeKey", if (!CGSizeEqualToSize(_minItemSize, CGSizeMakeZero())) [aCoder encodeSize:_minItemSize forKey:CPCollectionViewMinItemSizeKey]; - + if (!CGSizeEqualToSize(_maxItemSize, CGSizeMakeZero())) [aCoder encodeSize:_maxItemSize forKey:CPCollectionViewMaxItemSizeKey]; - + + [aCoder encodeBool:_isSelectable forKey:CPCollectionViewSelectableKey]; + [aCoder encodeFloat:_verticalMargin forKey:CPCollectionViewVerticalMarginKey]; [aCoder encodeObject:_backgroundColors forKey:CPCollectionViewBackgroundColorsKey]; diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index 2c0c0693d..58f051a88 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -1264,6 +1264,8 @@ CPTexturedBackgroundWindowMask if (_leftMouseDownView != _firstResponder && [_leftMouseDownView acceptsFirstResponder]) [self makeFirstResponder:_leftMouseDownView]; + [CPApp activateIgnoringOtherApps:YES]; + var theWindow = [anEvent window]; if ([theWindow isKeyWindow] || [theWindow becomesKeyOnlyIfNeeded]) diff --git a/AppKit/Platform/CPPlatform.j b/AppKit/Platform/CPPlatform.j index 851e538bc..a5eac3712 100644 --- a/AppKit/Platform/CPPlatform.j +++ b/AppKit/Platform/CPPlatform.j @@ -45,4 +45,12 @@ window.cpTerminate(); } ++ (void)activateIgnoringOtherApps:(BOOL)shouldIgnoreOtherApps +{ +#if PLATFORM(DOM) + if (typeof window["cpActivateIgnoringOtherApps"] === "function") + window.cpActivateIgnoringOtherApps(!!shouldIgnoreOtherApps); +#endif +} + @end diff --git a/Objective-J/CommonJS/objective-j/lib-js/objective-j.js b/Objective-J/CommonJS/objective-j/lib-js/objective-j.js index a226ba7f5..4c88c2ccd 100644 --- a/Objective-J/CommonJS/objective-j/lib-js/objective-j.js +++ b/Objective-J/CommonJS/objective-j/lib-js/objective-j.js @@ -135,7 +135,7 @@ var objj_eval = exports.objj_eval = function(code) } // prepocesses Objective-J code into JavaScript, which will perform imports synchronously when eval'd -var objj_preprocess_sync = function(code, path) +window.objj_preprocess_sync = function(code, path) { var fragments = objj_preprocess(code, new objj_bundle(), new objj_file(), OBJJ_PREPROCESSOR_DEBUG_SYMBOLS) @@ -155,7 +155,7 @@ var objj_preprocess_sync = function(code, path) // FIXME: Why does this need to be global? // synchronously perform an import -global.objj_import_sync = function(pathOrPaths, isLocal) +window.objj_import_sync = function(pathOrPaths, isLocal) { var context = new objj_context(); context.pushFragment(fragment_create_file(pathOrPaths, new objj_bundle(), isLocal, NULL)); diff --git a/Rakefile b/Rakefile index 05a81dfee..695a67f7e 100644 --- a/Rakefile +++ b/Rakefile @@ -118,7 +118,7 @@ task :install => [:tools_download] do end task :test => [:build] do - tests = "'" + FileList['Tests/**/*.j'].join("' '") + "'" + tests = "'" + FileList['Tests/**/*Test.j'].join("' '") + "'" build_result = %x{ojtest #{tests} } if build_result.match(/Test suite failed/i) diff --git a/Tests/AppKit/CPCollectionViewTest.j b/Tests/AppKit/CPCollectionViewTest.j index fc6eeafe2..d9c0c6bfb 100644 --- a/Tests/AppKit/CPCollectionViewTest.j +++ b/Tests/AppKit/CPCollectionViewTest.j @@ -2,15 +2,32 @@ @import @implementation CPCollectionViewTest : OJTestCase +{ + CPCollectionView _collectionView; +} + +- (void)setUp +{ + _collectionView = [[CPCollectionView alloc] initWithFrame:CGRectMakeZero()]; +} - (void)testItemPrototypeActuallyReturnsTheItemPrototype { - var propertiesCollectionView = [[CPCollectionView alloc] initWithFrame:CGRectMakeZero()], - itemPrototype = [[CPCollectionViewItem alloc] init]; - - [propertiesCollectionView setItemPrototype:itemPrototype]; + var itemPrototype = [[CPCollectionViewItem alloc] init]; + [_collectionView setItemPrototype:itemPrototype]; - [self assert:[CPCollectionViewItem class] equals:[[propertiesCollectionView itemPrototype] class]]; + [self assert:itemPrototype same:[_collectionView itemPrototype]]; +} + +- (void)testIsSelectableGetter +{ + var collectionView = [[CPCollectionView alloc] initWithFrame:CGRectMakeZero()]; + + [collectionView setSelectable:YES]; + [self assertTrue:[collectionView isSelectable]]; + + [collectionView setSelectable:NO]; + [self assertFalse:[collectionView isSelectable]]; } @end diff --git a/Tests/Foundation/CPDictionaryTest.j b/Tests/Foundation/CPDictionaryTest.j new file mode 100644 index 000000000..f3936b26b --- /dev/null +++ b/Tests/Foundation/CPDictionaryTest.j @@ -0,0 +1,176 @@ +@import + +@implementation CPDictionaryTest : OJTestCase +{ +} + +- (void)setUp +{ + json = { + "key1": ['1', '2', '3'], + "key2": "This is a string", + "key3": { + "another": "object" + } + } + + string_dict = [[CPDictionary alloc] initWithObjects:[@"1", @"2"] forKeys:[@"key1", @"key2"]]; + json_dict = [CPDictionary dictionaryWithJSObject:json recursively:YES]; +} + +- (void)testInitWithDictionary +{ + var dict = [[CPDictionary alloc] initWithObjects:[@"1", @"2"] forKeys:[@"key1", @"key2"]]; + + var new_dict = [[CPDictionary alloc] initWithDictionary:dict]; + [self assert:[new_dict objectForKey:@"key1"] equals:[dict objectForKey:@"key1"]]; + [self assert:[new_dict objectForKey:@"key2"] equals:[dict objectForKey:@"key2"]]; + + var new_dict_cm = [CPDictionary dictionaryWithDictionary:dict]; + [self assert:[new_dict_cm objectForKey:@"key1"] equals:[dict objectForKey:@"key1"]]; + [self assert:[new_dict_cm objectForKey:@"key2"] equals:[dict objectForKey:@"key2"]]; +} + +- (void)testInitWithObjects +{ + var dict = [[CPDictionary alloc] initWithObjects:[@"1", @"2"] forKeys:[@"key1", @"key2"]]; + [self assert:[dict objectForKey:@"key1"] equals:@"1"]; + [self assert:[dict objectForKey:@"key2"] equals:@"2"]; + [self assert:[dict count] equals:2]; + + var dict_cm = [CPDictionary dictionaryWithObjects:[@"1", @"2"] forKeys:[@"key1", @"key2"]]; + [self assert:[dict_cm objectForKey:@"key1"] equals:@"1"]; + [self assert:[dict_cm objectForKey:@"key2"] equals:@"2"]; + [self assert:[dict_cm count] equals:2]; +} + +- (void)testDictionaryWithObject +{ + var dict = [CPDictionary dictionaryWithObject:@"1" forKey:@"key1"]; + [self assert:[dict objectForKey:@"key1"] equals:@"1"]; + [self assert:[dict count] equals:1]; +} + +- (void)testDictionaryWithJSObjectRecursive +{ + var dict = [CPDictionary dictionaryWithJSObject:json recursively:YES]; + [self assert:[dict count] equals:3]; + [self assert:[[dict objectForKey:@"key3"] count] equals:1]; +} + +- (void)testDictionaryWithJSObjectNonRecursive +{ + var non_recursive_dict = [CPDictionary dictionaryWithJSObject:json recursively:NO]; + [self assertThrows:[non_recursive_dict objectForKey:@"key3"]]; +} + +- (void)testCopy +{ + var copy = [string_dict copy]; + [self assert:copy notSame:string_dict]; + [self assert:[copy objectForKey:@"key1"] equals:[string_dict objectForKey:@"key1"]]; +} + +- (void)testCount +{ + [self assert:[string_dict count] equals:2]; + [self assert:[json_dict count] equals:3]; +} + +- (void)testAllKeys +{ + [self assert:[string_dict allKeys] equals:[@"key2", @"key1"]]; + [self assert:[json_dict allKeys] equals:[@"key1", @"key2", @"key3"]]; +} + +- (void)testAllValues +{ + [self assert:[string_dict allValues] equals:[@"1", @"2"]]; + // Had to get object from key to get test passing + [self assert:[json_dict allValues] equals:[[json_dict objectForKey:@"key3"], @"This is a string", ['1', '2', '3']]]; +} + +- (void)testObjectForKey +{ + [self assert:[string_dict objectForKey:@"key1"] equals:"1"]; + [self assert:[json_dict objectForKey:@"key1"] equals:['1', '2', '3']]; +} + +- (void)testKeyEnumerator +{ + var dict = [[CPDictionary alloc] init]; + [self assertNull:[[dict keyEnumerator] nextObject]]; + [self assertNotNull:[[dict keyEnumerator] allObjects]]; + + [self assertNotNull:[[string_dict keyEnumerator] nextObject]]; + [self assertNotNull:[[json_dict keyEnumerator] nextObject]]; + [self assertNotNull:[[string_dict keyEnumerator] allObjects]]; + [self assertNotNull:[[json_dict keyEnumerator] allObjects]]; +} + +- (void)testObjectEnumerator +{ + var dict = [[CPDictionary alloc] init]; + [self assertNull:[[dict objectEnumerator] nextObject]]; + [self assertNotNull:[[dict objectEnumerator] allObjects]]; + + [self assertNotNull:[[string_dict objectEnumerator] nextObject]]; + [self assertNotNull:[[json_dict objectEnumerator] nextObject]]; + [self assertNotNull:[[string_dict objectEnumerator] allObjects]]; + [self assertNotNull:[[json_dict objectEnumerator] allObjects]]; +} + +- (void)testIsEqualToDictionary +{ + [self assertTrue:[string_dict isEqualToDictionary:[string_dict copy]]]; + [self assertTrue:[json_dict isEqualToDictionary:[json_dict copy]]]; + [self assertFalse:[json_dict isEqualToDictionary:[string_dict copy]]]; +} + +- (void)testRemoveAllObjects +{ + [string_dict removeAllObjects]; + [json_dict removeAllObjects]; + [self assert:[string_dict count] equals:0]; + [self assert:[json_dict count] equals:0]; +} + +- (void)testRemoveObjectForKey +{ + [string_dict removeObjectForKey:@"key1"]; + [json_dict removeObjectForKey:@"key1"]; + [self assert:[string_dict count] equals:1]; + [self assert:[json_dict count] equals:2]; + [self assertThrows:[string_dict objectForKey:@"key1"]]; + [self assertThrows:[json_dict objectForKey:@"key1"]]; +} + +- (void)testRemoveObjectsForKeys +{ + [string_dict removeObjectsForKeys:[@"key1"]]; + [json_dict removeObjectsForKeys:[@"key1", @"key2"]]; + [self assert:[string_dict count] equals:1]; + [self assert:[json_dict count] equals:1]; + [self assertThrows:[string_dict objectForKey:@"key1"]]; + [self assertThrows:[json_dict objectForKey:@"key1"]]; + [self assertThrows:[json_dict objectForKey:@"key2"]]; +} + +- (void)testSetObjectForKey +{ + var dict = [[CPDictionary alloc] init]; + [dict setObject:@"setObjectForKey test" forKey:@"key1"]; + [self assert:[dict objectForKey:@"key1"] equals:@"setObjectForKey test"]; + [self assert:[dict count] equals:1]; +} + +- (void)testAddEntriesFromDictionary +{ + var dict = [[CPDictionary alloc] initWithObjects:[@"1", @"2"] forKeys:[@"key4", @"key5"]]; + [string_dict addEntriesFromDictionary:dict] + [json_dict addEntriesFromDictionary:dict] + [self assert:[string_dict count] equals:4]; + [self assert:[json_dict count] equals:5]; +} + +@end \ No newline at end of file diff --git a/Tests/Foundation/CPURLTest.j b/Tests/Foundation/CPURLTest.j index 2df97011d..ea6ee8452 100644 --- a/Tests/Foundation/CPURLTest.j +++ b/Tests/Foundation/CPURLTest.j @@ -1,4 +1,4 @@ -@import "CPURL.j" +@import var exampleProtocol = "http", exampleUser = "foo",