From f3633c050b8a1d006371e9d52f6239429d8e6865 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Tue, 23 Feb 2010 15:41:52 -0800 Subject: [PATCH 1/6] Add OBJJ_AUTO_BOOTSTRAP option to disable auto-bootstrapping. Fixes flatten race condition. --- Objective-J/Bootstrap.js | 25 +++++++++++++++++-------- Tools/flatten/flatten | 35 ++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/Objective-J/Bootstrap.js b/Objective-J/Bootstrap.js index 0bda2073c..abd530ff7 100644 --- a/Objective-J/Bootstrap.js +++ b/Objective-J/Bootstrap.js @@ -26,15 +26,19 @@ var cwd = FILE.cwd(), StaticResource.root = rootResource; #ifdef BROWSER -if (rootResource.isResolved()) + +exports.bootstrap = function() { - rootResource.nodeAtSubPath(FILE.dirname(cwd), YES); - resolveCWD(); -} -else -{ - rootResource.resolve(); - rootResource.addEventListener("resolve", resolveCWD); + if (rootResource.isResolved()) + { + rootResource.nodeAtSubPath(FILE.dirname(cwd), YES); + resolveCWD(); + } + else + { + rootResource.resolve(); + rootResource.addEventListener("resolve", resolveCWD); + } } function resolveCWD() @@ -76,4 +80,9 @@ afterDocumentLoad(function() { documentLoaded = YES; }); + + +if (typeof OBJJ_AUTO_BOOTSTRAP === "undefined" || OBJJ_AUTO_BOOTSTRAP) + exports.bootstrap(); + #endif diff --git a/Tools/flatten/flatten b/Tools/flatten/flatten index c6b24eb9e..9854df81a 100755 --- a/Tools/flatten/flatten +++ b/Tools/flatten/flatten @@ -39,19 +39,15 @@ function main(args) var root = flattener.require("objective-j").StaticResource.root; + // FIXME: shouldn't have to do this manually var components = rootPath.split("/").slice(1, -1); - print(components) var node = root; while (components.length) { - print(node._path); node = node._children[components.shift()]; } applicationRoot = node; - print("applicationRoot._children="+Object.keys(applicationRoot._children)); - print("rootPath="+rootPath); - print("applicationRoot="+applicationRoot.toString()); - print("root="+root); + print(applicationRoot.toString()); var applicationJS = flattener.buildApplicationJS(applicationRoot); @@ -59,8 +55,8 @@ function main(args) outputPath.join("Application.js").write(applicationJS); - addApplicationScriptTag(outputPath.join("index.html")); - addApplicationScriptTag(outputPath.join("index-debug.html")); + rewriteMainHTML(outputPath.join("index.html")); + rewriteMainHTML(outputPath.join("index-debug.html")); } // ObjectiveJFlattener inherits from ObjectiveJRuntimeAnalyzer @@ -95,6 +91,7 @@ ObjectiveJFlattener.prototype.buildApplicationJS = function(applicationRoot) { buffer.push("console.log(ObjectiveJ.StaticResource.root);"); buffer.push("console.log(applicationRoot);"); + buffer.push("ObjectiveJ.bootstrap();"); buffer.push("})();"); return buffer.join("\n"); @@ -150,16 +147,24 @@ ObjectiveJFlattener.prototype.serializeStaticResources = function(node, depth) { this.resourceBuffer.push("currentNode = nodeStack.pop();"); } -function addApplicationScriptTag(indexHTMLPath) { +function rewriteMainHTML(indexHTMLPath) { var indexHTML = indexHTMLPath.read(); - // attempt to append the Application.js script tag after - var newIndexHTML = indexHTML.replace(/([ \t]+)]+Objective-J.js[^>]+>(?:\s*<\/script>)?/, - '$&\n$1'); + // "$1" is the matching indentation + var scriptTagsBefore = '$1'; + var scriptTagsAfter = '$1'; + + // attempt to find Objective-J script tag and add ours + var newIndexHTML = indexHTML.replace(/([ \t]+)]+Objective-J\.js[^>]+>(?:\s*<\/script>)?/, + scriptTagsBefore+'\n$&\n'+scriptTagsAfter); if (newIndexHTML === indexHTML) { - print("Unable to automatically add Application.js script tag."); + stream.print("\0yellow(Warning: Unable to automatically modify "+indexHTMLPath + "\0)"); + stream.print("\nAdd the following before the Objective-J script tag:"); + stream.print(scriptTagsBefore.replace(/\$1/g, " ")); + stream.print("\nAdd the following after the Objective-J script tag:"); + stream.print(scriptTagsAfter.replace(/\$1/g, " ")); + } else { + indexHTMLPath.write(newIndexHTML); } - - indexHTMLPath.write(newIndexHTML); } From 9ff73e5e63d8d11a774e34888c1bed8e56a0d4ce Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Tue, 23 Feb 2010 17:04:56 -0800 Subject: [PATCH 2/6] Make "capp" print usage if more than one file argument is given --- Tools/capp/Generate.j | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Tools/capp/Generate.j b/Tools/capp/Generate.j index bcdd07a47..b8097bcea 100644 --- a/Tools/capp/Generate.j +++ b/Tools/capp/Generate.j @@ -71,6 +71,11 @@ function gen(/*va_args*/) var args = ["capp gen"].concat(Array.prototype.slice.call(arguments)); var options = parser.parse(args); + if (options.args.length > 1) { + parser.printUsage(options); + OS.exit(1); + } + if (options.listTemplates) { listTemplates(); return; From 3da1c4381c4f635de1f286ec49441140ea3ed8f6 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Tue, 23 Feb 2010 18:06:23 -0800 Subject: [PATCH 3/6] Setup automated builds. --- Jakefile | 45 ++++++++++++++++++------- Tools/Scripts/ci.sh | 38 +++++++++++++++++++++ Tools/{ => Scripts}/githooks/pre-commit | 0 3 files changed, 71 insertions(+), 12 deletions(-) create mode 100755 Tools/Scripts/ci.sh rename Tools/{ => Scripts}/githooks/pre-commit (100%) diff --git a/Jakefile b/Jakefile index 4687216af..36a6da3eb 100644 --- a/Jakefile +++ b/Jakefile @@ -188,47 +188,68 @@ task("test-only", function() OS.exit(code); }); -task("push-packages", ["CommonJS", "push-cappuccino", "push-objective-j"]); +task("push-packages", ["push-cappuccino", "push-objective-j"]); task("push-cappuccino", function() { pushPackage( $BUILD_CJS_CAPPUCCINO, - "git@github.com:280north/cappuccino-package.git" + "git@github.com:280north/cappuccino-package.git", + SYSTEM.env["PACKAGE_BRANCH"] ); }); task("push-objective-j", function() { pushPackage( $BUILD_CJS_OBJECTIVE_J, - "git@github.com:280north/objective-j-package.git" + "git@github.com:280north/objective-j-package.git", + SYSTEM.env["PACKAGE_BRANCH"] ); }); -function pushPackage(path, remote) +function pushPackage(path, remote, branch) { - stream.print("Pushing \0blue(" + path + "\0) to \0blue(" + remote + "\0)"); + branch = branch || "master"; + + stream.print("Pushing \0blue(" + path + "\0) to "+branch+" of \0blue(" + remote + "\0)"); FILE.mkdirs(".push-package"); var pushPackageDir = FILE.join(".push-package", remote.replace(/[^\w]/g, "_")); if (FILE.exists(pushPackageDir)) - OS.system(buildCommandString([["cd", pushPackageDir], ["git", "pull"]])); + OS.system(buildCmd([["cd", pushPackageDir], ["git", "fetch"]])); else OS.system(["git", "clone", remote, pushPackageDir]); - OS.system("cd "+OS.enquote(pushPackageDir)+" && git rm --ignore-unmatch -r * && rm -rf *"); - OS.system("cp -R "+OS.enquote(path)+"/* "+OS.enquote(pushPackageDir)+"/."); + if (OS.system(buildCmd([["cd", pushPackageDir], ["git", "checkout", "origin/"+branch]]))) { + if (OS.system(buildCmd([ + ["cd", pushPackageDir], + ["git", "symbolic-ref", "HEAD", "refs/heads/"+branch], + ["rm", ".git/index"], + ["git", "clean", "-fdx"] + ]))) + throw "pushPackage failed"; + } - OS.system(buildCommandString([ + if (OS.system("cd "+OS.enquote(pushPackageDir)+" && git rm --ignore-unmatch -r * && rm -rf *")) + throw "pushPackage failed"; + if (OS.system("cp -R "+OS.enquote(path)+"/* "+OS.enquote(pushPackageDir)+"/.")) + throw "pushPackage failed"; + + OS.system(buildCmd([ ["cd", pushPackageDir], ["git", "add", "."], - ["git", "commit", "-m", "Pushed on " + new Date()], - ["git", "push", "origin", "master"] + ["git", "commit", "-m", "Pushed on " + new Date()] ])); + + if (OS.system(buildCmd([ + ["cd", pushPackageDir], + ["git", "push", "origin", "HEAD:"+branch] + ]))) + throw "pushPackage failed"; } -function buildCommandString(arrayOfCommands) +function buildCmd(arrayOfCommands) { return arrayOfCommands.map(function(cmd) { return cmd.map(OS.enquote).join(" "); diff --git a/Tools/Scripts/ci.sh b/Tools/Scripts/ci.sh new file mode 100755 index 000000000..4bc798a70 --- /dev/null +++ b/Tools/Scripts/ci.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +project_home="$(dirname "$PWD")" + +export PATH="$HOME/narwhal/bin:$PATH" + +export CAPP_BUILD=$project_home/build_incremental +time jake test +code=$? +if [ $code -ne 0 ]; then + echo "INCREMENTAL BUILD FAILED ($code)" + exit $code +else + echo "INCREMENTAL BUILD SUCCEEDED" +fi + +export CAPP_BUILD=$project_home/build_clean +rm -rf $CAPP_BUILD + +time jake CommonJS test +code=$? +if [ $code -ne 0 ]; then + echo "CLEAN BUILD FAILED ($code)" + exit $code +else + echo "CLEAN BUILD SUCCEEDED" +fi + +PACKAGE_BRANCH="nightly" jake push-packages +code=$? +if [ $code -ne 0 ]; then + echo "NIGHTLY BUILD PUSH FAILED ($code)" + exit $code +else + echo "NIGHTLY BUILD PUSH SUCCEEDED" +fi + +exit 0 \ No newline at end of file diff --git a/Tools/githooks/pre-commit b/Tools/Scripts/githooks/pre-commit similarity index 100% rename from Tools/githooks/pre-commit rename to Tools/Scripts/githooks/pre-commit From 3a1ebcaf3fd0f86b20e5bf43234c5dc75ed394e4 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Tue, 23 Feb 2010 20:07:17 -0800 Subject: [PATCH 4/6] Allow interleaved arguments in "capp gen" (requires latest Narwhal) --- Tools/capp/Generate.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/capp/Generate.j b/Tools/capp/Generate.j index b8097bcea..ce42fad38 100644 --- a/Tools/capp/Generate.j +++ b/Tools/capp/Generate.j @@ -69,7 +69,7 @@ var templatesDirectory = FILE.join(CAPP_HOME, "lib", "capp", "Resources", "Templ function gen(/*va_args*/) { var args = ["capp gen"].concat(Array.prototype.slice.call(arguments)); - var options = parser.parse(args); + var options = parser.parse(args, null, null, true); if (options.args.length > 1) { parser.printUsage(options); From f7a40a071b3ea885d16b7a9e1f59157d0958481e Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Wed, 24 Feb 2010 02:24:36 -0500 Subject: [PATCH 5/6] Added proper resize cursor support for CPSplitView and cleaned up some whitespace. --- AppKit/CPSplitView.j | 45 ++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/AppKit/CPSplitView.j b/AppKit/CPSplitView.j index 33d243f22..6974c25e0 100644 --- a/AppKit/CPSplitView.j +++ b/AppKit/CPSplitView.j @@ -75,9 +75,9 @@ var CPSplitViewHorizontalImage = nil, if (self = [super initWithFrame:aFrame]) { _currentDivider = CPNotFound; - + _DOMDividerElements = []; - + [self _setVertical:YES]; } @@ -102,9 +102,9 @@ var CPSplitViewHorizontalImage = nil, // Just re-adjust evenly. var frame = [self frame], dividerThickness = [self dividerThickness]; - + [self _postNotificationWillResize]; - + var eachSize = ROUND((frame.size[_sizeComponent] - dividerThickness * (_subviews.length - 1)) / _subviews.length), index = 0, count = _subviews.length; @@ -115,9 +115,9 @@ var CPSplitViewHorizontalImage = nil, else for (; index < count; ++index) [_subviews[index] setFrame:CGRectMake(0, ROUND((eachSize + dividerThickness) * index), frame.size.width, eachSize)]; - + [self setNeedsDisplay:YES]; - + [self _postNotificationDidResize]; } @@ -170,9 +170,9 @@ var CPSplitViewHorizontalImage = nil, { var frame = [_subviews[aDivider] frame], rect = CGRectMakeZero(); - + rect.size = [self frame].size; - + rect.size[_sizeComponent] = [self dividerThickness]; rect.origin[_originComponent] = frame.origin[_originComponent] + frame.size[_sizeComponent]; @@ -182,19 +182,19 @@ var CPSplitViewHorizontalImage = nil, - (CGRect)effectiveRectOfDividerAtIndex:(int)aDivider { var realRect = [self rectOfDividerAtIndex:aDivider]; - + var padding = 2; - + realRect.size[_sizeComponent] += padding * 2; realRect.origin[_originComponent] -= padding; - + return realRect; } - (void)drawRect:(CGRect)rect { var count = [_subviews count] - 1; - + while ((count--) > 0) { _drawingDivider = count; @@ -208,7 +208,12 @@ var CPSplitViewHorizontalImage = nil, if (!_DOMDividerElements[_drawingDivider]) { _DOMDividerElements[_drawingDivider] = document.createElement("div"); - _DOMDividerElements[_drawingDivider].style.cursor = "move"; + + if(_isVertical) + _DOMDividerElements[_drawingDivider].style.cursor = [[CPCursor resizeLeftRightCursor] _cssString]; + else + _DOMDividerElements[_drawingDivider].style.cursor = [[CPCursor resizeUpDownCursor] _cssString]; + _DOMDividerElements[_drawingDivider].style.position = "absolute"; _DOMDividerElements[_drawingDivider].style.backgroundRepeat = "repeat"; @@ -245,9 +250,9 @@ var CPSplitViewHorizontalImage = nil, { if (!_needsResizeSubviews) return; - + _needsResizeSubviews = NO; - + var subviews = [self subviews], count = subviews.length, oldSize = CGSizeMakeZero(); @@ -262,10 +267,10 @@ var CPSplitViewHorizontalImage = nil, oldSize.width = CGRectGetWidth([self frame]); oldSize.height += [self dividerThickness] * (count - 1); } - + while (count--) oldSize[_sizeComponent] += [subviews[count] frame].size[_sizeComponent]; - + [self resizeSubviewsWithOldSize:oldSize]; } @@ -278,7 +283,7 @@ var CPSplitViewHorizontalImage = nil, if ([_delegate respondsToSelector:@selector(splitView:effectiveRect:forDrawnRect:ofDividerAtIndex:)]) effectiveRect = [_delegate splitView:self effectiveRect:effectiveRect forDrawnRect:effectiveRect ofDividerAtIndex:anIndex]; - + if ([_delegate respondsToSelector:@selector(splitView:additionalEffectiveRectOfDividerAtIndex:)]) additionalRect = [_delegate splitView:self additionalEffectiveRectOfDividerAtIndex:anIndex]; @@ -289,9 +294,9 @@ var CPSplitViewHorizontalImage = nil, { if ([self isHidden] || ![self hitTests] || !CGRectContainsPoint([self frame], aPoint)) return nil; - + var point = [self convertPoint:aPoint fromView:[self superview]]; - + var count = [_subviews count] - 1; for (var i = 0; i < count; i++) { From 39f3e7b292c6ee8934dd3ed2f5d8428aad772ede Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Wed, 24 Feb 2010 02:56:38 -0800 Subject: [PATCH 6/6] Fix for menus not redrawing correctly after closing in non-Safari browsers. Closes #495. Reviewed by me. --- AppKit/CPMenu/CPMenu.j | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/AppKit/CPMenu/CPMenu.j b/AppKit/CPMenu/CPMenu.j index 940664f7a..2b3989af4 100644 --- a/AppKit/CPMenu/CPMenu.j +++ b/AppKit/CPMenu/CPMenu.j @@ -886,6 +886,13 @@ var _CPMenuBarVisible = NO, subtype:0 data1:0 data2:0]]; + + // FIXME: We need to do this because this happens in a limitDateForMode:, thus + // the second limitDateForMode: won't take effect and the perform selector that + // actually draws also won't go into effect. In Safari this works because it sends + // an additional mouse move after all this, but not in other browsers. + // This will be fixed correctly with the coming run loop changes. + [_CPDisplayServer run]; } /* @ignore */ @@ -980,13 +987,14 @@ var _CPMenuBarVisible = NO, */ - (void)_highlightItemAtIndex:(int)anIndex { - var previousHighlightedIndex = _highlightedIndex; - + if (_highlightedIndex === anIndex) + return; + + if (_highlightedIndex !== CPNotFound) + [[_items[_highlightedIndex] _menuItemView] highlight:NO]; + _highlightedIndex = anIndex; - - if (previousHighlightedIndex !== CPNotFound) - [[_items[previousHighlightedIndex] _menuItemView] highlight:NO]; - + if (_highlightedIndex !== CPNotFound) [[_items[_highlightedIndex] _menuItemView] highlight:YES]; }