Compare commits

...
11 Commits
11 changed files with 273 additions and 239 deletions
+4 -5
View File
@@ -860,12 +860,11 @@ CPRunContinuesResponse = -1002;
if ([windowController respondsToSelector:anAction]) if ([windowController respondsToSelector:anAction])
return windowController; return windowController;
var theDocument = [windowController document]; var theDocument = [windowController document];
if (theDocument !== delegate && [theDocument respondsToSelector:anAction])
if (theDocument != delegate && [theDocument respondsToSelector:anAction])
return theDocument; return theDocument;
return nil; return nil;
} }
@@ -1063,7 +1062,7 @@ CPRunContinuesResponse = -1002;
else if ([self mainWindow]) else if ([self mainWindow])
[[self mainWindow] makeKeyAndOrderFront:self]; [[self mainWindow] makeKeyAndOrderFront:self];
else else
[[[self mainMenu] window] makeKeyWindow]; //FIXME this may not actually work [[self mainMenu]._menuWindow makeKeyWindow]; //FIXME this may not actually work
_previousKeyWindow = nil; _previousKeyWindow = nil;
_previousMainWindow = nil; _previousMainWindow = nil;
+56 -80
View File
@@ -24,26 +24,10 @@
#include "Platform/Platform.h" #include "Platform/Platform.h"
/*! CPSearchFieldRecentsTitleMenuItemTag = 1000;
@global CPSearchFieldRecentsMenuItemTag = 1001;
@group Menu tags CPSearchFieldClearRecentsMenuItemTag = 1002;
*/ CPSearchFieldNoRecentsMenuItemTag = 1003;
CPSearchFieldRecentsTitleMenuItemTag = 1000;
/*!
@global
@group Menu tags
*/
CPSearchFieldRecentsMenuItemTag = 1001;
/*!
@global
@group Menu tags
*/
CPSearchFieldClearRecentsMenuItemTag = 1002;
/*!
@global
@group Menu tags
*/
CPSearchFieldNoRecentsMenuItemTag = 1003;
var CPSearchFieldSearchImage = nil, var CPSearchFieldSearchImage = nil,
CPSearchFieldFindImage = nil, CPSearchFieldFindImage = nil,
@@ -79,64 +63,49 @@ var CPSearchFieldSearchImage = nil,
return; return;
var bundle = [CPBundle bundleForClass:self]; var bundle = [CPBundle bundleForClass:self];
CPSearchFieldSearchImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSearchField/CPSearchFieldSearch.png"]]; CPSearchFieldSearchImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSearchField/CPSearchFieldSearch.png"] size:CGSizeMake(25, 22)];
CPSearchFieldFindImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSearchField/CPSearchFieldFind.png"]]; CPSearchFieldFindImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSearchField/CPSearchFieldFind.png"] size:CGSizeMake(25, 22)];
CPSearchFieldCancelImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSearchField/CPSearchFieldCancel.png"]]; CPSearchFieldCancelImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSearchField/CPSearchFieldCancel.png"] size:CGSizeMake(22, 22)];
CPSearchFieldCancelPressedImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSearchField/CPSearchFieldCancelPressed.png"]]; CPSearchFieldCancelPressedImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPSearchField/CPSearchFieldCancelPressed.png"] size:CGSizeMake(22, 22)];
} }
- (id)initWithFrame:(CPRect)frame - (id)initWithFrame:(CGRect)frame
{ {
self = [super initWithFrame:frame]; if (self = [super initWithFrame:frame])
if (self != nil)
{ {
_recentSearches = [CPArray array]; _recentSearches = [CPArray array];
_maximumRecents = 10; _maximumRecents = 10;
_sendsWholeSearchString = NO; _sendsWholeSearchString = NO;
_sendsSearchStringImmediately = NO; _sendsSearchStringImmediately = NO;
_recentsAutosaveName = nil; _recentsAutosaveName = nil;
[self setBezeled:YES];
[self setBezelStyle:CPTextFieldRoundedBezel];
[self setBordered:YES];
[self setEditable:YES];
[self setDelegate:self];
_cancelButton = [[CPButton alloc] initWithFrame:CPMakeRect(frame.size.width - 27,(frame.size.height-22)/2,22,22)];
[self resetCancelButton];
[_cancelButton setHidden:YES];
[_cancelButton setAutoresizingMask:CPViewMinXMargin];
[self addSubview:_cancelButton];
_searchButton = [[CPButton alloc] initWithFrame:CPMakeRect(5,(frame.size.height-25)/2,25,25)];
[self resetSearchButton];
[self addSubview:_searchButton];
[self _initWithFrame:frame];
#if PLATFORM(DOM) #if PLATFORM(DOM)
_cancelButton._DOMElement.style.cursor = "default"; _cancelButton._DOMElement.style.cursor = "default";
_searchButton._DOMElement.style.cursor = "default"; _searchButton._DOMElement.style.cursor = "default";
#endif #endif
} }
return self; return self;
} }
- (id)copy - (void)_initWithFrame:(CGRect)frame
{ {
var copy = [super copy]; [self setBezeled:YES];
[self setBezelStyle:CPTextFieldRoundedBezel];
[self setBordered:YES];
[self setEditable:YES];
[self setDelegate:self];
[copy setCancelButton:[_cancelButton copy]]; _cancelButton = [[CPButton alloc] initWithFrame:CGRectMake(frame.size.width - 27,(frame.size.height-22)/2,22,22)];
[copy setSearchButton:[_searchButton copy]]; [self resetCancelButton];
[copy setSendsWholeSearchString:[_sendsWholeSearchString copy]]; [_cancelButton setHidden:YES];
[copy setSendsSearchStringImmediately:[_sendsSearchStringImmediately copy]]; [_cancelButton setAutoresizingMask:CPViewMinXMargin];
[copy setMaximumRecents:_maximumRecents]; [self addSubview:_cancelButton];
if (_recentsAutosaveName)
[copy setrecentsAutosaveName:[_recentsAutosaveName copy]];
if (_searchMenuTemplate)
[copy setSearchMenutemplate:[_searchMenuTemplate copy]];
return copy; _searchButton = [[CPButton alloc] initWithFrame:CGRectMake(5,(frame.size.height-25)/2,25,25)];
[self resetSearchButton];
[self addSubview:_searchButton];
} }
// Managing Buttons // Managing Buttons
@@ -695,9 +664,7 @@ var CPSearchFieldSearchImage = nil,
@end @end
var CPSearchButtonKey = @"CPSearchButtonKey", var CPRecentsAutosaveNameKey = @"CPRecentsAutosaveNameKey",
CPCancelButtonKey = @"CPCancelButtonKey",
CPRecentsAutosaveNameKey = @"CPRecentsAutosaveNameKey",
CPSendsWholeSearchStringKey = @"CPSendsWholeSearchStringKey", CPSendsWholeSearchStringKey = @"CPSendsWholeSearchStringKey",
CPSendsSearchStringImmediatelyKey = @"CPSendsSearchStringImmediatelyKey", CPSendsSearchStringImmediatelyKey = @"CPSendsSearchStringImmediatelyKey",
CPMaximumRecentsKey = @"CPMaximumRecentsKey", CPMaximumRecentsKey = @"CPMaximumRecentsKey",
@@ -707,13 +674,20 @@ var CPSearchButtonKey = @"CPSearchButtonKey",
- (void)encodeWithCoder:(CPCoder)coder - (void)encodeWithCoder:(CPCoder)coder
{ {
[super encodeWithCoder:coder]; [_searchButton removeFromSuperview];
[_cancelButton removeFromSuperview];
[coder encodeObject:_searchButton forKey:CPSearchButtonKey];
[coder encodeObject:_cancelButton forKey:CPCancelButtonKey]; [super encodeWithCoder:coder];
if (_searchButton)
[self addSubview:_searchButton];
if (_cancelButton)
[self addSubview:_cancelButton];
[coder encodeBool:_sendsWholeSearchString forKey:CPSendsWholeSearchStringKey]; [coder encodeBool:_sendsWholeSearchString forKey:CPSendsWholeSearchStringKey];
[coder encodeBool:_sendsSearchStringImmediately forKey:CPSendsSearchStringImmediatelyKey]; [coder encodeBool:_sendsSearchStringImmediately forKey:CPSendsSearchStringImmediatelyKey];
[coder encodeInt:_maximumRecents forKey:CPMaximumRecentsKey]; [coder encodeInt:_maximumRecents forKey:CPMaximumRecentsKey];
if (_recentsAutosaveName) if (_recentsAutosaveName)
[coder encodeObject:_recentsAutosaveName forKey:CPRecentsAutosaveNameKey]; [coder encodeObject:_recentsAutosaveName forKey:CPRecentsAutosaveNameKey];
if (_searchMenuTemplate) if (_searchMenuTemplate)
@@ -722,21 +696,23 @@ var CPSearchButtonKey = @"CPSearchButtonKey",
- (id)initWithCoder:(CPCoder)coder - (id)initWithCoder:(CPCoder)coder
{ {
self = [super initWithCoder:coder]; if (self = [super initWithCoder:coder])
{
_searchButton = [coder decodeObjectForKey:CPSearchButtonKey]; [self _initWithFrame:[self frame]];
_cancelButton = [coder decodeObjectForKey:CPCancelButtonKey];
_recentsAutosaveName = [coder decodeObjectForKey:CPRecentsAutosaveNameKey]; _recentsAutosaveName = [coder decodeObjectForKey:CPRecentsAutosaveNameKey];
_sendsWholeSearchString = [coder decodeBoolForKey:CPSendsWholeSearchStringKey]; _sendsWholeSearchString = [coder decodeBoolForKey:CPSendsWholeSearchStringKey];
_sendsSearchStringImmediately = [coder decodeBoolForKey:CPSendsSearchStringImmediatelyKey]; _sendsSearchStringImmediately = [coder decodeBoolForKey:CPSendsSearchStringImmediatelyKey];
_maximumRecents = [coder decodeIntForKey:CPMaximumRecentsKey]; _maximumRecents = [coder decodeIntForKey:CPMaximumRecentsKey];
var template = [coder decodeObjectForKey:CPSearchMenuTemplateKey];
if (template) var template = [coder decodeObjectForKey:CPSearchMenuTemplateKey];
[self setSearchMenuTemplate:template]; if (template)
[self setSearchMenuTemplate:template];
[self setDelegate:self];
[self setDelegate:self];
}
return self; return self;
} }
@end @end
+15 -17
View File
@@ -160,21 +160,24 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
CPTableView _tableView @accessors(property=tableView); CPTableView _tableView @accessors(property=tableView);
} }
- (void)initWithFrame:(CGRect)aFrame - (void)_init
{
_resizedColumn = -1;
_draggedColumn = -1;
_pressedColumn = -1;
_draggedDistance = 0.0;
_lastLocation = nil;
_columnOldWidth = nil;
[self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview.png", CGSizeMake(1.0, 22.0))]];
}
- (id)initWithFrame:(CGRect)aFrame
{ {
self = [super initWithFrame:aFrame]; self = [super initWithFrame:aFrame];
if (self) if (self)
{ [self _init];
_resizedColumn = -1;
_draggedColumn = -1;
_pressedColumn = -1;
_draggedDistance = 0.0;
_lastLocation = nil;
_columnOldWidth = nil;
[self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview.png", CGSizeMake(1.0, 22.0))]];
}
return self; return self;
} }
@@ -481,12 +484,7 @@ var CPTableHeaderViewTableViewKey = @"CPTableHeaderViewTableViewKey";
{ {
if (self = [super initWithCoder:aCoder]) if (self = [super initWithCoder:aCoder])
{ {
_resizedColumn = -1; [self _init];
_draggedColumn = -1;
_pressedColumn = -1;
_draggedDistance = 0.0;
_lastLocation = nil;
_columnOldWidth = nil;
_tableView = [aCoder decodeObjectForKey:CPTableHeaderViewTableViewKey]; _tableView = [aCoder decodeObjectForKey:CPTableHeaderViewTableViewKey];
} }
+5 -1
View File
@@ -194,6 +194,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
SEL _doubleAction; SEL _doubleAction;
unsigned _columnAutoResizingStyle; unsigned _columnAutoResizingStyle;
int _lastTrackedRowIndex;
CGPoint _originalMouseDownPoint; CGPoint _originalMouseDownPoint;
BOOL _verticalMotionCanDrag; BOOL _verticalMotionCanDrag;
unsigned _destinationDragStyle; unsigned _destinationDragStyle;
@@ -2654,8 +2655,11 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
} }
_isSelectingSession = YES; _isSelectingSession = YES;
if(row >= 0) if(row >= 0 && row !== _lastTrackedRowIndex)
{
_lastTrackedRowIndex = row;
[self _updateSelectionWithMouseAtRow:row]; [self _updateSelectionWithMouseAtRow:row];
}
if ((_implementedDataSourceMethods & CPTableViewDataSource_tableView_setObjectValue_forTableColumn_row_) if ((_implementedDataSourceMethods & CPTableViewDataSource_tableView_setObjectValue_forTableColumn_row_)
&& !_trackingPointMovedOutOfClickSlop) && !_trackingPointMovedOutOfClickSlop)
+5 -7
View File
@@ -1497,7 +1497,8 @@ CPTexturedBackgroundWindowMask
if (_firstResponder != self && [_firstResponder respondsToSelector:@selector(resignKeyWindow)]) if (_firstResponder != self && [_firstResponder respondsToSelector:@selector(resignKeyWindow)])
[_firstResponder resignKeyWindow]; [_firstResponder resignKeyWindow];
CPApp._keyWindow = nil; if (CPApp._keyWindow === self)
CPApp._keyWindow = nil;
[[CPNotificationCenter defaultCenter] [[CPNotificationCenter defaultCenter]
postNotificationName:CPWindowDidResignKeyNotification postNotificationName:CPWindowDidResignKeyNotification
@@ -1858,7 +1859,8 @@ CPTexturedBackgroundWindowMask
postNotificationName:CPWindowDidResignMainNotification postNotificationName:CPWindowDidResignMainNotification
object:self]; object:self];
CPApp._mainWindow = nil; if (CPApp._mainWindow === self)
CPApp._mainWindow = nil;
} }
- (void)_updateMainAndKeyWindows - (void)_updateMainAndKeyWindows
@@ -1866,9 +1868,6 @@ CPTexturedBackgroundWindowMask
var allWindows = [CPApp orderedWindows], var allWindows = [CPApp orderedWindows],
windowCount = [allWindows count]; windowCount = [allWindows count];
if (!windowCount)
return;
if ([self isKeyWindow]) if ([self isKeyWindow])
{ {
var keyWindow = [CPApp keyWindow]; var keyWindow = [CPApp keyWindow];
@@ -1893,11 +1892,10 @@ CPTexturedBackgroundWindowMask
} }
if (![CPApp keyWindow]) if (![CPApp keyWindow])
[keyWindow makeKeyWindow]; [menuWindow makeKeyWindow];
} }
} }
if ([self isMainWindow]) if ([self isMainWindow])
{ {
var mainWindow = [CPApp mainWindow]; var mainWindow = [CPApp mainWindow];
+93 -93
View File
@@ -87,22 +87,7 @@ function main(args)
flattener.load(mainPath); flattener.load(mainPath);
flattener.finishLoading(); flattener.finishLoading();
var rootResources = flattener.require("objective-j").StaticResource.rootResources(); var applicationJS = flattener.buildApplicationJS();
var root = rootResources["file:"];
// FIXME: shouldn't have to do this manually
var components = rootPath.split("/").slice(0, -1);
components[0] = "/";
var node = root;
while (components.length) {
node = node.children()[components.shift()];
}
applicationRoot = node;
print(applicationRoot.toString());
var applicationJS = flattener.buildApplicationJS(applicationRoot);
FILE.copyTree(rootPath, outputPath); FILE.copyTree(rootPath, outputPath);
@@ -115,7 +100,9 @@ function main(args)
function ObjectiveJFlattener(rootPath) { function ObjectiveJFlattener(rootPath) {
ObjectiveJRuntimeAnalyzer.apply(this, arguments); ObjectiveJRuntimeAnalyzer.apply(this, arguments);
this.resourceBuffer = []; this.fileCacheBuffer = [];
this.staticResourceBuffer = [];
this.bundleBuffer = []; this.bundleBuffer = [];
this.functionsBuffer = []; this.functionsBuffer = [];
@@ -124,105 +111,118 @@ function ObjectiveJFlattener(rootPath) {
ObjectiveJFlattener.prototype = Object.create(ObjectiveJRuntimeAnalyzer.prototype); ObjectiveJFlattener.prototype = Object.create(ObjectiveJRuntimeAnalyzer.prototype);
ObjectiveJFlattener.prototype.buildApplicationJS = function(applicationRoot) { ObjectiveJFlattener.prototype.buildApplicationJS = function() {
this.serializeStaticResources(applicationRoot);
this.serializeStaticFileExecutables();
var buffer = [] this.serializeFunctions();
this.serializeFileCache();
buffer.push("(function(){"); var buffer = [];
buffer.push("var appURL = new CFURL('.', ObjectiveJ.pageURL);")
buffer.push(this.bundleBuffer.join("\n"));
buffer.push("var nodeStack = [];");
buffer.push("var applicationRoot = ObjectiveJ.StaticResource.resourceAtURL(appURL, true);");
buffer.push("var currentNode = null;");
buffer.push("var newNode;");
buffer.push(this.resourceBuffer.join("\n"));
buffer.push("})();");
buffer.push("var baseURL = new CFURL(\".\", ObjectiveJ.pageURL);");
buffer.push(this.fileCacheBuffer.join("\n"))
buffer.push(this.functionsBuffer.join("\n")); buffer.push(this.functionsBuffer.join("\n"));
buffer.push("ObjectiveJ.bootstrap();"); buffer.push("ObjectiveJ.bootstrap();");
return buffer.join("\n"); return buffer.join("\n");
} }
ObjectiveJFlattener.prototype.serializeStaticFileExecutables = function() { ObjectiveJFlattener.prototype.serializeFunctions = function() {
this.require("objective-j").FileExecutable.allFileExecutables().forEach(function(aFileExecutable) { var inlineFunctions = true;//this.options.inlineFunctions;
var deps = aFileExecutable.fileDependencies().map(function(dependency) {
return "new ObjectiveJ.FileDependency(new CFURL("+JSON.stringify(dependency.path())+"),"+JSON.stringify(dependency.isLocal())+")"
}).join(",");
var func = aFileExecutable._function.toString(); var outputFiles = {};
// HACK
func = func.replace(", require, exports, module, system, print, window", "");
this.functionsBuffer.push("var path = "+JSON.stringify(this.rootPath.relative(aFileExecutable.path()).toString())+";"); var _cachedExecutableFunctions = {};
this.functionsBuffer.push("new ObjectiveJ.FileExecutable(path,"+
"new ObjectiveJ.Executable(null, ["+deps+"], path, "+func+"));"); this.require("objective-j").FileExecutable.allFileExecutables().forEach(function(executable) {
var path = executable.path();
if (inlineFunctions)
{
// stringify the function, replacing arguments
var functionString = executable._function.toString().replace(", require, exports, module, system, print, window", ""); // HACK
var relative = this.rootPath.relative(path).toString();
this.functionsBuffer.push("ObjectiveJ.FileExecutable._cacheFunction(new CFURL("+JSON.stringify(relative)+", baseURL), "+functionString+");");
}
var bundle = this.context.global.CFBundle.bundleContainingURL(path);
if (bundle && bundle.infoDictionary())
{
var executablePath = bundle.executablePath(),
relativeToBundle = FILE.relative(FILE.join(bundle.path(), ""), path);
if (executablePath)
{
if (inlineFunctions)
{
// remove the code since we're inlining the functions
executable._code = "alert("+JSON.stringify(relativeToBundle)+");";
}
if (!outputFiles[executablePath])
{
outputFiles[executablePath] = [];
outputFiles[executablePath].push("@STATIC;1.0;");
}
var fileContents = executable.toMarkedString();
outputFiles[executablePath].push("p;" + relativeToBundle.length + ";" + relativeToBundle);
outputFiles[executablePath].push("t;" + fileContents.length + ";" + fileContents);
// stream.print("Adding \0green(" + this.rootPath.relative(path) + "\0) to \0cyan(" + this.rootPath.relative(executablePath) + "\0)");
}
}
else
CPLog.warn("No bundle (or info dictionary for) " + rootPath.relative(path));
}, this); }, this);
for (var executablePath in outputFiles)
{
var relative = this.rootPath.relative(executablePath).toString();
var contents = outputFiles[executablePath].join("");
this.fileCacheBuffer.push("CFHTTPRequest._cacheRequest(new CFURL("+JSON.stringify(relative)+", baseURL), 200, {}, "+JSON.stringify(contents)+");");
}
} }
ObjectiveJFlattener.prototype.serializeStaticResources = function(node, depth) { ObjectiveJFlattener.prototype.serializeFileCache = function() {
depth = depth || 0; Object.keys(this.requestedURLs).forEach(function(absolute) {
var relative = this.rootPath.relative(absolute).toString();
var bundle = this.context.global.CFBundle.bundleContainingURL(node.URL()); if (relative.indexOf("..") === 0)
if (!bundle) { {
stream.print("\0yellow(Warning:\0) No bundle for path: \0cyan("+node.URL()+"\0)"); print("skipping (parent of app root): " + absolute);
} return;
else if (!this._outputBundles[bundle.path()]) {
this._outputBundles[bundle.path()] = bundle;
stream.print("Writing bundle: \0cyan("+bundle.path()+"\0)");
print(bundle.infoDictionary())
var relative = this.rootPath.relative(bundle.path()).toString();
this.bundleBuffer.push("var bundle = new CFBundle("+(relative ? JSON.stringify(relative) : "appURL")+");");
this.bundleBuffer.push("bundle._loadStatus = " + (1<<4) + ";");
if (bundle.infoDictionary()) {
this.bundleBuffer.push("bundle._infoDictionary = CFPropertyList.propertyListFromString(" +
JSON.stringify(CPPropertyListCreateData(bundle.infoDictionary()).rawString()) + ");");
} }
}
// not the root node: if (FILE.isFile(absolute))
if (depth > 0) { {
this.resourceBuffer.push("newNode = new ObjectiveJ.StaticResource(" + if (FILE.extension(absolute) === ".sj")
JSON.stringify(node.name()) + {
", currentNode, " + print("skipping (bundle executable): " + absolute);
JSON.stringify(node.isDirectory()) + ", " + return;
JSON.stringify(node.isResolved()) + ");"); }
} else { // if (this.options.maxCachedSize && FILE.size(absolute) > this.options.maxCachedSize)
this.resourceBuffer.push("newNode = applicationRoot;"); // {
} // print("skipping (larger than "+this.options.maxCachedSize+" bytes): " + absolute);
// return;
// }
// var contents = node.contents(); print("caching: " + absolute);
// if (contents) { var contents = FILE.read(absolute, { charset : "UTF-8" });
// this.resourceBuffer.push("newNode._contents = " + JSON.stringify(contents) + ";"); this.fileCacheBuffer.push("CFHTTPRequest._cacheRequest(new CFURL("+JSON.stringify(relative)+", baseURL), 200, {}, "+JSON.stringify(contents)+");");
// } } else {
this.fileCacheBuffer.push("CFHTTPRequest._cacheRequest(new CFURL("+JSON.stringify(relative)+", baseURL), 404);");
if (!node.children()) }
return; }, this);
this.resourceBuffer.push("nodeStack.push(currentNode);");
this.resourceBuffer.push("currentNode = newNode;");
var children = node.children();
for (var name in children) {
this.serializeStaticResources(children[name], depth+1);
}
this.resourceBuffer.push("currentNode = nodeStack.pop();");
} }
// "$1" is the matching indentation // "$1" is the matching indentation
var scriptTagsBefore = '$1<script type = "text/javascript">\n$1 OBJJ_AUTO_BOOTSTRAP = false;\n$1</script>'; var scriptTagsBefore = '$1<script type = "text/javascript">\n$1 OBJJ_AUTO_BOOTSTRAP = false;\n$1</script>';
var scriptTagsAfter = '$1<script type = "text/javascript" src = "Application.js"></script>'; var scriptTagsAfter = '$1<script type = "text/javascript" src = "Application.js"></script>';
// enable CPLog:
// scriptTagsAfter = '$1<script type = "text/javascript">\n$1 CPLogRegister(CPLogConsole);\n$1</script>\n' + scriptTagsAfter;
function rewriteMainHTML(indexHTMLPath) { function rewriteMainHTML(indexHTMLPath) {
if (indexHTMLPath.isFile()) { if (indexHTMLPath.isFile()) {
var indexHTML = indexHTMLPath.read(); var indexHTML = indexHTMLPath.read();
@@ -5,6 +5,8 @@ var Context = require("interpreter").Context;
ObjectiveJRuntimeAnalyzer = function(rootPath) ObjectiveJRuntimeAnalyzer = function(rootPath)
{ {
this.rootPath = rootPath; this.rootPath = rootPath;
this.rootURL = new CFURL(String(rootPath));
this.context = new Context(); this.context = new Context();
this.scope = setupObjectiveJ(this.context); this.scope = setupObjectiveJ(this.context);
@@ -28,6 +30,14 @@ ObjectiveJRuntimeAnalyzer = function(rootPath)
var url = this.executableURL(); var url = this.executableURL();
return url ? url.absoluteURL().path() : null; return url ? url.absoluteURL().path() : null;
} }
var requestedURLs = this.requestedURLs = {};
var _lookupCachedRequest = this.context.global.CFHTTPRequest._lookupCachedRequest;
this.context.global.CFHTTPRequest._lookupCachedRequest = function(aURL) {
var path = new CFURL(aURL, this.rootURL).absoluteURL().path();
requestedURLs[path] = true;
return _lookupCachedRequest.apply(null, arguments);
}
} }
ObjectiveJRuntimeAnalyzer.prototype.setIncludePaths = function(includePaths) { ObjectiveJRuntimeAnalyzer.prototype.setIncludePaths = function(includePaths) {
+62 -27
View File
@@ -196,9 +196,14 @@ CFHTTPRequest.prototype.overrideMimeType = function(/*String*/ aMimeType)
return this._nativeRequest.overrideMimeType(aMimeType); return this._nativeRequest.overrideMimeType(aMimeType);
} }
CFHTTPRequest.prototype.open = function(/*...*/) CFHTTPRequest.prototype.open = function(/*String*/ method, /*String*/ url, /*Boolean*/ async, /*String*/ user, /*String*/ password)
{ {
return this._nativeRequest.open(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]); var cachedRequest = CFHTTPRequest._lookupCachedRequest(url);
if (cachedRequest) {
cachedRequest.onreadystatechange = this._nativeRequest.onreadystatechange;
this._nativeRequest = cachedRequest;
}
return this._nativeRequest.open(method, url, async, user, password);
} }
CFHTTPRequest.prototype.send = function(/*Object*/ aBody) CFHTTPRequest.prototype.send = function(/*Object*/ aBody)
@@ -254,43 +259,73 @@ function determineAndDispatchHTTPRequestEvents(/*CFHTTPRequest*/ aRequest)
function FileRequest(/*CFURL*/ aURL, onsuccess, onfailure) function FileRequest(/*CFURL*/ aURL, onsuccess, onfailure)
{ {
#ifdef BROWSER
var request = new CFHTTPRequest(); var request = new CFHTTPRequest();
request.onsuccess = Asynchronous(onsuccess);
request.onfailure = Asynchronous(onfailure);
if (aURL.pathExtension() === "plist") if (aURL.pathExtension() === "plist")
request.overrideMimeType("text/xml"); request.overrideMimeType("text/xml");
request.open("GET", aURL.absoluteString(), YES); if (FileRequest.async)
{
request.onsuccess = Asynchronous(onsuccess);
request.onfailure = Asynchronous(onfailure);
}
else
{
request.onsuccess = onsuccess;
request.onfailure = onfailure;
}
request.open("GET", aURL.absoluteString(), FileRequest.async);
request.send(""); request.send("");
}
#ifdef BROWSER
FileRequest.async = YES;
#else #else
var FILE = require("file"), FileRequest.async = NO;
filePath = aURL.absoluteURL().path();
if (!FILE.exists(filePath))
return onfailure();
this._responseText = FILE.read(filePath, { charset:"UTF-8" });
onsuccess({ type:"success", request:this });
#endif #endif
var URLCache = { };
CFHTTPRequest._cacheRequest = function(/*CFURL|String*/ aURL, /*Number*/ status, /*Object*/ headers, /*String*/ body)
{
aURL = typeof aURL === "string" ? aURL : aURL.absoluteString();
URLCache[aURL] = new MockXMLHttpRequest(status, headers, body);
} }
#ifdef COMMONJS CFHTTPRequest._lookupCachedRequest = function(/*CFURL|String*/ aURL)
FileRequest.prototype.responseText = function()
{ {
return this._responseText; aURL = typeof aURL === "string" ? aURL : aURL.absoluteString();
return URLCache[aURL];
} }
FileRequest.prototype.responseXML = function() function MockXMLHttpRequest(status, headers, body)
{ {
return new DOMParser().parseFromString(anXMLString, "text/xml"); this.readyState = CFHTTPRequest.UninitializedState;
} this.status = status || 200;
this.statusText = "";
FileRequest.prototype.responsePropertyList = function() this.responseText = body || "";
this._responseHeaders = headers || {};
};
MockXMLHttpRequest.prototype.open = function(method, url, async, user, password)
{ {
return CFPropertyList.propertyListFromString(this.responseText()); this.readyState = CFHTTPRequest.LoadingState;
} this.async = async;
#endif };
MockXMLHttpRequest.prototype.send = function(body)
{
var self = this;
self.responseText = self.responseText.toString();
function complete() {
for (self.readyState = CFHTTPRequest.LoadedState; self.readyState <= CFHTTPRequest.CompleteState; self.readyState++)
self.onreadystatechange();
}
(self.async ? Asynchronous(complete) : complete)();
};
MockXMLHttpRequest.prototype.onreadystatechange = function() {};
MockXMLHttpRequest.prototype.abort = function() {};
MockXMLHttpRequest.prototype.setRequestHeader = function(header, value) {};
MockXMLHttpRequest.prototype.getAllResponseHeaders = function() { return this._responseHeaders; };
MockXMLHttpRequest.prototype.getResponseHeader = function(header) { return this._responseHeaders[header]; };
MockXMLHttpRequest.prototype.overrideMimeType = function(mimetype) {};
+20 -5
View File
@@ -22,7 +22,7 @@
var FileExecutablesForURLStrings = { }; var FileExecutablesForURLStrings = { };
function FileExecutable(/*CFURL|String*/ aURL, /*Executable*/ anExecutable) function FileExecutable(/*CFURL|String*/ aURL)
{ {
aURL = makeAbsoluteURL(aURL); aURL = makeAbsoluteURL(aURL);
@@ -38,10 +38,7 @@ function FileExecutable(/*CFURL|String*/ aURL, /*Executable*/ anExecutable)
executable = NULL, executable = NULL,
extension = aURL.pathExtension(); extension = aURL.pathExtension();
if (anExecutable) if (fileContents.match(/^@STATIC;/))
executable = anExecutable;
else if (fileContents.match(/^@STATIC;/))
executable = decompile(fileContents, aURL); executable = decompile(fileContents, aURL);
else if (extension === "j" || !extension) else if (extension === "j" || !extension)
@@ -117,5 +114,23 @@ function decompile(/*String*/ aString, /*CFURL*/ aURL)
dependencies.push(new FileDependency(new CFURL(text), YES)); dependencies.push(new FileDependency(new CFURL(text), YES));
} }
var fn = FileExecutable._lookupCachedFunction(aURL)
if (fn)
return new Executable(code, dependencies, aURL, fn);
return new Executable(code, dependencies, aURL); return new Executable(code, dependencies, aURL);
} }
var FunctionCache = { };
FileExecutable._cacheFunction = function(/*CFURL|String*/ aURL, /*Function*/ fn)
{
aURL = typeof aURL === "string" ? aURL : aURL.absoluteString();
FunctionCache[aURL] = fn;
}
FileExecutable._lookupCachedFunction = function(/*CFURL|String*/ aURL)
{
aURL = typeof aURL === "string" ? aURL : aURL.absoluteString();
return FunctionCache[aURL];
}
+3 -1
View File
@@ -45,7 +45,9 @@
- (id)initWithCoder:(CPCoder)aCoder - (id)initWithCoder:(CPCoder)aCoder
{ {
return [self NS_initWithCoder:aCoder]; self = [self NS_initWithCoder:aCoder];
return self;
} }
- (Class)classForKeyedArchiver - (Class)classForKeyedArchiver
-3
View File
@@ -27,10 +27,7 @@
- (id)NS_initWithCoder:(CPCoder)aCoder - (id)NS_initWithCoder:(CPCoder)aCoder
{ {
if (self = [super NS_initWithCoder:aCoder]) if (self = [super NS_initWithCoder:aCoder])
{
_tableView = [aCoder decodeObjectForKey:"NSTableView"]; _tableView = [aCoder decodeObjectForKey:"NSTableView"];
[self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview.png", CGSizeMake(1.0, 22.0))]];
}
return self; return self;
} }