Emit 'open-file' event when OS X is trying to open file with the app.
This commit is contained in:
parent
01af2fd0c5
commit
7dd48e24d3
10 changed files with 49 additions and 3 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "browser/api/atom_api_app.h"
|
#include "browser/api/atom_api_app.h"
|
||||||
|
|
||||||
|
#include "base/values.h"
|
||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
#include "browser/browser.h"
|
#include "browser/browser.h"
|
||||||
#include "vendor/node/src/node.h"
|
#include "vendor/node/src/node.h"
|
||||||
|
@ -29,6 +30,12 @@ void App::OnWindowAllClosed() {
|
||||||
Emit("window-all-closed");
|
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
|
// static
|
||||||
v8::Handle<v8::Value> App::New(const v8::Arguments &args) {
|
v8::Handle<v8::Value> App::New(const v8::Arguments &args) {
|
||||||
v8::HandleScope scope;
|
v8::HandleScope scope;
|
||||||
|
|
|
@ -26,6 +26,8 @@ class App : public EventEmitter,
|
||||||
// BrowserObserver implementations:
|
// BrowserObserver implementations:
|
||||||
virtual void OnWillQuit(bool* prevent_default) OVERRIDE;
|
virtual void OnWillQuit(bool* prevent_default) OVERRIDE;
|
||||||
virtual void OnWindowAllClosed() OVERRIDE;
|
virtual void OnWindowAllClosed() OVERRIDE;
|
||||||
|
virtual void OnOpenFile(bool* prevent_default,
|
||||||
|
const std::string& file_path) OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static v8::Handle<v8::Value> New(const v8::Arguments &args);
|
static v8::Handle<v8::Value> New(const v8::Arguments &args);
|
||||||
|
|
|
@ -16,6 +16,11 @@
|
||||||
andEventID:kAEQuitApplication];
|
andEventID:kAEQuitApplication];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)application:(NSApplication*)sender
|
||||||
|
openFile:(NSString*)filename {
|
||||||
|
return [[AtomApplication sharedApplication] openFile:filename];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)handleQuitEvent:(NSAppleEventDescriptor*)event
|
- (void)handleQuitEvent:(NSAppleEventDescriptor*)event
|
||||||
withReplyEvent:(NSAppleEventDescriptor*)replyEvent {
|
withReplyEvent:(NSAppleEventDescriptor*)replyEvent {
|
||||||
[[AtomApplication sharedApplication] closeAllWindows:self];
|
[[AtomApplication sharedApplication] closeAllWindows:self];
|
||||||
|
|
|
@ -10,13 +10,15 @@
|
||||||
BOOL handlingSendEvent_;
|
BOOL handlingSendEvent_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (AtomApplication*)sharedApplication;
|
||||||
|
|
||||||
// CrAppProtocol:
|
// CrAppProtocol:
|
||||||
- (BOOL)isHandlingSendEvent;
|
- (BOOL)isHandlingSendEvent;
|
||||||
|
|
||||||
// CrAppControlProtocol:
|
// CrAppControlProtocol:
|
||||||
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
|
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
|
||||||
|
|
||||||
+ (AtomApplication*)sharedApplication;
|
- (BOOL)openFile:(NSString*)file;
|
||||||
|
|
||||||
- (IBAction)closeAllWindows:(id)sender;
|
- (IBAction)closeAllWindows:(id)sender;
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,15 @@
|
||||||
#import "browser/atom_application_mac.h"
|
#import "browser/atom_application_mac.h"
|
||||||
|
|
||||||
#include "base/auto_reset.h"
|
#include "base/auto_reset.h"
|
||||||
|
#include "base/strings/sys_string_conversions.h"
|
||||||
#include "browser/browser.h"
|
#include "browser/browser.h"
|
||||||
|
|
||||||
@implementation AtomApplication
|
@implementation AtomApplication
|
||||||
|
|
||||||
|
+ (AtomApplication*)sharedApplication {
|
||||||
|
return (AtomApplication*)[super sharedApplication];
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL)isHandlingSendEvent {
|
- (BOOL)isHandlingSendEvent {
|
||||||
return handlingSendEvent_;
|
return handlingSendEvent_;
|
||||||
}
|
}
|
||||||
|
@ -22,8 +27,9 @@
|
||||||
handlingSendEvent_ = handlingSendEvent;
|
handlingSendEvent_ = handlingSendEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (AtomApplication*)sharedApplication {
|
- (BOOL)openFile:(NSString*)filename {
|
||||||
return (AtomApplication*)[super sharedApplication];
|
std::string filename_str(base::SysNSStringToUTF8(filename));
|
||||||
|
return atom::Browser::Get()->OpenFile(filename_str) ? YES : NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)closeAllWindows:(id)sender {
|
- (IBAction)closeAllWindows:(id)sender {
|
||||||
|
|
|
@ -31,6 +31,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||||
virtual void PostEarlyInitialization() OVERRIDE;
|
virtual void PostEarlyInitialization() OVERRIDE;
|
||||||
virtual void PreMainMessageLoopStart() OVERRIDE;
|
virtual void PreMainMessageLoopStart() OVERRIDE;
|
||||||
virtual void PreMainMessageLoopRun() OVERRIDE;
|
virtual void PreMainMessageLoopRun() OVERRIDE;
|
||||||
|
virtual void PostDestroyThreads() OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
scoped_ptr<AtomBrowserBindings> atom_bindings_;
|
scoped_ptr<AtomBrowserBindings> atom_bindings_;
|
||||||
|
|
|
@ -25,4 +25,8 @@ void AtomBrowserMainParts::PreMainMessageLoopStart() {
|
||||||
[mainNib release];
|
[mainNib release];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AtomBrowserMainParts::PostDestroyThreads() {
|
||||||
|
[[[AtomApplication sharedApplication] delegate] release];
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -32,6 +32,15 @@ void Browser::Quit() {
|
||||||
window_list->CloseAllWindows();
|
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() {
|
void Browser::NotifyAndTerminate() {
|
||||||
bool prevent_default = false;
|
bool prevent_default = false;
|
||||||
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillQuit(&prevent_default));
|
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillQuit(&prevent_default));
|
||||||
|
|
|
@ -27,6 +27,9 @@ class Browser : public WindowListObserver {
|
||||||
// Quit the application immediately without cleanup work.
|
// Quit the application immediately without cleanup work.
|
||||||
void Terminate();
|
void Terminate();
|
||||||
|
|
||||||
|
// Tell the application to open a file.
|
||||||
|
bool OpenFile(const std::string& file_path);
|
||||||
|
|
||||||
void AddObserver(BrowserObserver* obs) {
|
void AddObserver(BrowserObserver* obs) {
|
||||||
observers_.AddObserver(obs);
|
observers_.AddObserver(obs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#ifndef ATOM_BROSER_BROWSER_OBSERVER_H_
|
#ifndef ATOM_BROSER_BROWSER_OBSERVER_H_
|
||||||
#define ATOM_BROSER_BROWSER_OBSERVER_H_
|
#define ATOM_BROSER_BROWSER_OBSERVER_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
class BrowserObserver {
|
class BrowserObserver {
|
||||||
|
@ -16,6 +18,11 @@ class BrowserObserver {
|
||||||
// method will not be called, instead it will call OnWillQuit.
|
// method will not be called, instead it will call OnWillQuit.
|
||||||
virtual void OnWindowAllClosed() {}
|
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:
|
protected:
|
||||||
virtual ~BrowserObserver() {}
|
virtual ~BrowserObserver() {}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue