diff --git a/appshell/appshell_extensions.cpp b/appshell/appshell_extensions.cpp index eb40b8b3f..d9113e768 100644 --- a/appshell/appshell_extensions.cpp +++ b/appshell/appshell_extensions.cpp @@ -117,8 +117,6 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate { argList->GetType(5) != VTYPE_STRING) { error = ERR_INVALID_PARAMS; } - - CefRefPtr selectedFiles = CefListValue::Create(); if (error == NO_ERROR) { bool allowMultipleSelection = argList->GetBool(1); @@ -127,16 +125,33 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate { ExtensionString initialPath = argList->GetString(4); ExtensionString fileTypes = argList->GetString(5); +#ifdef OS_MACOSX + ShowOpenDialog(allowMultipleSelection, + chooseDirectory, + title, + initialPath, + fileTypes, + browser, + response); + + // Skip standard callback handling. ShowOpenDialog fires the + // callback asynchronously. + + return true; +#else + CefRefPtr selectedFiles = CefListValue::Create(); error = ShowOpenDialog(allowMultipleSelection, chooseDirectory, title, initialPath, fileTypes, selectedFiles); + // Set response args for this function + responseArgs->SetList(2, selectedFiles); +#endif + } - - // Set response args for this function - responseArgs->SetList(2, selectedFiles); + } else if (message_name == "ShowSaveDialog") { // Parameters: // 0: int32 - callback id @@ -150,21 +165,32 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate { error = ERR_INVALID_PARAMS; } - ExtensionString newFilePath; - if (error == NO_ERROR) { ExtensionString title = argList->GetString(1); ExtensionString initialPath = argList->GetString(2); ExtensionString proposedNewFilename = argList->GetString(3); - + +#ifdef OS_MACOSX + // Skip standard callback handling. ShowSaveDialog fires the + // callback asynchronously. + ShowSaveDialog(title, + initialPath, + proposedNewFilename, + browser, + response); + return true; +#else + ExtensionString newFilePath; error = ShowSaveDialog(title, - initialPath, - proposedNewFilename, - newFilePath); + initialPath, + proposedNewFilename, + newFilePath); + + // Set response args for this function + responseArgs->SetString(2, newFilePath); +#endif } - // Set response args for this function - responseArgs->SetString(2, newFilePath); } else if (message_name == "IsNetworkDrive") { // Parameters: // 0: int32 - callback id diff --git a/appshell/appshell_extensions_mac.mm b/appshell/appshell_extensions_mac.mm index 84ff24dae..353653949 100644 --- a/appshell/appshell_extensions_mac.mm +++ b/appshell/appshell_extensions_mac.mm @@ -375,12 +375,13 @@ int32 OpenURLInDefaultBrowser(ExtensionString url) return NO_ERROR; } -int32 ShowOpenDialog(bool allowMulitpleSelection, +void ShowOpenDialog(bool allowMulitpleSelection, bool chooseDirectory, ExtensionString title, ExtensionString initialDirectory, ExtensionString fileTypes, - CefRefPtr& selectedFiles) + CefRefPtr browser, + CefRefPtr response) { NSArray* allowedFileTypes = nil; BOOL canChooseDirectories = chooseDirectory; @@ -408,23 +409,36 @@ int32 ShowOpenDialog(bool allowMulitpleSelection, [openPanel setAllowedFileTypes:allowedFileTypes]; - [openPanel beginSheetModalForWindow:[NSApp mainWindow] completionHandler:nil]; - if ([openPanel runModal] == NSOKButton) + // cache the browser and response variables, so that these + // can be accessed from within the completionHandler block. + CefRefPtr _browser = browser; + CefRefPtr _response = response; + + [openPanel beginSheetModalForWindow:[NSApp mainWindow] completionHandler: ^(NSInteger returnCode) { - NSArray* urls = [openPanel URLs]; - for (NSUInteger i = 0; i < [urls count]; i++) { - selectedFiles->SetString(i, [[[urls objectAtIndex:i] path] UTF8String]); + if(_browser && _response){ + + NSArray *urls = [openPanel URLs]; + CefRefPtr selectedFiles = CefListValue::Create(); + if (returnCode == NSModalResponseOK){ + for (NSUInteger i = 0; i < [urls count]; i++) { + selectedFiles->SetString(i, [[[urls objectAtIndex:i] path] UTF8String]); + } + } + + // Set common response args (error and selectedfiles list) + _response->GetArgumentList()->SetInt(1, NO_ERROR); + _response->GetArgumentList()->SetList(2, selectedFiles); + _browser->SendProcessMessage(PID_RENDERER, _response); } - } - [NSApp endSheet:openPanel]; - - return NO_ERROR; + }]; } -int32 ShowSaveDialog(ExtensionString title, +void ShowSaveDialog(ExtensionString title, ExtensionString initialDirectory, ExtensionString proposedNewFilename, - ExtensionString& absoluteFilepath) + CefRefPtr browser, + CefRefPtr response) { NSSavePanel* savePanel = [NSSavePanel savePanel]; [savePanel setTitle: [NSString stringWithUTF8String:title.c_str()]]; @@ -436,17 +450,29 @@ int32 ShowSaveDialog(ExtensionString title, } [savePanel setNameFieldStringValue:[NSString stringWithUTF8String:proposedNewFilename.c_str()]]; - [savePanel beginSheetModalForWindow:[NSApp mainWindow] completionHandler:nil]; - - if ([savePanel runModal] == NSFileHandlingPanelOKButton) - { - NSURL* theFile = [savePanel URL]; - absoluteFilepath = [[theFile path] UTF8String]; - } - [NSApp endSheet:savePanel]; + // cache the browser and response variables, so that these + // can be accessed from within the completionHandler block. + CefRefPtr _browser = browser; + CefRefPtr _response = response; - return NO_ERROR; + [savePanel beginSheetModalForWindow:[NSApp mainWindow] completionHandler: ^(NSInteger returnCode) + { + if(_response && _browser){ + + CefString pathStr; + if (returnCode == NSModalResponseOK){ + NSURL* selectedFile = [savePanel URL]; + if(selectedFile) + pathStr = [[selectedFile path] UTF8String]; + } + + // Set common response args (error and the new file name string) + _response->GetArgumentList()->SetInt(1, NO_ERROR); + _response->GetArgumentList()->SetString(2, pathStr); + _browser->SendProcessMessage(PID_RENDERER, _response); + } + }]; } int32 IsNetworkDrive(ExtensionString path, bool& isRemote) diff --git a/appshell/appshell_extensions_platform.h b/appshell/appshell_extensions_platform.h index 9114b8f01..1d09e3bee 100644 --- a/appshell/appshell_extensions_platform.h +++ b/appshell/appshell_extensions_platform.h @@ -86,6 +86,7 @@ void CloseLiveBrowser(CefRefPtr browser, CefRefPtr browser, + CefRefPtr response); + +void ShowSaveDialog(ExtensionString title, + ExtensionString initialDirectory, + ExtensionString proposedNewFilename, + CefRefPtr browser, + CefRefPtr response); +#endif int32 IsNetworkDrive(ExtensionString path, bool& isRemote); diff --git a/appshell/client_handler_mac.mm b/appshell/client_handler_mac.mm index 46881fb67..6fb1474b2 100644 --- a/appshell/client_handler_mac.mm +++ b/appshell/client_handler_mac.mm @@ -61,6 +61,14 @@ if ([window styleMask] & NSFullScreenWindowMask) { [window setTitle:str]; } + // This is required as we are now managing the window's title + // on our own, using CustomTitlbeBarView. As we are nuking the + // window's title, currently open windows like new brackets + // windows/dev tools are not getting listed under the + // 'Window' menu. So we are now explicitly telling OS to make + // sure we have a menu entry under 'Window' menu. This is a + // safe call and is officially supported. + [NSApp changeWindowsItem:window title:str filename:NO]; [delegate performSelectorOnMainThread:@selector(windowTitleDidChange:) withObject:str waitUntilDone:NO]; }