mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
wii - gettings specs on App.open. Window closing not working quite right.
This commit is contained in:
@@ -323,6 +323,7 @@
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
||||
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
|
||||
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
|
||||
@@ -345,6 +346,7 @@
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = NO;
|
||||
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
|
||||
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
|
||||
|
||||
@@ -6,9 +6,6 @@
|
||||
|
||||
@property (nonatomic, retain) NSMutableArray *controllers;
|
||||
|
||||
- (AtomController *)createController:(NSString *)path;
|
||||
- (AtomController *)createController:(NSString *)path;
|
||||
- (void)removeController:(AtomController *)controller;
|
||||
- (void)reloadController:(AtomController *)controller;
|
||||
|
||||
@end
|
||||
|
||||
@@ -11,46 +11,31 @@
|
||||
|
||||
@synthesize controllers = _controllers;
|
||||
|
||||
- (AtomController *)createController:(NSString *)path {
|
||||
AtomController *controller = [[AtomController alloc] initWithURL:path];
|
||||
[self.controllers addObject:controller];
|
||||
return controller;
|
||||
}
|
||||
|
||||
- (AtomController *)createSpecController {
|
||||
AtomController *controller = [[AtomController alloc] initForSpecs];
|
||||
[self.controllers addObject:controller];
|
||||
return controller;
|
||||
}
|
||||
|
||||
- (void)removeController:(AtomController *)controller {
|
||||
[self.controllers removeObject:controller];
|
||||
[controller.jscocoa callJSFunctionNamed:@"triggerEvent" withArguments:@"window:close", nil, false, nil];
|
||||
}
|
||||
|
||||
- (void)reloadController:(AtomController *)controller {
|
||||
[controller createWebView];
|
||||
}
|
||||
|
||||
- (void)open:(NSString *)path {
|
||||
if (!path) {
|
||||
NSOpenPanel *panel =[NSOpenPanel openPanel];
|
||||
panel.canChooseDirectories = YES;
|
||||
if (panel.runModal != NSFileHandlingPanelOKButton) return;
|
||||
|
||||
path = [[[panel URLs] lastObject] path];
|
||||
}
|
||||
|
||||
[self createController:path];
|
||||
AtomController *controller = [[AtomController alloc] initWithURL:path];
|
||||
[self.controllers addObject:controller];
|
||||
}
|
||||
|
||||
// Events in the "app:*" namespace get sent to all controllers
|
||||
- (void)triggerGlobalEvent:(NSString *)name data:(id)data {
|
||||
- (void)triggerGlobalAtomEvent:(NSString *)name data:(id)data {
|
||||
for (AtomController *controller in self.controllers) {
|
||||
[controller.jscocoa callJSFunctionNamed:@"triggerEvent" withArguments:name, data, false, nil];
|
||||
[controller triggerAtomEventWithName:name data:data];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)shouldRunSpecsOnEvent:(NSEvent *)event {
|
||||
return [event modifierFlags] & (NSAlternateKeyMask | NSControlKeyMask | NSCommandKeyMask) && [[event charactersIgnoringModifiers] hasPrefix:@"s"];
|
||||
}
|
||||
|
||||
// Overridden
|
||||
- (void)sendEvent:(NSEvent *)event {
|
||||
if ([event type] != NSKeyDown) {
|
||||
@@ -58,32 +43,22 @@
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL handeled = NO;
|
||||
AtomController *controller = [[self keyWindow] windowController];
|
||||
if ([self shouldRunSpecsOnEvent:event]) {
|
||||
[self createSpecController];
|
||||
return;
|
||||
}
|
||||
|
||||
// The keyWindow could be a Cocoa Dialog or something, ignore those.
|
||||
if ([controller isKindOfClass:[AtomController class]]) {
|
||||
// cmd-r should always reload the current controller, so it needs to be here
|
||||
if ([event modifierFlags] & NSCommandKeyMask && [[event charactersIgnoringModifiers] hasPrefix:@"r"]) {
|
||||
[self reloadController:controller];
|
||||
handeled = YES;
|
||||
}
|
||||
else if ([event modifierFlags] & (NSAlternateKeyMask | NSControlKeyMask | NSCommandKeyMask) && [[event charactersIgnoringModifiers] hasPrefix:@"s"]) {
|
||||
[self createSpecController];
|
||||
handeled = YES;
|
||||
}
|
||||
else {
|
||||
JSValueRef value = [controller.jscocoa callJSFunctionNamed:@"handleKeyEvent" withArguments:event, nil];
|
||||
handeled = [controller.jscocoa toBool:value];
|
||||
}
|
||||
AtomController *controller = [[self keyWindow] windowController];
|
||||
if ([controller isKindOfClass:[AtomController class]]) { // ensure its not a dialog
|
||||
if ([controller handleInputEvent:event]) return;
|
||||
}
|
||||
|
||||
if (!handeled) [super sendEvent:event];
|
||||
[super sendEvent:event];
|
||||
}
|
||||
|
||||
- (void)terminate:(id)sender {
|
||||
for (AtomController *controller in self.controllers) {
|
||||
[controller.jscocoa callJSFunctionNamed:@"shutdown" withArguments:nil];
|
||||
for (AtomController *controller in self.controllers) {
|
||||
[controller close];
|
||||
}
|
||||
|
||||
[super terminate:sender];
|
||||
@@ -98,7 +73,6 @@
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
||||
[self createController:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "JSCocoa.h"
|
||||
|
||||
@class JSCocoa;
|
||||
@class WebView;
|
||||
|
||||
struct JSGlobalContextRef;
|
||||
|
||||
@interface AtomController : NSWindowController <NSWindowDelegate> {
|
||||
}
|
||||
|
||||
@property (assign) WebView *webView;
|
||||
@property (nonatomic, retain) JSCocoa *jscocoa;
|
||||
|
||||
@property (nonatomic, retain, readonly) NSString *url;
|
||||
@property (nonatomic, retain, readonly) NSString *bootstrapScript;
|
||||
@@ -15,6 +17,9 @@
|
||||
- (id)initForSpecs;
|
||||
- (id)initWithURL:(NSString *)url;
|
||||
|
||||
- (void)createWebView;
|
||||
- (BOOL)handleInputEvent:(NSEvent *)event;
|
||||
- (void)triggerAtomEventWithName:(NSString *)name data:(id)data;
|
||||
- (void)reload;
|
||||
- (JSValueRefAndContextRef)jsWindow;
|
||||
|
||||
@end
|
||||
|
||||
@@ -11,6 +11,19 @@
|
||||
|
||||
@end
|
||||
|
||||
@interface WebView (Atom)
|
||||
- (id)inspector;
|
||||
- (void)showConsole:(id)sender;
|
||||
- (void)startDebuggingJavaScript:(id)sender;
|
||||
@end
|
||||
|
||||
@interface AtomController ()
|
||||
- (void)createWebView;
|
||||
|
||||
@property (nonatomic, retain) JSCocoa *jscocoa;
|
||||
|
||||
@end
|
||||
|
||||
@implementation AtomController
|
||||
|
||||
@synthesize
|
||||
@@ -47,10 +60,31 @@
|
||||
return [self initWithBootstrapScript:@"bootstrap" url:url];
|
||||
}
|
||||
|
||||
- (void)createWebView {
|
||||
[self.webView removeFromSuperview];
|
||||
- (BOOL)shouldReloadOnEvent:(NSEvent *)event {
|
||||
return [event modifierFlags] & NSCommandKeyMask && [[event charactersIgnoringModifiers] hasPrefix:@"r"];
|
||||
}
|
||||
|
||||
- (BOOL)handleInputEvent:(NSEvent *)event {
|
||||
if ([self shouldReloadOnEvent:event]) {
|
||||
[self reload];
|
||||
return YES;
|
||||
}
|
||||
|
||||
if ([self.jscocoa hasJSFunctionNamed:@"handleKeyEvent"]) {
|
||||
JSValueRef handled = [self.jscocoa callJSFunctionNamed:@"handleKeyEvent" withArguments:event, nil];
|
||||
return [self.jscocoa toBool:handled];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)triggerAtomEventWithName:(NSString *)name data:(id)data {
|
||||
[self.jscocoa callJSFunctionNamed:@"triggerEvent" withArguments:name, data, false, nil];
|
||||
}
|
||||
|
||||
- (void)createWebView {
|
||||
self.webView = [[WebView alloc] initWithFrame:[self.window.contentView frame]];
|
||||
|
||||
[self.webView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
|
||||
[self.window.contentView addSubview:self.webView];
|
||||
[self.webView setUIDelegate:self];
|
||||
@@ -64,6 +98,19 @@
|
||||
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:indexURL];
|
||||
[[self.webView mainFrame] loadRequest:request];
|
||||
|
||||
[[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 {
|
||||
@@ -79,7 +126,8 @@
|
||||
}
|
||||
|
||||
- (void)close {
|
||||
[(AtomApp *)NSApp removeController:self];
|
||||
[(AtomApp *)NSApp removeController:self];
|
||||
[self.jscocoa callJSFunctionNamed:@"triggerEvent" withArguments:@"window:close", nil, false, nil];
|
||||
[super close];
|
||||
}
|
||||
|
||||
@@ -87,7 +135,13 @@
|
||||
return PROJECT_DIR;
|
||||
}
|
||||
|
||||
// WebUIDelegate
|
||||
#pragma mark NSWindowDelegate
|
||||
- (BOOL)windowShouldClose:(id)sender {
|
||||
[self close];
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark WebUIDelegate
|
||||
- (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element defaultMenuItems:(NSArray *)defaultMenuItems {
|
||||
return defaultMenuItems;
|
||||
}
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>
|
||||
<title>Jasmine suite</title>
|
||||
<link rel="stylesheet" type="text/css" href="static/jasmine.css"/>
|
||||
<script type="text/javascript" src="static/jasmine.js"></script>
|
||||
<script type="text/javascript" src="static/jasmine-html.js"></script>
|
||||
<script type="text/javascript" src="src/stdlib/require.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
@@ -19,11 +16,11 @@
|
||||
return trivialReporter.specFilter(spec);
|
||||
};
|
||||
|
||||
window.onload = function() {
|
||||
window.onload = function() {
|
||||
|
||||
require('spec-suite');
|
||||
require('spec-suite');
|
||||
|
||||
jasmineEnv.execute();
|
||||
jasmineEnv.execute();
|
||||
|
||||
};
|
||||
})();
|
||||
@@ -34,8 +31,7 @@
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="jasmine_runner"></div>
|
||||
<div id="jasmine_content"></div>
|
||||
<div id="jasmine_runner"></div><div id="jasmine_content"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
@@ -1,11 +1,24 @@
|
||||
App = require 'views/app'
|
||||
App = require 'app'
|
||||
|
||||
describe "App", ->
|
||||
view = null
|
||||
app = null
|
||||
|
||||
beforeEach ->
|
||||
view = App.buildView()
|
||||
app = new App()
|
||||
|
||||
afterEach ->
|
||||
window.x = app.windows()[0]
|
||||
setTimeout (-> window.x.close()), 1
|
||||
#w.close() for w in app.windows()
|
||||
|
||||
describe "open", ->
|
||||
it "loads a buffer based on the given path and displays it in a new window", ->
|
||||
filePath = require.resolve 'fixtures/sample.txt'
|
||||
expect(app.windows().length).toBe 0
|
||||
|
||||
app.open filePath
|
||||
|
||||
expect(app.windows().length).toBe 1
|
||||
newWindow = app.windows()[0]
|
||||
|
||||
expect(newWindow.editor.buffer.url).toEqual filePath
|
||||
|
||||
1
spec/fixtures/sample.txt
vendored
Normal file
1
spec/fixtures/sample.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Some text.
|
||||
24
spec/spec-bootstrap.coffee
Normal file
24
spec/spec-bootstrap.coffee
Normal file
@@ -0,0 +1,24 @@
|
||||
nakedLoad 'jasmine'
|
||||
nakedLoad 'jasmine-html'
|
||||
|
||||
$ = require 'jquery'
|
||||
coffeekup = require 'coffeekup'
|
||||
|
||||
$('head').append coffeekup.render ->
|
||||
link rel: "stylesheet", type: "text/css", href: "static/jasmine.css"
|
||||
|
||||
$('body').append coffeekup.render ->
|
||||
div id: 'jasmine_runner'
|
||||
div id: 'jasmine_content'
|
||||
|
||||
jasmineEnv = jasmine.getEnv()
|
||||
trivialReporter = new jasmine.TrivialReporter(document, 'jasmine_runner')
|
||||
|
||||
jasmineEnv.addReporter(trivialReporter)
|
||||
|
||||
jasmineEnv.specFilter = (spec) ->
|
||||
return trivialReporter.specFilter(spec)
|
||||
|
||||
require 'spec-suite'
|
||||
jasmineEnv.execute()
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
require 'template-spec'
|
||||
require 'atom/app-spec'
|
||||
|
||||
require 'stdlib/template-spec'
|
||||
|
||||
|
||||
@@ -5,3 +5,6 @@ class App
|
||||
|
||||
quit: ->
|
||||
OSX.NSApp.terminate null
|
||||
|
||||
windows: ->
|
||||
controller.jsWindow for controller in OSX.NSApp.controllers
|
||||
|
||||
@@ -13,7 +13,7 @@ class Event
|
||||
|
||||
trigger: (name, data...) ->
|
||||
if name.match /^app:/
|
||||
OSX.NSApp.triggerGlobalEvent_data name, data
|
||||
OSX.NSApp.triggerGlobalAtomEvent_data name, data
|
||||
return
|
||||
|
||||
_.each @events[name], (callback) => callback data...
|
||||
|
||||
@@ -12,6 +12,11 @@ paths = [
|
||||
|
||||
window.__filename = null
|
||||
|
||||
nakedLoad = (file) ->
|
||||
file = resolve file
|
||||
code = __read file
|
||||
__jsc__.evalJSString_withScriptPath code, file
|
||||
|
||||
require = (file, cb) ->
|
||||
return cb require file if cb?
|
||||
|
||||
@@ -110,8 +115,8 @@ __read = (path) ->
|
||||
__modules = { loaded : {} }
|
||||
__defines = []
|
||||
|
||||
|
||||
this.require = require
|
||||
this.nakedLoad = nakedLoad
|
||||
this.define = define
|
||||
|
||||
this.require.resourcePath = resourcePath
|
||||
|
||||
2
static/jasmine.js → vendor/jasmine.js
vendored
2
static/jasmine.js → vendor/jasmine.js
vendored
@@ -41,7 +41,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
|
||||
|
||||
jasmine.getGlobal = function() {
|
||||
function getGlobal() {
|
||||
return this;
|
||||
return window;
|
||||
}
|
||||
|
||||
return getGlobal();
|
||||
Reference in New Issue
Block a user