mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Every window has a path
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
@property (nonatomic, retain) NSMutableArray *controllers;
|
||||
|
||||
- (AtomController *)createController;
|
||||
- (AtomController *)createController:(NSString *)path;
|
||||
- (void)removeController:(AtomController *)controller;
|
||||
|
||||
@end
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
#import "AtomController.h"
|
||||
#import "JSCocoa.h"
|
||||
|
||||
#import <WebKit/WebKit.h>
|
||||
|
||||
@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];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
|
||||
<data>
|
||||
<int key="IBDocument.SystemTarget">1060</int>
|
||||
<int key="IBDocument.SystemTarget">1070</int>
|
||||
<string key="IBDocument.SystemVersion">11C74</string>
|
||||
<string key="IBDocument.InterfaceBuilderVersion">1938</string>
|
||||
<string key="IBDocument.AppKitVersion">1138.23</string>
|
||||
@@ -56,7 +56,7 @@
|
||||
<nil key="NSViewClass"/>
|
||||
<nil key="NSUserInterfaceItemIdentifier"/>
|
||||
<object class="NSView" key="NSWindowView" id="610964987">
|
||||
<nil key="NSNextResponder"/>
|
||||
<reference key="NSNextResponder"/>
|
||||
<int key="NSvFlags">256</int>
|
||||
<object class="NSMutableArray" key="NSSubviews">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
@@ -86,25 +86,18 @@
|
||||
</object>
|
||||
<string key="NSFrameSize">{725, 723}</string>
|
||||
<reference key="NSSuperview" ref="610964987"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView"/>
|
||||
<string key="FrameName"/>
|
||||
<string key="GroupName"/>
|
||||
<object class="WebPreferences" key="Preferences">
|
||||
<string key="Identifier"/>
|
||||
<string key="Identifier">atomController</string>
|
||||
<object class="NSMutableDictionary" key="Values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<object class="NSArray" key="dict.sortedKeys" id="0">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>WebKitDefaultFixedFontSize</string>
|
||||
<string>WebKitDefaultFontSize</string>
|
||||
<string>WebKitMinimumFontSize</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<integer value="12"/>
|
||||
<integer value="12"/>
|
||||
<integer value="1"/>
|
||||
</object>
|
||||
<reference key="dict.values" ref="0"/>
|
||||
</object>
|
||||
</object>
|
||||
<bool key="UseBackForwardList">YES</bool>
|
||||
@@ -112,6 +105,9 @@
|
||||
</object>
|
||||
</object>
|
||||
<string key="NSFrameSize">{725, 723}</string>
|
||||
<reference key="NSSuperview"/>
|
||||
<reference key="NSWindow"/>
|
||||
<reference key="NSNextKeyView" ref="615135301"/>
|
||||
</object>
|
||||
<string key="NSScreenRect">{{0, 0}, {1440, 878}}</string>
|
||||
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
|
||||
@@ -144,9 +140,7 @@
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">0</int>
|
||||
<object class="NSArray" key="object" id="0">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<reference key="object" ref="0"/>
|
||||
<reference key="children" ref="1000"/>
|
||||
<nil key="parent"/>
|
||||
</object>
|
||||
@@ -235,6 +229,25 @@
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">AtomController</string>
|
||||
<string key="superclassName">NSWindowController</string>
|
||||
<object class="NSMutableDictionary" key="outlets">
|
||||
<string key="NS.key.0">webView</string>
|
||||
<string key="NS.object.0">WebView</string>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
|
||||
<string key="NS.key.0">webView</string>
|
||||
<object class="IBToOneOutletInfo" key="NS.object.0">
|
||||
<string key="name">webView</string>
|
||||
<string key="candidateClassName">WebView</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBProjectSource</string>
|
||||
<string key="minorKey">./Classes/AtomController.h</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">WebView</string>
|
||||
<object class="NSMutableDictionary" key="actions">
|
||||
@@ -257,10 +270,6 @@
|
||||
</object>
|
||||
<int key="IBDocument.localizationMode">0</int>
|
||||
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string>
|
||||
<integer value="1060" key="NS.object.0"/>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string>
|
||||
<integer value="3000" key="NS.object.0"/>
|
||||
|
||||
@@ -8,4 +8,4 @@ class App
|
||||
window.startup()
|
||||
|
||||
@quit: ->
|
||||
OSX.NSApp.terminate OSX.NSApp
|
||||
OSX.NSApp.terminate null
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user