Add facility for running specs… still don't have any yet.

Use property accessors instead of raw ivars.
This commit is contained in:
Corey Johnson & Nathan Sobo
2011-12-12 13:04:46 -08:00
parent 0d61a0f14f
commit 5daabb3241
5 changed files with 58 additions and 24 deletions

View File

@@ -12,7 +12,7 @@
@synthesize controllers;
- (AtomController *)createController:(NSString *)path {
AtomController *controller = [[AtomController alloc] initWithURL:path];
AtomController *controller = [(AtomController *)[AtomController alloc] initWithURL:path];
[controllers addObject:controller];
return controller;
@@ -23,6 +23,11 @@
[controller.jscocoa callJSFunctionNamed:@"triggerEvent" withArguments:@"window:close", nil, false, nil];
}
- (void)runSpecs {
AtomController *controller = [(AtomController *)[AtomController alloc] initForSpecs];
[controllers addObject:controller];
}
- (void)reloadController:(AtomController *)controller {
CGRect frame = [[controller window] frame];
AtomController *newController = [self createController:controller.url];
@@ -55,10 +60,10 @@
[super sendEvent:event];
return;
}
BOOL handeled = NO;
AtomController *controller = [[self keyWindow] windowController];
// The keyWindow could be a Cocoa Dialog or something, ignore those.
if ([controller isKindOfClass:[AtomController class]]) {
// cmd-r should always reload the current controller, so it needs to be here
@@ -66,6 +71,10 @@
[self reloadController:controller];
handeled = YES;
}
else if ([event modifierFlags] & (NSAlternateKeyMask | NSControlKeyMask | NSCommandKeyMask) && [[event charactersIgnoringModifiers] hasPrefix:@"s"]) {
[self runSpecs];
handeled = YES;
}
else {
JSValueRef value = [controller.jscocoa callJSFunctionNamed:@"handleKeyEvent" withArguments:event, nil];
handeled = [controller.jscocoa toBool:value];

View File

@@ -7,9 +7,12 @@
}
@property (retain) WebView *webView;
@property (retain, readonly) NSString *url;
@property (retain) JSCocoa *jscocoa;
@property (nonatomic, retain) JSCocoa *jscocoa;
@property (nonatomic, retain, readonly) NSString *url;
@property (nonatomic, retain, readonly) NSString *bootstrapPage;
- (id)initForSpecs;
- (AtomController *)initWithURL:(NSString *)url;
@end

View File

@@ -2,54 +2,75 @@
#import "AtomApp.h"
#import "JSCocoa.h"
#import <WebKit/WebKit.h>
@interface AtomController ()
@property (nonatomic, retain, readwrite) NSString *url;
@property (nonatomic, retain, readwrite) NSString *bootstrapPage;
@end
@implementation AtomController
@synthesize webView, url, jscocoa;
@synthesize
webView = _webView,
jscocoa = _jscocoa,
url = _url,
bootstrapPage = _bootstrapPage;
- (void)dealloc {
[jscocoa unlinkAllReferences];
[jscocoa garbageCollect];
[jscocoa release]; jscocoa = nil;
[webView release];
[url release];
[self.jscocoa unlinkAllReferences];
[self.jscocoa garbageCollect];
self.jscocoa = nil;
self.webView = nil;
self.bootstrapPage = nil;
self.url = nil;
[super dealloc];
}
- (id)initWithURL:(NSString *)_url {
self = [super initWithWindowNibName:@"AtomWindow"];
url = [_url retain];
[self.window makeKeyWindow];
- (id)initWithBootstrapPage:(NSString *)bootstrapPage url:(NSString *)url {
self = [super initWithWindowNibName:@"AtomWindow"];
self.bootstrapPage = bootstrapPage;
self.url = url;
[self.window makeKeyWindow];
return self;
}
- (id)initForSpecs {
return [self initWithBootstrapPage:@"spec-suite.html" url:nil];
}
- (id)initWithURL:(NSString *)url {
return [self initWithBootstrapPage:@"index.html" url:url];
}
- (void)windowDidLoad {
[super windowDidLoad];
[self.window setDelegate:self];
[self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
[webView setUIDelegate:self];
[self.webView setUIDelegate:self];
[self setShouldCascadeWindows:YES];
[self setWindowFrameAutosaveName:@"atomController"];
jscocoa = [[JSCocoa alloc] initWithGlobalContext:[[webView mainFrame] globalContext]];
[jscocoa setObject:self withName:@"$atomController"];
self.jscocoa = [[JSCocoa alloc] initWithGlobalContext:[[self.webView mainFrame] globalContext]];
[self.jscocoa setObject:self withName:@"$atomController"];
NSURL *resourceURL = [[NSBundle mainBundle] resourceURL];
NSURL *indexURL = [resourceURL URLByAppendingPathComponent:@"index.html"];
NSURL *bootstrapPageURL = [resourceURL URLByAppendingPathComponent:self.bootstrapPage];
NSURLRequest *request = [NSURLRequest requestWithURL:indexURL];
[[webView mainFrame] loadRequest:request];
NSURLRequest *request = [NSURLRequest requestWithURL:bootstrapPageURL];
[[self.webView mainFrame] loadRequest:request];
}
- (void)close {
[(AtomApp *)NSApp removeController:self];
[super close];

View File

@@ -8,7 +8,7 @@ task :build do
dest = File.join(built_dir, contents_dir, "Resources")
%w( index.html src docs static extensions test vendor ).each do |dir|
%w( spec-suite.html index.html src docs static extensions test vendor ).each do |dir|
rm_rf File.join(dest, dir)
cp_r dir, File.join(dest, dir)
end

1
spec-suite.html Normal file
View File

@@ -0,0 +1 @@
OMG HI