mirror of
https://github.com/atom/atom.git
synced 2026-02-11 07:05:11 -05:00
Kind of starting from scratch.
Recreated the project as an xcode 4 project. Key Bindings are working and reloading. Got rid of everything that wasn't being used right now.
This commit is contained in:
12
Atom/Classes/AtomApp.h
Normal file
12
Atom/Classes/AtomApp.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class AtomController;
|
||||
|
||||
@interface AtomApp : NSApplication <NSApplicationDelegate>
|
||||
|
||||
@property (nonatomic, retain) NSMutableArray *controllers;
|
||||
|
||||
- (AtomController *)createController;
|
||||
- (void)removeController:(AtomController *)controller;
|
||||
|
||||
@end
|
||||
48
Atom/Classes/AtomApp.m
Normal file
48
Atom/Classes/AtomApp.m
Normal file
@@ -0,0 +1,48 @@
|
||||
#import "AtomApp.h"
|
||||
#import "AtomController.h"
|
||||
#import "JSCocoa.h"
|
||||
|
||||
@implementation AtomApp
|
||||
|
||||
@synthesize controllers;
|
||||
|
||||
- (AtomController *)createController {
|
||||
AtomController *controller = [[AtomController alloc] initWithWindowNibName:@"AtomWindow"];
|
||||
[controllers addObject:controller];
|
||||
return controller;
|
||||
}
|
||||
|
||||
- (void)removeController:(AtomController *)controller {
|
||||
[controllers removeObject:controller];
|
||||
}
|
||||
|
||||
// Overridden
|
||||
- (void)sendEvent:(NSEvent *)event {
|
||||
if ([event type] == NSKeyDown) {
|
||||
BOOL handeled = NO;
|
||||
id controller = [[self keyWindow] windowController];
|
||||
|
||||
// The keyWindow could be a Cocoa Dialog or something, ignore that.
|
||||
if ([controller isKindOfClass:[AtomController class]]) {
|
||||
handeled = [controller handleKeyEvent:event];
|
||||
}
|
||||
|
||||
if (!handeled) [super sendEvent:event];
|
||||
}
|
||||
else {
|
||||
[super sendEvent:event];
|
||||
}
|
||||
}
|
||||
|
||||
// AppDelegate
|
||||
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification {
|
||||
NSDictionary *defaults = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"WebKitDeveloperExtras", nil];
|
||||
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
||||
AtomController *controller = [self createController];
|
||||
[controller window];
|
||||
}
|
||||
|
||||
@end
|
||||
16
Atom/Classes/AtomController.h
Normal file
16
Atom/Classes/AtomController.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class JSCocoa;
|
||||
|
||||
@interface AtomController : NSWindowController {
|
||||
IBOutlet id webView;
|
||||
NSString *URL;
|
||||
JSCocoa* jscocoa;
|
||||
}
|
||||
|
||||
@property (assign) IBOutlet id webView;
|
||||
@property (assign) IBOutlet NSString *URL;
|
||||
|
||||
-(BOOL) handleKeyEvent:(NSEvent *)event;
|
||||
|
||||
@end
|
||||
67
Atom/Classes/AtomController.m
Normal file
67
Atom/Classes/AtomController.m
Normal file
@@ -0,0 +1,67 @@
|
||||
#import "AtomController.h"
|
||||
#import "AtomApp.h"
|
||||
|
||||
#import <WebKit/WebKit.h>
|
||||
#import "JSCocoa.h"
|
||||
|
||||
@implementation AtomController
|
||||
|
||||
@synthesize webView, URL;
|
||||
|
||||
- (void)dealloc {
|
||||
[jscocoa unlinkAllReferences];
|
||||
[jscocoa garbageCollect];
|
||||
[jscocoa release]; jscocoa = nil;
|
||||
|
||||
[webView release];
|
||||
[URL release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id)initWithURL:(NSString *)_URL {
|
||||
self = [super initWithWindowNibName:@"AtomWindow"];
|
||||
self.URL = _URL;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)windowDidLoad {
|
||||
[super windowDidLoad];
|
||||
|
||||
[webView setUIDelegate:self];
|
||||
|
||||
[self setShouldCascadeWindows:YES];
|
||||
[self setWindowFrameAutosaveName:@"atomController"];
|
||||
|
||||
if (self.URL) {
|
||||
[webView setMainFrameURL:self.URL];
|
||||
}
|
||||
else {
|
||||
jscocoa = [[JSCocoa alloc] initWithGlobalContext:[[webView mainFrame] globalContext]];
|
||||
[jscocoa setObject:self withName:@"atomController"];
|
||||
|
||||
NSURL *resourceURL = [[NSBundle mainBundle] resourceURL];
|
||||
NSURL *indexURL = [resourceURL URLByAppendingPathComponent:@"index.html"];
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:indexURL];
|
||||
[[webView mainFrame] loadRequest:request];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)close {
|
||||
[(AtomApp *)NSApp removeController:self];
|
||||
[super close];
|
||||
}
|
||||
|
||||
- (BOOL)handleKeyEvent:(NSEvent *)event {
|
||||
// ICKY: Using a global function defined in App.js to deal with key events
|
||||
JSValueRef returnValue = [jscocoa callJSFunctionNamed:@"handleKeyEvent" withArguments:event, nil];
|
||||
return [jscocoa toBool:returnValue];
|
||||
}
|
||||
|
||||
// WebUIDelegate Protocol
|
||||
- (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element defaultMenuItems:(NSArray *)defaultMenuItems {
|
||||
return defaultMenuItems;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user