Support for blends.

Reviewed by me.
This commit is contained in:
Francisco Tolmasky
2009-03-16 17:00:02 -07:00
parent 6d34f53e43
commit 0a32d13cb0
3 changed files with 87 additions and 3 deletions
+16
View File
@@ -739,7 +739,23 @@ var _CPRunModalLoop = function(anEvent)
@class CPApplication
@return void
*/
@implementation X : CPObject
{
}
- (void)blendDidFinishLoading:(CPBundle)aBundle
{
[CPTheme setDefaultTheme:[CPTheme themeNamed:@"Aristo"]];
_CPApplicationMain()
}
@end
function CPApplicationMain(args, namedArgs)
{
var blend = [[CPBlend alloc] initWithContentsOfURL:[[CPBundle bundleForClass:[CPApplication class]] pathForResource:@"Aristo.blend"]];
[blend loadWithDelegate:[X new]];
}
function _CPApplicationMain(args, namedArgs)
{
var mainBundle = [CPBundle mainBundle],
principalClass = [mainBundle principalClass];
+54
View File
@@ -27,6 +27,60 @@
@import "CPThemedAttribute.j"
@implementation CPBlend : CPObject
{
CPBundle _bundle;
CPArray _themes @accessors(readonly);
id _loadDelegate;
}
- (id)initWithContentsOfURL:(CPURL)aURL
{
self = [super init];
if (self)
{
_bundle = [[CPBundle alloc] initWithPath:aURL + "/Info.plist"];
}
return self;
}
- (void)loadWithDelegate:(id)aDelegate
{
_loadDelegate = aDelegate;
[_bundle loadWithDelegate:self];
}
- (void)bundleDidFinishLoading:(CPBundle)aBundle
{
var paths = [_bundle objectForInfoDictionaryKey:@"CPBundleReplacedFiles"],
index = 0,
count = paths.length,
bundlePath = [_bundle bundlePath];
while (count--)
{
var path = paths[count];
if ([path pathExtension] === "keyedtheme")
{
var unarchiver = [[_CPThemeKeyedUnarchiver alloc]
initForReadingWithData:[CPData dataWithString:objj_files[bundlePath + '/' + path].contents]
bundle:_bundle];
[unarchiver decodeObjectForKey:@"root"];
[unarchiver finishDecoding];
}
}
[_loadDelegate blendDidFinishLoading:self];
}
@end
var CPThemesByName = nil,
CPThemeDefaultTheme = nil,
+17 -3
View File
@@ -129,15 +129,29 @@
context.didCompleteCallback = function() { [_delegate bundleDidFinishLoading:self]; };
var files = [self objectForInfoDictionaryKey:@"CPBundleReplacedFiles"],
count = files.length;
count = files.length,
bundlePath = [self bundlePath];
while (count--)
context.pushFragment(fragment_create_file([self bundlePath] + '/' + files[count], new objj_bundle(""), YES, NULL));
{
var fileName = files[count];
if (fileName.indexOf(".j") === fileName.length - 2)
context.pushFragment(fragment_create_file(bundlePath + '/' + fileName, new objj_bundle(""), YES, NULL));
}
context.evaluate();
if (context.fragments.length)
context.evaluate();
else
[_delegate bundleDidFinishLoading:self];
}
}
- (void)connection:(CPURLConnection)aConnection didFailWithError:(CPError)anError
{
alert("what the hell!?!!!" + anError)
}
- (void)connectionDidFinishLoading:(CPURLConnection)aConnection
{
}