From 5daabb3241954ac5ccc863a531fdd5d0f67dfbe2 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Mon, 12 Dec 2011 13:04:46 -0800 Subject: [PATCH] =?UTF-8?q?Add=20facility=20for=20running=20specs=E2=80=A6?= =?UTF-8?q?=20still=20don't=20have=20any=20yet.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use property accessors instead of raw ivars. --- Atom/Classes/AtomApp.m | 15 +++++++-- Atom/Classes/AtomController.h | 7 +++-- Atom/Classes/AtomController.m | 57 ++++++++++++++++++++++++----------- Rakefile | 2 +- spec-suite.html | 1 + 5 files changed, 58 insertions(+), 24 deletions(-) create mode 100644 spec-suite.html diff --git a/Atom/Classes/AtomApp.m b/Atom/Classes/AtomApp.m index c7212cb6a..02db33bba 100644 --- a/Atom/Classes/AtomApp.m +++ b/Atom/Classes/AtomApp.m @@ -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]; diff --git a/Atom/Classes/AtomController.h b/Atom/Classes/AtomController.h index fad7ee298..69478e1ee 100644 --- a/Atom/Classes/AtomController.h +++ b/Atom/Classes/AtomController.h @@ -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 diff --git a/Atom/Classes/AtomController.m b/Atom/Classes/AtomController.m index 4f1b9913d..a20f80eff 100644 --- a/Atom/Classes/AtomController.m +++ b/Atom/Classes/AtomController.m @@ -2,54 +2,75 @@ #import "AtomApp.h" #import "JSCocoa.h" - #import +@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]; diff --git a/Rakefile b/Rakefile index 4d354a2e4..8bd884017 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/spec-suite.html b/spec-suite.html new file mode 100644 index 000000000..8fef4f264 --- /dev/null +++ b/spec-suite.html @@ -0,0 +1 @@ +OMG HI