From 445e5a8ce08ece85903aac07d996ae833d5303cc Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 28 Oct 2011 17:12:16 -0700 Subject: [PATCH] Every window has a path --- Atom/Classes/AtomApp.h | 2 +- Atom/Classes/AtomApp.m | 8 +++--- Atom/Classes/AtomController.h | 12 +++++---- Atom/Classes/AtomController.m | 28 +++++++++----------- Atom/xibs/AtomWindow.xib | 49 +++++++++++++++++++++-------------- src/app.coffee | 2 +- src/editor.coffee | 16 ++++++------ src/native.coffee | 2 +- src/window.coffee | 31 +++++++++++++++++++--- 9 files changed, 91 insertions(+), 59 deletions(-) diff --git a/Atom/Classes/AtomApp.h b/Atom/Classes/AtomApp.h index 50e55faab..fff27b881 100644 --- a/Atom/Classes/AtomApp.h +++ b/Atom/Classes/AtomApp.h @@ -6,7 +6,7 @@ @property (nonatomic, retain) NSMutableArray *controllers; -- (AtomController *)createController; +- (AtomController *)createController:(NSString *)path; - (void)removeController:(AtomController *)controller; @end diff --git a/Atom/Classes/AtomApp.m b/Atom/Classes/AtomApp.m index 0bbe41ad4..d5bd4b875 100644 --- a/Atom/Classes/AtomApp.m +++ b/Atom/Classes/AtomApp.m @@ -2,12 +2,14 @@ #import "AtomController.h" #import "JSCocoa.h" +#import + @implementation AtomApp @synthesize controllers; -- (AtomController *)createController { - AtomController *controller = [[AtomController alloc] initWithWindowNibName:@"AtomWindow"]; +- (AtomController *)createController:(NSString *)path { + AtomController *controller = [[AtomController alloc] initWithPath:path]; [controllers addObject:controller]; return controller; } @@ -41,7 +43,7 @@ } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - AtomController *controller = [self createController]; + AtomController *controller = [self createController:NULL]; [controller window]; } diff --git a/Atom/Classes/AtomController.h b/Atom/Classes/AtomController.h index b23cff639..2317c1a1b 100644 --- a/Atom/Classes/AtomController.h +++ b/Atom/Classes/AtomController.h @@ -1,16 +1,18 @@ #import @class JSCocoa; +@class WebView; @interface AtomController : NSWindowController { - IBOutlet id webView; - NSString *URL; + IBOutlet WebView *webView; + NSString *path; JSCocoa* jscocoa; } -@property (assign) IBOutlet id webView; -@property (assign) IBOutlet NSString *URL; +@property (retain) IBOutlet WebView *webView; +@property (retain) NSString *path; --(BOOL) handleKeyEvent:(NSEvent *)event; +- (AtomController *)initWithPath:(NSString *)aPath; +- (BOOL)handleKeyEvent:(NSEvent *)event; @end diff --git a/Atom/Classes/AtomController.m b/Atom/Classes/AtomController.m index 655a0677f..bff481682 100644 --- a/Atom/Classes/AtomController.m +++ b/Atom/Classes/AtomController.m @@ -6,7 +6,7 @@ @implementation AtomController -@synthesize webView, URL; +@synthesize webView, path; - (void)dealloc { [jscocoa unlinkAllReferences]; @@ -14,37 +14,33 @@ [jscocoa release]; jscocoa = nil; [webView release]; - [URL release]; + [path release]; [super dealloc]; } -- (id)initWithURL:(NSString *)_URL { +- (id)initWithPath:(NSString *)aPath { self = [super initWithWindowNibName:@"AtomWindow"]; - self.URL = _URL; + [self setPath:aPath]; + 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"]; + 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]; - } + NSURL *resourceURL = [[NSBundle mainBundle] resourceURL]; + NSURL *indexURL = [resourceURL URLByAppendingPathComponent:@"index.html"]; + NSURLRequest *request = [NSURLRequest requestWithURL:indexURL]; + [[webView mainFrame] loadRequest:request]; } - (void)close { diff --git a/Atom/xibs/AtomWindow.xib b/Atom/xibs/AtomWindow.xib index 74ddf870a..c81efc46e 100644 --- a/Atom/xibs/AtomWindow.xib +++ b/Atom/xibs/AtomWindow.xib @@ -1,7 +1,7 @@ - 1060 + 1070 11C74 1938 1138.23 @@ -56,7 +56,7 @@ - + 256 YES @@ -86,25 +86,18 @@ {725, 723} + - + atomController YES - + YES - WebKitDefaultFixedFontSize - WebKitDefaultFontSize - WebKitMinimumFontSize - - - YES - - - + YES @@ -112,6 +105,9 @@ {725, 723} + + + {{0, 0}, {1440, 878}} {10000000000000, 10000000000000} @@ -144,9 +140,7 @@ YES 0 - - YES - + @@ -235,6 +229,25 @@ YES + + AtomController + NSWindowController + + webView + WebView + + + webView + + webView + WebView + + + + IBProjectSource + ./Classes/AtomController.h + + WebView @@ -257,10 +270,6 @@ 0 IBCocoaFramework - - com.apple.InterfaceBuilder.CocoaPlugin.macosx - - com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 diff --git a/src/app.coffee b/src/app.coffee index c419af70a..ada16169d 100644 --- a/src/app.coffee +++ b/src/app.coffee @@ -8,4 +8,4 @@ class App window.startup() @quit: -> - OSX.NSApp.terminate OSX.NSApp + OSX.NSApp.terminate null diff --git a/src/editor.coffee b/src/editor.coffee index cfc9055af..7eda44f7a 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -15,7 +15,7 @@ class Editor sessions: {} - constructor: -> + constructor: (path) -> KeyBinder.register "editor", @ # Resize editor when panes are added/removed el = document.body @@ -36,6 +36,8 @@ class Editor Event.on 'window:open', (e) => @open e.details Event.on 'window:close', (e) => @close e.details + @open path if path + modeMap: js: 'javascript' c: 'c_cpp' @@ -115,20 +117,18 @@ class Editor resize: (timeout=1) -> setTimeout => - @editor.ace.focus() - @editor.ace.resize() + @ace.focus() + @ace.resize() , timeout copy: -> - editor = @ace - text = editor.getSession().doc.getTextRange editor.getSelectionRange() + text = @ace.getSession().doc.getTextRange @ace.getSelectionRange() Native.writeToPasteboard text cut: -> - editor = @ace - text = editor.getSession().doc.getTextRange editor.getSelectionRange() + text = @ace.getSession().doc.getTextRange @ace.getSelectionRange() Native.writeToPasteboard text - editor.session.remove editor.getSelectionRange() + @ace.session.remove @ace.getSelectionRange() eval: -> eval @code() diff --git a/src/native.coffee b/src/native.coffee index 860acd365..85f3f8f48 100644 --- a/src/native.coffee +++ b/src/native.coffee @@ -2,7 +2,7 @@ module.exports = class Native # path - Optional. The String path to the file to base it on. @newWindow: (path) -> - controller = OSX.NSApp.createController + controller = OSX.NSApp.createController path controller.window controller.window.makeKeyAndOrderFront null diff --git a/src/window.coffee b/src/window.coffee index 4d2f2d18a..e322d10b4 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -14,12 +14,18 @@ windowAdditions = appRoot: OSX.NSBundle.mainBundle.resourcePath - path: localStorage.lastOpenedPath ? fs.workingDirectory() + path: null + + startup: () -> + @path = atomController.path ? @recentPath() + console.log localStorage.hi + localStorage.hi = "12345" + console.log localStorage + @showConsole() - startup: -> KeyBinder.register "window", window - @editor = new Editor() + @editor = new Editor @path @loadExtensions() @@ -47,15 +53,32 @@ windowAdditions = console.warn "window: Extension #{extension.constructor.name} failed to startup." console.warn error + recentPath: -> + localStorage.lastOpenedPath ? "/tmp/atom" + + setRecentPath: (path) -> + console.log "New Path #{path}" + localStorage.lastOpenedPath = path + handleKeyEvent: -> KeyBinder.handleEvent.apply KeyBinder, arguments showConsole: -> atomController.webView.inspector.showConsole true + reload: -> + @close() + Native.newWindow @path + open: (path) -> path = Native.openPanel() if not path - Event.trigger 'window:open', path if path + if path + @path = path + @setRecentPath path + Event.trigger 'window:open', path + + close: -> + atomController.close() for key, value of windowAdditions console.warn "DOMWindow already has a key named `#{key}`" if window[key]