mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Support opening files from dialog
This commit is contained in:
@@ -82,9 +82,22 @@ void ClientHandler::OnLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefV8Value> 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<CefV8Value> pathToOpen = CefV8Value::CreateString(path);
|
||||
global->SetValue("$pathToOpen", pathToOpen, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
CefRefPtr<NativeHandler> nativeHandler = new NativeHandler();
|
||||
nativeHandler->window = window;
|
||||
nativeHandler->path = path;
|
||||
global->SetValue("$native", nativeHandler->object, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
m_nativeHandler = nativeHandler;
|
||||
|
||||
CefRefPtr<CefV8Value> atom = CefV8Value::CreateObject(NULL, NULL);
|
||||
global->SetValue("atom", atom, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
@@ -94,13 +107,7 @@ void ClientHandler::OnLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
|
||||
CefRefPtr<CefV8Value> 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<CefV8Value> pathToOpen = CefV8Value::CreateString(path);
|
||||
global->SetValue("$pathToOpen", pathToOpen, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
|
||||
context->Exit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <string>
|
||||
#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<NativeHandler> m_nativeHandler;
|
||||
|
||||
// The child browser window
|
||||
CefRefPtr<CefBrowser> m_Browser;
|
||||
|
||||
@@ -131,6 +131,13 @@ void NativeHandler::OpenDialog(const CefString& name,
|
||||
gtk_widget_destroy(dialog);
|
||||
}
|
||||
|
||||
void NativeHandler::Open(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval, CefString& exception) {
|
||||
path = arguments[0]->GetStringValue().ToString();
|
||||
CefV8Context::GetCurrentContext()->GetBrowser()->Reload();
|
||||
}
|
||||
|
||||
bool NativeHandler::Execute(const CefString& name, CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) {
|
||||
@@ -151,6 +158,8 @@ bool NativeHandler::Execute(const CefString& name, CefRefPtr<CefV8Value> 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;
|
||||
|
||||
@@ -3,14 +3,17 @@
|
||||
|
||||
#include "include/cef_base.h"
|
||||
#include "include/cef_v8.h"
|
||||
#include <string>
|
||||
|
||||
class NativeHandler: public CefV8Handler {
|
||||
public:
|
||||
NativeHandler();
|
||||
|
||||
CefRefPtr<CefV8Value> object;
|
||||
|
||||
|
||||
GtkWidget* window;
|
||||
|
||||
std::string path;
|
||||
|
||||
virtual bool Execute(const CefString& name, CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval,
|
||||
@@ -47,6 +50,10 @@ private:
|
||||
void OpenDialog(const CefString& name, CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception);
|
||||
|
||||
void Open(const CefString& name, CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user