#include "browser/api/atom_api_app.h"
+#include "base/values.h"
#include "base/command_line.h"
#include "browser/browser.h"
#include "vendor/node/src/node.h"
Emit("window-all-closed");
}
+void App::OnOpenFile(bool* prevent_default, const std::string& file_path) {
+ base::ListValue args;
+ args.AppendString(file_path);
+ *prevent_default = Emit("open-file", &args);
+}
+
// static
v8::Handle<v8::Value> App::New(const v8::Arguments &args) {
v8::HandleScope scope;
// BrowserObserver implementations:
virtual void OnWillQuit(bool* prevent_default) OVERRIDE;
virtual void OnWindowAllClosed() OVERRIDE;
+ virtual void OnOpenFile(bool* prevent_default,
+ const std::string& file_path) OVERRIDE;
private:
static v8::Handle<v8::Value> New(const v8::Arguments &args);
andEventID:kAEQuitApplication];
}
+- (BOOL)application:(NSApplication*)sender
+ openFile:(NSString*)filename {
+ return [[AtomApplication sharedApplication] openFile:filename];
+}
+
- (void)handleQuitEvent:(NSAppleEventDescriptor*)event
withReplyEvent:(NSAppleEventDescriptor*)replyEvent {
[[AtomApplication sharedApplication] closeAllWindows:self];
BOOL handlingSendEvent_;
}
++ (AtomApplication*)sharedApplication;
+
// CrAppProtocol:
- (BOOL)isHandlingSendEvent;
// CrAppControlProtocol:
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
-+ (AtomApplication*)sharedApplication;
+- (BOOL)openFile:(NSString*)file;
- (IBAction)closeAllWindows:(id)sender;
#import "browser/atom_application_mac.h"
#include "base/auto_reset.h"
+#include "base/strings/sys_string_conversions.h"
#include "browser/browser.h"
@implementation AtomApplication
++ (AtomApplication*)sharedApplication {
+ return (AtomApplication*)[super sharedApplication];
+}
+
- (BOOL)isHandlingSendEvent {
return handlingSendEvent_;
}
handlingSendEvent_ = handlingSendEvent;
}
-+ (AtomApplication*)sharedApplication {
- return (AtomApplication*)[super sharedApplication];
+- (BOOL)openFile:(NSString*)filename {
+ std::string filename_str(base::SysNSStringToUTF8(filename));
+ return atom::Browser::Get()->OpenFile(filename_str) ? YES : NO;
}
- (IBAction)closeAllWindows:(id)sender {
virtual void PostEarlyInitialization() OVERRIDE;
virtual void PreMainMessageLoopStart() OVERRIDE;
virtual void PreMainMessageLoopRun() OVERRIDE;
+ virtual void PostDestroyThreads() OVERRIDE;
private:
scoped_ptr<AtomBrowserBindings> atom_bindings_;
[mainNib release];
}
+void AtomBrowserMainParts::PostDestroyThreads() {
+ [[[AtomApplication sharedApplication] delegate] release];
+}
+
} // namespace atom
window_list->CloseAllWindows();
}
+bool Browser::OpenFile(const std::string& file_path) {
+ bool prevent_default = false;
+ FOR_EACH_OBSERVER(BrowserObserver,
+ observers_,
+ OnOpenFile(&prevent_default, file_path));
+
+ return prevent_default;
+}
+
void Browser::NotifyAndTerminate() {
bool prevent_default = false;
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillQuit(&prevent_default));
// Quit the application immediately without cleanup work.
void Terminate();
+ // Tell the application to open a file.
+ bool OpenFile(const std::string& file_path);
+
void AddObserver(BrowserObserver* obs) {
observers_.AddObserver(obs);
}
#ifndef ATOM_BROSER_BROWSER_OBSERVER_H_
#define ATOM_BROSER_BROWSER_OBSERVER_H_
+#include <string>
+
namespace atom {
class BrowserObserver {
// method will not be called, instead it will call OnWillQuit.
virtual void OnWindowAllClosed() {}
+ // The browser has opened a file by double clicking in Finder or dragging the
+ // file to the Dock icon. (OS X only)
+ virtual void OnOpenFile(bool* prevent_default,
+ const std::string& file_path) {}
+
protected:
virtual ~BrowserObserver() {}
};