From bf28b8bbc6e4f6f8fd9cd590e72e90df844c556e Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Sun, 5 Oct 2008 18:15:36 -0700 Subject: [PATCH 1/6] CPString -capitalizedString fixed Reviewed by me. [#90 state:resolved responsible:tlrobinson] --- Foundation/CPString.j | 19 +++------- Tests/Foundation/CPStringTest.j | 66 +++++++++++++++------------------ 2 files changed, 35 insertions(+), 50 deletions(-) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index d98b64a42..24a904f9a 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -465,22 +465,15 @@ var CPStringHashes = new objj_dictionary(); */ - (CPString)capitalizedString { - var i = 0, - last = true, - capitalized = self; - - for(; i < length; ++i) + var parts = self.split(/\b/g); // split on word boundaries + for (var i = 0; i < parts.length; i++) { - var character = charAt(i); - if (character == ' ' || character == '\t' || character == '\n') last = true; + if (i == 0 || (/\s$/).test(parts[i-1])) // only capitalize if previous token was whitespace + parts[i] = parts[i].substring(0, 1).toUpperCase() + parts[i].substring(1).toLowerCase(); else - { - if (last) capitalized = capitalized.substr(0, i - 1) + character.toUpperCase() + capitalized.substr(i); - last = false; - } + parts[i] = parts[i].toLowerCase(); } - - return capitalized; + return parts.join(""); } /* diff --git a/Tests/Foundation/CPStringTest.j b/Tests/Foundation/CPStringTest.j index 289663cdc..ec4c3e7f4 100644 --- a/Tests/Foundation/CPStringTest.j +++ b/Tests/Foundation/CPStringTest.j @@ -24,47 +24,39 @@ import message:"stringByAppendingFormat: expected:" + expectedString + " actual:" + actualString]; } -- (void) testBoolValue +- (void)testBoolValue { - var testString = @" 090"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + var testStrings = [ + [" 090", YES], + [" YES", YES], + [" true", YES], + [" True", YES], + [" tTR", YES], + [" +98", YES], + [" -98", YES], + [" +08", YES], + [" -98", YES], + [" NO", NO], + [" -N00", NO], + [" 00", NO], + [" -00", NO] + ]; - testString = @" YES"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - - testString = @" true"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - - testString = @" True"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + for (var i = 0; i < testStrings.length; i++) + [self assert:[testStrings[i][0] boolValue] equals:testStrings[i][1]]; +} - testString = @" tTR"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - - testString = @" +98"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - - testString = @" -98"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - - testString = @" +08"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - - testString = @" -98"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - - testString = @" NO"; - [self assertFalse:[testString boolValue] message:"boolValue for the string " + testString + " should return false"]; - - testString = @" -N00"; - [self assertFalse:[testString boolValue] message:"boolValue for the string " + testString + " should return false"]; - - testString = @" 00"; - [self assertFalse:[testString boolValue] message:"boolValue for the string " + testString + " should return false"]; - - testString = @" -00"; - [self assertFalse:[testString boolValue] message:"boolValue for the string " + testString + " should return false"]; +- (void)testCapitalizedString +{ + var testStrings = [ + ["", ""], + ["hElLo wOrLd", "Hello World"], + [" monkey-Cow", " Monkey-cow"], + ["tHe QuicK bRowN-Fox JumPed_Over +the LaZy%dog", "The Quick Brown-fox Jumped_over +the Lazy%dog"] + ]; + for (var i = 0; i < testStrings.length; i++) + [self assert:[testStrings[i][0] capitalizedString] equals:testStrings[i][1]]; } From ba189afaf518acfdf4dafae41bb2d7a39538c7be Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Sun, 5 Oct 2008 18:34:06 -0700 Subject: [PATCH 2/6] CPArray -componentsJoinedByString fixed Moved objj object toString override to CPObject.j Reviewed by me [#89 state:resolved responsible:tlrobinson] --- Foundation/CPArray.j | 13 ++++--------- Foundation/CPLog.j | 9 --------- Foundation/CPObject.j | 10 ++++++++++ 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Foundation/CPArray.j b/Foundation/CPArray.j index c57ecb99f..8fec1956c 100755 --- a/Foundation/CPArray.j +++ b/Foundation/CPArray.j @@ -656,21 +656,16 @@ import "CPException.j" /* Returns a string formed by concatenating the objects in the receiver, with the specified separator string inserted between each part. - If the element is a Cappuccino object, then the description + If the element is a Objective-J object, then the description of that object will be used, otherwise the default JavaScript representation will be used. @param aString the separator that will separate each object string @return the string representation of the array */ - (CPString)componentsJoinedByString:(CPString)aString { - var index = 0, - count = [self count], - string = @""; - - for(; index < count; ++i) - string += self[index].isa ? [self[index] description] : self[index]; - - return string; + // Objective-J objects get "description" called on them automatically when coerced to strings + // (see "objj_object.prototype.toString" at bottom of CPObject.j) + return join(aString); } // Creating a description of the array diff --git a/Foundation/CPLog.j b/Foundation/CPLog.j index baea2eed1..77000967f 100644 --- a/Foundation/CPLog.j +++ b/Foundation/CPLog.j @@ -372,12 +372,3 @@ var _CPLogInitPopup = function(logWindow) } }, false); } - -// override toString on Objective-J objects so we print the actual description of the object instead of [Object object] -objj_object.prototype.toString = function() -{ - if (this.isa && class_getInstanceMethod(this.isa, "description") != NULL) - return [this description] - else - return String(this) + " (-description not implemented)"; -} diff --git a/Foundation/CPObject.j b/Foundation/CPObject.j index 7bae52908..be44363ee 100644 --- a/Foundation/CPObject.j +++ b/Foundation/CPObject.j @@ -453,3 +453,13 @@ } @end + +// override toString on Objective-J objects so we get the actual description of the object +// when coerced to a string, instead of "[Object object]" +objj_object.prototype.toString = function() +{ + if (this.isa && class_getInstanceMethod(this.isa, "description") != NULL) + return [this description] + else + return String(this) + " (-description not implemented)"; +} From 02b41877427e9cf67ab5d28b3b72d1d38024c71c Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Sun, 5 Oct 2008 18:47:47 -0700 Subject: [PATCH 3/6] CPArrayTest --- Tests/Foundation/CPArrayTest.j | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Tests/Foundation/CPArrayTest.j diff --git a/Tests/Foundation/CPArrayTest.j b/Tests/Foundation/CPArrayTest.j new file mode 100644 index 000000000..403cfc6c6 --- /dev/null +++ b/Tests/Foundation/CPArrayTest.j @@ -0,0 +1,21 @@ +import +import +import + +@implementation CPArrayTest : OJTestCase + +- (void)testComponentsJoinedByString +{ + var testStrings = [ + [[], "", ""], + [[], "-", ""], + [[1,2], "-", "1-2"], + [[1,2,3], "-", "1-2-3"], + [["123", 456], "-", "123-456"] + ]; + + for (var i = 0; i < testStrings.length; i++) + [self assert:[testStrings[i][0] componentsJoinedByString:testStrings[i][1]] equals:testStrings[i][2]]; +} + +@end From b1c8265f4cac6ee61761b89c980ee9adb4280635 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Sun, 5 Oct 2008 20:00:31 -0700 Subject: [PATCH 4/6] Changed "steam" to "steam build" and added "steam create" Updated ant scripts to reflect steam changes. Minor update to objj --- AppKit/build.xml | 22 ++++++----- Foundation/build.xml | 18 +++++---- Objective-J/build.xml | 18 +++++---- Tools/NewApplication/build.xml | 6 ++- Tools/bake/example.bakefile | 4 +- Tools/nib2cib/build.xml | 8 ++-- Tools/objj/objj | 6 ++- Tools/objj/objj.js | 27 +++++++++----- Tools/steam/steam | 2 + Tools/steam/steam.js | 67 ++++++++++++++++++++++++++++++++++ Tools/steam/steam.xml | 3 +- build.xml | 6 +++ common.xml | 4 +- 13 files changed, 147 insertions(+), 44 deletions(-) diff --git a/AppKit/build.xml b/AppKit/build.xml index 322f7f3b0..45feb0d91 100644 --- a/AppKit/build.xml +++ b/AppKit/build.xml @@ -5,26 +5,26 @@ - + - + - + - + - + - + @@ -34,11 +34,15 @@ - + + + + + + diff --git a/Foundation/build.xml b/Foundation/build.xml index 4fbc75dcf..950483c23 100644 --- a/Foundation/build.xml +++ b/Foundation/build.xml @@ -5,20 +5,20 @@ - + - + - + - + @@ -28,11 +28,15 @@ - + + + - - + + diff --git a/Objective-J/build.xml b/Objective-J/build.xml index 533a4f286..ba6595c8b 100644 --- a/Objective-J/build.xml +++ b/Objective-J/build.xml @@ -64,20 +64,24 @@ - + + - - + + + + + + + - - + diff --git a/Tools/NewApplication/build.xml b/Tools/NewApplication/build.xml index 5a9377c2b..95b23c81a 100644 --- a/Tools/NewApplication/build.xml +++ b/Tools/NewApplication/build.xml @@ -20,8 +20,12 @@ - + + + + + diff --git a/Tools/bake/example.bakefile b/Tools/bake/example.bakefile index e87955c35..9374f3723 100644 --- a/Tools/bake/example.bakefile +++ b/Tools/bake/example.bakefile @@ -13,13 +13,13 @@ { "src" : "Foundation", "dst" : "Frameworks/Foundation", - "build" : "steam -c Release -b BUILD_PATH", + "build" : "steam build -c Release -b BUILD_PATH", "copyFrom" : "Release/Foundation" }, { "src" : "AppKit", "dst" : "Frameworks/AppKit", - "build" : "steam -c Release -b BUILD_PATH", + "build" : "steam build -c Release -b BUILD_PATH", "copyFrom" : "Release/AppKit" } ] diff --git a/Tools/nib2cib/build.xml b/Tools/nib2cib/build.xml index 6436588a4..29d4af4ce 100644 --- a/Tools/nib2cib/build.xml +++ b/Tools/nib2cib/build.xml @@ -5,20 +5,20 @@ - + - + - + - + diff --git a/Tools/objj/objj b/Tools/objj/objj index e0205f667..5db25cee1 100644 --- a/Tools/objj/objj +++ b/Tools/objj/objj @@ -43,9 +43,11 @@ if [[ `uname` == CYGWIN* ]]; then CLASSPATH=`cygpath -wp "$CLASSPATH"` fi +export OBJJ_LIB + #if [ -e $STEAM_BUILD/Objective-J.build/Release/Rhino ]; then - $RLWRAP java -classpath $CLASSPATH objj $OBJJ_LIB $@ - #$RLWRAP java -classpath $CLASSPATH org.mozilla.javascript.tools.shell.Main $OBJJ $OBJJ_LIB $STEAM_BUILD $@ + $RLWRAP java -classpath $CLASSPATH objj $@ + #$RLWRAP java -classpath $CLASSPATH org.mozilla.javascript.tools.shell.Main $OBJJ $@ #else # echo "Missing frameworks at $STEAM_BUILD/Objective-J.build/Release/Rhino" 1>&2 #fi diff --git a/Tools/objj/objj.js b/Tools/objj/objj.js index 4a66b5a87..6caad2b3a 100644 --- a/Tools/objj/objj.js +++ b/Tools/objj/objj.js @@ -1,9 +1,8 @@ debug = false; args = arguments; -var OBJJ_LIB = arguments[0]; - -arguments.splice(0, 1); +// FIXME: remove Rhino/Java dependencies +var OBJJ_LIB = Packages.java.lang.System.getenv("OBJJ_LIB"); if (typeof window == "undefined") { @@ -14,7 +13,7 @@ if (typeof window == "undefined") if (typeof objj_import == "undefined") { print("Loading Objective-J."); - load(OBJJ_LIB+'/Frameworks/Objective-J/Objective-J.js'); + load(OBJJ_LIB+'/Frameworks-Rhino/Objective-J/Objective-J.js'); } var OBJJ_INCLUDE_PATHS_STRING = getEnv("OBJJ_INCLUDE_PATHS"); @@ -24,19 +23,27 @@ if (OBJJ_INCLUDE_PATHS_STRING) } else { - OBJJ_INCLUDE_PATHS = [OBJJ_LIB+'/Frameworks']; + OBJJ_INCLUDE_PATHS = [OBJJ_LIB+'/Frameworks-Rhino']; } try { - if (arguments.length > 0) + if (args.length > 0) { - var main_file = arguments[0]; - arguments.splice(0, 1); + var mainFilename = args.shift(); + + mainFile = new Packages.java.io.File(mainFilename); + if (!mainFile.exists()) + { + print(mainFile.getAbsolutePath() + " not found.") + Packages.java.System.exit(1); + } + + var mainFilePath = mainFile.getAbsolutePath(); if (debug) - print("Loading: " + main_file); + print("Loading: " + mainFilePath); - objj_import(main_file, YES); + objj_import(mainFilePath, YES); serviceTimeouts(); diff --git a/Tools/steam/steam b/Tools/steam/steam index bac0bb5b8..d5f64ee3a 100644 --- a/Tools/steam/steam +++ b/Tools/steam/steam @@ -32,4 +32,6 @@ if [[ `uname` == CYGWIN* ]]; then STEAM_BUILD=`cygpath -wp "$STEAM_BUILD"` fi +export OBJJ_LIB + java -classpath $CLASSPATH steam $@ diff --git a/Tools/steam/steam.js b/Tools/steam/steam.js index 92492b3b0..620169d2d 100644 --- a/Tools/steam/steam.js +++ b/Tools/steam/steam.js @@ -317,7 +317,74 @@ Project.prototype.copyResources = function() rsync(this._resources, this.buildProducts()); } +function printUsage(command) +{ + var usage = "usage: steam COMMAND [ARGS]\n\n"+ +"The most commonly used steam commands are:\n"+ +"\tbuild Build a project\n"+ +"\tcreate Create a new project\n\n"+ +"See 'steam help COMMAND' for more information on a specific command."; + + switch (command) + { + case "--help" : + case undefined : + java.lang.System.out.println(usage); + break; + default : + java.lang.System.out.println("steam: '" + command + "' is not a steam command. See 'steam --help'."); + } + java.lang.System.exit(1); +} + function main() +{ + if (arguments.length < 1) + printUsage(); + + var command = Array.prototype.shift.apply(arguments); + switch (command) + { + case "create" : + mainCreate.apply(mainCreate, arguments); + break; + case "build" : + mainBuild.apply(mainBuild, arguments); + break; + default : + printUsage(command); + } + +} + +function mainCreate() +{ + var OBJJ_LIB = System.getenv("OBJJ_LIB"); + + if (arguments.length < 1) + printUsage("create"); + + var dst = arguments[0]; + + var srcNewApp = new File(OBJJ_LIB+"/NewApplication"), + srcFrameworks = new File(OBJJ_LIB+"/Frameworks"), + dstNewApp = new File(dst), + dstFrameworks = new File(dst+"/Frameworks"); + + System.out.println(srcNewApp.getCanonicalPath() + "," + dstNewApp.getCanonicalPath() + "," + srcFrameworks.getCanonicalPath() + "," + dstFrameworks.getCanonicalPath()); + + if (!dstNewApp.exists()) + { + exec(["cp", "-vR", srcNewApp.getCanonicalPath(), dstNewApp.getCanonicalPath()], true); + exec(["cp", "-vR", srcFrameworks.getCanonicalPath(), dstFrameworks.getCanonicalPath()], true); + } + else + { + System.out.println("Directory already exists"); + } +} + +function mainBuild() { var index = 0, count = arguments.length, diff --git a/Tools/steam/steam.xml b/Tools/steam/steam.xml index 5d994b3c6..66e972e49 100644 --- a/Tools/steam/steam.xml +++ b/Tools/steam/steam.xml @@ -2,12 +2,13 @@ - + + diff --git a/build.xml b/build.xml index 0659b82a4..150cc4eb9 100644 --- a/build.xml +++ b/build.xml @@ -45,5 +45,11 @@ + + + + + + \ No newline at end of file diff --git a/common.xml b/common.xml index 6f591df75..62fbbc8f7 100644 --- a/common.xml +++ b/common.xml @@ -19,6 +19,7 @@ + @@ -36,13 +37,14 @@ - + + From 1fc253d9433b33de88da5771ecf27ec0cc0558b6 Mon Sep 17 00:00:00 2001 From: tlrobinson Date: Mon, 6 Oct 2008 10:29:54 -0700 Subject: [PATCH 5/6] CPCollectionView -shouldAllowMultipleSelection typo [#91 state:resolved responsible:tlrobinson] --- AppKit/CPCollectionView.j | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index dbc631d8c..1f1123407 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -235,7 +235,7 @@ import */ - (void)setAllowsMultipleSelection:(BOOL)shouldAllowMultipleSelection { - _allowsMultipleSelection = shouldAllowsMultipleSelection; + _allowsMultipleSelection = shouldAllowMultipleSelection; } /* @@ -691,4 +691,4 @@ var CPCollectionViewItemViewKey = @"CPCollectionViewItemViewKey"; [aCoder encodeObject:_view forKey:CPCollectionViewItemViewKey]; } -@end +@end \ No newline at end of file From 358251ec4446980ab6c5790065eb64904ab9787e Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Mon, 6 Oct 2008 15:45:26 -0700 Subject: [PATCH 6/6] Fix for #92 - CPColor colorWithHexString should accept lowercase strings [#92 state:resolved] --- AppKit/CPColor.j | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/AppKit/CPColor.j b/AppKit/CPColor.j index fccc66733..74eb1a810 100644 --- a/AppKit/CPColor.j +++ b/AppKit/CPColor.j @@ -518,7 +518,9 @@ function hexToRGB(hex) { if(hex.length != 6) return null; - + + hex = hex.toUpperCase(); + for(var i=0; i