mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
Merge branch 'master' of github.com:github/atom
This commit is contained in:
@@ -12,7 +12,7 @@ class ClientHandler;
|
||||
CefRefPtr<ClientHandler> _clientHandler;
|
||||
}
|
||||
|
||||
- (void)open:(NSString *)path;
|
||||
- (AtomController *)open:(NSString *)path;
|
||||
- (IBAction)runSpecs:(id)sender;
|
||||
- (IBAction)runBenchmarks:(id)sender;
|
||||
|
||||
|
||||
@@ -60,8 +60,8 @@
|
||||
CefBrowser::CreateBrowser(window_info, _clientHandler.get(), [indexURLString UTF8String], settings);
|
||||
}
|
||||
|
||||
- (void)open:(NSString *)path {
|
||||
[[AtomController alloc] initWithPath:path atomContext:[self atomContext]];
|
||||
- (AtomController *)open:(NSString *)path {
|
||||
return [[AtomController alloc] initWithPath:path atomContext:[self atomContext]];
|
||||
}
|
||||
|
||||
- (IBAction)runSpecs:(id)sender {
|
||||
|
||||
@@ -10,6 +10,8 @@ class ClientHandler;
|
||||
NSString *_bootstrapScript;
|
||||
NSString *_pathToOpen;
|
||||
|
||||
BOOL _loaded;
|
||||
|
||||
CefRefPtr<CefV8Context> _atomContext;
|
||||
CefRefPtr<ClientHandler> _clientHandler;
|
||||
}
|
||||
@@ -20,8 +22,10 @@ class ClientHandler;
|
||||
- (id)initBenchmarksWithAtomContext:(CefRefPtr<CefV8Context>)atomContext;
|
||||
|
||||
- (void)createBrowser;
|
||||
- (void)blockUntilBrowserLoaded;
|
||||
|
||||
@property (nonatomic, retain) IBOutlet NSView *webView;
|
||||
@property (nonatomic, readonly) CefRefPtr<ClientHandler> clientHandler;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
@implementation AtomController
|
||||
|
||||
@synthesize webView=_webView;
|
||||
@synthesize clientHandler=_clientHandler;
|
||||
|
||||
- (void)dealloc {
|
||||
[_bootstrapScript release];
|
||||
@@ -20,6 +21,7 @@
|
||||
self = [super initWithWindowNibName:@"ClientWindow"];
|
||||
_bootstrapScript = [bootstrapScript retain];
|
||||
_atomContext = atomContext;
|
||||
_loaded = false;
|
||||
|
||||
[self.window makeKeyAndOrderFront:nil];
|
||||
[self createBrowser];
|
||||
@@ -60,9 +62,16 @@
|
||||
CefBrowser::CreateBrowser(window_info, _clientHandler.get(), [indexURLString UTF8String], settings);
|
||||
}
|
||||
|
||||
#pragma mark BrowserDelegate
|
||||
- (void)blockUntilBrowserLoaded {
|
||||
NSRunLoop *runLoop = [NSRunLoop mainRunLoop];
|
||||
while (!_loaded) {
|
||||
[runLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0]];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark BrowserDelegate
|
||||
- (void)loadStart {
|
||||
_loaded = false;
|
||||
CefRefPtr<CefV8Context> context = _clientHandler->GetBrowser()->GetMainFrame()->GetV8Context();
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
|
||||
@@ -82,6 +91,10 @@
|
||||
context->Exit();
|
||||
}
|
||||
|
||||
- (void)loadEnd {
|
||||
_loaded = true;
|
||||
}
|
||||
|
||||
- (bool)keyEventOfType:(cef_handler_keyevent_type_t)type
|
||||
code:(int)code
|
||||
modifiers:(int)modifiers
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#import "native_handler.h"
|
||||
#import "include/cef.h"
|
||||
#import "Atom.h"
|
||||
#import "AtomController.h"
|
||||
#import "client_handler.h"
|
||||
|
||||
NSString *stringFromCefV8Value(const CefRefPtr<CefV8Value>& value) {
|
||||
std::string cc_value = value->GetStringValue().ToString();
|
||||
@@ -51,6 +53,13 @@ bool NativeHandler::Execute(const CefString& name,
|
||||
NSString *path = stringFromCefV8Value(arguments[0]);
|
||||
NSString *content = stringFromCefV8Value(arguments[1]);
|
||||
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
|
||||
// Create parent directories if they don't exist
|
||||
BOOL exists = [fm fileExistsAtPath:[path stringByDeletingLastPathComponent] isDirectory:nil];
|
||||
if (!exists) {
|
||||
[fm createDirectoryAtPath:[path stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
}
|
||||
|
||||
NSError *error = nil;
|
||||
BOOL success = [content writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error];
|
||||
@@ -62,7 +71,9 @@ bool NativeHandler::Execute(const CefString& name,
|
||||
std::string exception = "Cannot write to '";
|
||||
exception += [path UTF8String];
|
||||
exception += "'";
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (name == "absolute") {
|
||||
NSString *path = stringFromCefV8Value(arguments[0]);
|
||||
@@ -224,12 +235,16 @@ bool NativeHandler::Execute(const CefString& name,
|
||||
}
|
||||
else if (name == "open") {
|
||||
NSString *path = stringFromCefV8Value(arguments[0]);
|
||||
[NSApp open:path];
|
||||
AtomController *atomController = [(Atom *)NSApp open:path];
|
||||
[atomController blockUntilBrowserLoaded];
|
||||
|
||||
CefRefPtr<ClientHandler> clientHandler = [atomController clientHandler];
|
||||
retval = clientHandler->GetBrowser()->GetMainFrame()->GetV8Context()->GetGlobal();
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (name == "newWindow") {
|
||||
[NSApp open:nil];
|
||||
[(Atom *)NSApp open:nil];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ describe "RootView", ->
|
||||
expect(editor1.buffer.url).not.toBe expectedUrl
|
||||
expect(editor2.buffer.url).toBe expectedUrl
|
||||
|
||||
describe "global keymap wiring", ->
|
||||
describe "keymap wiring", ->
|
||||
commandHandler = null
|
||||
beforeEach ->
|
||||
commandHandler = jasmine.createSpy('commandHandler')
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
Keymap = require 'keymap'
|
||||
fs = require 'fs'
|
||||
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
require 'underscore-extensions'
|
||||
@@ -8,11 +10,13 @@ class App
|
||||
keymap: null
|
||||
windows: null
|
||||
tabText: null
|
||||
userConfigurationPath: null
|
||||
|
||||
constructor: (@loadPath, nativeMethods)->
|
||||
@windows = []
|
||||
@setUpKeymap()
|
||||
@tabText = " "
|
||||
@userConfigurationPath = fs.absolute "~/.atom/atom.coffee"
|
||||
|
||||
setUpKeymap: ->
|
||||
@keymap = new Keymap()
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
$ = require 'jquery'
|
||||
fs = require 'fs'
|
||||
BindingSet = require 'binding-set'
|
||||
Specificity = require 'specificity'
|
||||
|
||||
$ = require 'jquery'
|
||||
|
||||
module.exports =
|
||||
class Keymap
|
||||
bindingSetsBySelector: null
|
||||
@@ -11,19 +13,25 @@ class Keymap
|
||||
|
||||
bindDefaultKeys: ->
|
||||
@bindKeys "*",
|
||||
'meta-n': 'newWindow'
|
||||
'meta-n': 'new-window'
|
||||
'meta-o': 'open'
|
||||
'meta-,': 'open-user-configuration'
|
||||
|
||||
@_newWindow = => $native.newWindow()
|
||||
@_open = =>
|
||||
url = $native.openDialog()
|
||||
atom.open(url) if url
|
||||
@_openUserConfiguration = =>
|
||||
openedWindow = atom.open(atom.userConfigurationPath)
|
||||
defaultConfiguration = "# This is run when a window is loaded!\nconsole.log('see!')"
|
||||
openedWindow.rootView.editor.buffer.setText defaultConfiguration unless fs.exists(atom.userConfigurationPath)
|
||||
|
||||
$(document).on 'newWindow', @_newWindow
|
||||
$(document).on 'new-window', @_newWindow
|
||||
$(document).on 'open', @_open
|
||||
$(document).on 'open-user-configuration', @_openUserConfiguration
|
||||
|
||||
unbindDefaultKeys: ->
|
||||
$(document).unbind 'newWindow', @_newWindow
|
||||
$(document).unbind 'new-window', @_newWindow
|
||||
$(document).unbind 'open', @_open
|
||||
|
||||
bindKeys: (selector, bindings) ->
|
||||
|
||||
@@ -19,7 +19,7 @@ windowAdditions =
|
||||
startup: (url) ->
|
||||
@setUpKeymap()
|
||||
@attachRootView(url)
|
||||
@loadUserConfig()
|
||||
@loadUserConfiguration()
|
||||
$(window).on 'close', => @close()
|
||||
$(window).focus()
|
||||
atom.windowOpened this
|
||||
@@ -46,12 +46,12 @@ windowAdditions =
|
||||
@rootView = new RootView {url}
|
||||
$(@rootViewParentSelector).append @rootView
|
||||
|
||||
loadUserConfig: (path="~/.atom") ->
|
||||
absolutePath = fs.absolute(path)
|
||||
loadUserConfiguration: ->
|
||||
try
|
||||
require absolutePath if fs.exists(absolutePath)
|
||||
require atom.userConfigurationPath if fs.exists(atom.userConfigurationPath)
|
||||
catch error
|
||||
console.error "Failed to load `#{absolutePath}`", error
|
||||
console.error "Failed to load `#{atom.userConfigurationPath}`", error
|
||||
@showConsole()
|
||||
|
||||
requireStylesheet: (path) ->
|
||||
fullPath = require.resolve(path)
|
||||
|
||||
Reference in New Issue
Block a user