From 1e6a34db813fe69959522f8bfa121f75018f4c8b Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 1 Mar 2012 12:11:17 -0800 Subject: [PATCH] Added native.openDialog --- Atom/src/native_handler.mm | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Atom/src/native_handler.mm b/Atom/src/native_handler.mm index 092f5cfcd..2638c9a10 100644 --- a/Atom/src/native_handler.mm +++ b/Atom/src/native_handler.mm @@ -10,7 +10,7 @@ NSString *stringFromCefV8Value(const CefRefPtr& value) { NativeHandler::NativeHandler() : CefV8Handler() { m_object = CefV8Value::CreateObject(NULL); - const char *functionNames[] = {"exists", "read", "write", "absolute", "list", "isFile", "isDirectory", "remove", "asyncList", "open", "quit", "writeToPasteboard", "readFromPasteboard"}; + const char *functionNames[] = {"exists", "read", "write", "absolute", "list", "isFile", "isDirectory", "remove", "asyncList", "open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard", "showDevTools"}; NSUInteger arrayLength = sizeof(functionNames) / sizeof(const char *); for (NSUInteger i = 0; i < arrayLength; i++) { const char *functionName = functionNames[i]; @@ -24,8 +24,7 @@ bool NativeHandler::Execute(const CefString& name, CefRefPtr object, const CefV8ValueList& arguments, CefRefPtr& retval, - CefString& exception) -{ + CefString& exception) { if (name == "exists") { NSString *path = stringFromCefV8Value(arguments[0]); bool exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:nil]; @@ -210,6 +209,19 @@ bool NativeHandler::Execute(const CefString& name, return true; } + else if (name == "openDialog") { + NSOpenPanel *panel = [NSOpenPanel openPanel]; + [panel setCanChooseDirectories:YES]; + if ([panel runModal] != NSFileHandlingPanelOKButton) { + retval = CefV8Value::CreateNull(); + } + else { + NSURL *url = [[panel URLs] lastObject]; + retval = CefV8Value::CreateString([[url absoluteString] UTF8String]); + } + + return true; + } else if (name == "open") { NSString *path = stringFromCefV8Value(arguments[0]); [NSApp open:path]; @@ -220,6 +232,10 @@ bool NativeHandler::Execute(const CefString& name, [NSApp terminate:nil]; return true; } + else if (name == "showDevTools") { + CefV8Context::GetCurrentContext()->GetBrowser()->ShowDevTools(); + return true; + } return false; };