From f1b6bf152d000f2bcad3e5217c95826fc77ef82b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 4 Jun 2012 15:57:51 -0700 Subject: [PATCH] Support opening files from dialog --- Atom-Linux/client_handler.cpp | 21 ++++++++++++++------- Atom-Linux/client_handler.h | 3 +++ Atom-Linux/native_handler.cpp | 9 +++++++++ Atom-Linux/native_handler.h | 9 ++++++++- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Atom-Linux/client_handler.cpp b/Atom-Linux/client_handler.cpp index ca4cecb6e..5a9e0b289 100644 --- a/Atom-Linux/client_handler.cpp +++ b/Atom-Linux/client_handler.cpp @@ -82,9 +82,22 @@ void ClientHandler::OnLoadStart(CefRefPtr browser, CefRefPtr windowNumber = CefV8Value::CreateInt(0); global->SetValue("$windowNumber", windowNumber, V8_PROPERTY_ATTRIBUTE_NONE); + std::string path; + if (m_nativeHandler) + path = m_nativeHandler->path; + else { + path.append(AppGetWorkingDirectory()); + path.append("/../src/app/atom.coffee"); + } + + CefRefPtr pathToOpen = CefV8Value::CreateString(path); + global->SetValue("$pathToOpen", pathToOpen, V8_PROPERTY_ATTRIBUTE_NONE); + CefRefPtr nativeHandler = new NativeHandler(); nativeHandler->window = window; + nativeHandler->path = path; global->SetValue("$native", nativeHandler->object, V8_PROPERTY_ATTRIBUTE_NONE); + m_nativeHandler = nativeHandler; CefRefPtr atom = CefV8Value::CreateObject(NULL, NULL); global->SetValue("atom", atom, V8_PROPERTY_ATTRIBUTE_NONE); @@ -94,13 +107,7 @@ void ClientHandler::OnLoadStart(CefRefPtr browser, CefRefPtr bootstrapScript = CefV8Value::CreateString("window-bootstrap"); global->SetValue("$bootstrapScript", bootstrapScript, V8_PROPERTY_ATTRIBUTE_NONE); - - std::string path; - path.append(AppGetWorkingDirectory()); - path.append("/../src/app/atom.coffee"); - CefRefPtr pathToOpen = CefV8Value::CreateString(path); - global->SetValue("$pathToOpen", pathToOpen, V8_PROPERTY_ATTRIBUTE_NONE); - + context->Exit(); } } diff --git a/Atom-Linux/client_handler.h b/Atom-Linux/client_handler.h index 2426ea8c8..a555ee764 100644 --- a/Atom-Linux/client_handler.h +++ b/Atom-Linux/client_handler.h @@ -10,6 +10,7 @@ #include #include "include/cef_client.h" #include "util.h" +#include "native_handler.h" // Define this value to redirect all popup URLs to the main application browser @@ -173,6 +174,8 @@ class ClientHandler : public CefClient, void SetNavState(bool canGoBack, bool canGoForward); GtkWidget* window; + + CefRefPtr m_nativeHandler; // The child browser window CefRefPtr m_Browser; diff --git a/Atom-Linux/native_handler.cpp b/Atom-Linux/native_handler.cpp index bcf3fa361..8c10d5c07 100644 --- a/Atom-Linux/native_handler.cpp +++ b/Atom-Linux/native_handler.cpp @@ -131,6 +131,13 @@ void NativeHandler::OpenDialog(const CefString& name, gtk_widget_destroy(dialog); } +void NativeHandler::Open(const CefString& name, + CefRefPtr object, const CefV8ValueList& arguments, + CefRefPtr& retval, CefString& exception) { + path = arguments[0]->GetStringValue().ToString(); + CefV8Context::GetCurrentContext()->GetBrowser()->Reload(); +} + bool NativeHandler::Execute(const CefString& name, CefRefPtr object, const CefV8ValueList& arguments, CefRefPtr& retval, CefString& exception) { @@ -151,6 +158,8 @@ bool NativeHandler::Execute(const CefString& name, CefRefPtr object, CefV8Context::GetCurrentContext()->GetBrowser()->ShowDevTools(); else if (name == "openDialog") OpenDialog(name, object, arguments, retval, exception); + else if(name =="open") + Open(name, object, arguments, retval, exception); else cout << "Unhandled -> " + name.ToString() << " : " << arguments[0]->GetStringValue().ToString() << endl; diff --git a/Atom-Linux/native_handler.h b/Atom-Linux/native_handler.h index 9c299cc70..f2f8a39a6 100644 --- a/Atom-Linux/native_handler.h +++ b/Atom-Linux/native_handler.h @@ -3,14 +3,17 @@ #include "include/cef_base.h" #include "include/cef_v8.h" +#include class NativeHandler: public CefV8Handler { public: NativeHandler(); CefRefPtr object; - + GtkWidget* window; + + std::string path; virtual bool Execute(const CefString& name, CefRefPtr object, const CefV8ValueList& arguments, CefRefPtr& retval, @@ -47,6 +50,10 @@ private: void OpenDialog(const CefString& name, CefRefPtr object, const CefV8ValueList& arguments, CefRefPtr& retval, CefString& exception); + + void Open(const CefString& name, CefRefPtr object, + const CefV8ValueList& arguments, CefRefPtr& retval, + CefString& exception); }; #endif