This commit is contained in:
Corey Johnson
2011-12-15 09:34:09 -08:00
parent 2a01ef757b
commit 583d0d749c
3 changed files with 34 additions and 47 deletions

View File

@@ -5,10 +5,11 @@
#import <WebKit/WebKit.h>
@interface AtomController ()
- (void)createWebView;
@property (nonatomic, retain) JSCocoa *jscocoa;
@property (nonatomic, retain, readwrite) NSString *url;
@property (nonatomic, retain, readwrite) NSString *bootstrapScript;
@end
@interface WebView (Atom)
@@ -17,26 +18,18 @@
- (void)startDebuggingJavaScript:(id)sender;
@end
@interface AtomController ()
- (void)createWebView;
@property (nonatomic, retain) JSCocoa *jscocoa;
@end
@implementation AtomController
@synthesize
webView = _webView,
jscocoa = _jscocoa,
url = _url,
bootstrapScript = _bootstrapScript;
@synthesize webView = _webView;
@synthesize jscocoa = _jscocoa;
@synthesize url = _url;
@synthesize bootstrapScript = _bootstrapScript;
- (void)dealloc {
[self.jscocoa unlinkAllReferences];
[self.jscocoa garbageCollect];
self.jscocoa = nil;
self.webView = nil;;
self.webView = nil;
self.bootstrapScript = nil;
self.url = nil;
@@ -60,6 +53,18 @@
return [self initWithBootstrapScript:@"bootstrap" url:url];
}
- (void)windowDidLoad {
[super windowDidLoad];
[self.window setDelegate:self];
[self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
[self setShouldCascadeWindows:YES];
[self setWindowFrameAutosaveName:@"atomController"];
[self createWebView];
}
- (BOOL)handleInputEvent:(NSEvent *)event {
BOOL shouldReload = [event modifierFlags] & NSCommandKeyMask && [[event charactersIgnoringModifiers] hasPrefix:@"r"];
if (shouldReload) {
@@ -99,32 +104,13 @@
[[self.webView inspector] showConsole:self];
}
- (JSValueRefAndContextRef)jsWindow {
JSValueRef window = [self.jscocoa evalJSString:@"window"];
JSValueRefAndContextRef windowWithContext = {window, self.jscocoa.ctx};
return windowWithContext;
}
- (void)reload {
[self.webView removeFromSuperview];
[self createWebView];
}
- (void)windowDidLoad {
[super windowDidLoad];
[self.window setDelegate:self];
[self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
[self setShouldCascadeWindows:YES];
[self setWindowFrameAutosaveName:@"atomController"];
[self createWebView];
}
- (void)close {
[(AtomApp *)NSApp removeController:self];
[self.jscocoa callJSFunctionNamed:@"triggerEvent" withArguments:@"window:close", nil, false, nil];
[super close];
}
@@ -132,6 +118,12 @@
return PROJECT_DIR;
}
- (JSValueRefAndContextRef)jsWindow {
JSValueRef window = [self.jscocoa evalJSString:@"window"];
JSValueRefAndContextRef windowWithContext = {window, self.jscocoa.ctx};
return windowWithContext;
}
#pragma mark NSWindowDelegate
- (BOOL)windowShouldClose:(id)sender {
[self close];