@@ -366,14 +366,57 @@ void cef_main_window::RestoreWindowPlacement(int showCmd)
366366BOOL cef_main_window::HandleCopyData (HWND, PCOPYDATASTRUCT lpCopyData)
367367{
368368 if ((lpCopyData) && (lpCopyData->dwData == ID_WM_COPYDATA_SENDOPENFILECOMMAND) && (lpCopyData->cbData > 0 )) {
369- // another Brackets instance requests that we open the given filename
369+ // another Brackets instance requests that we open the given files/folders
370370 std::wstring wstrFilename = (LPCWSTR)lpCopyData->lpData ;
371+ std::wstring wstrFileArray = L" [" ;
372+ bool hasMultipleFiles = false ;
373+
374+ if (wstrFilename.find (' "' ) != std::wstring::npos) {
375+ if (wstrFilename.find (L" \" " ) != std::wstring::npos ||
376+ (wstrFilename.front () != ' "' || wstrFilename.back () != ' "' )) {
377+ hasMultipleFiles = true ;
378+ }
379+ } else {
380+ hasMultipleFiles = (wstrFilename.find (L" " ) != std::wstring::npos);
381+ }
371382
372- // Windows Explorer might enclose the filename in double-quotes. We need to strip these off.
373- if ((wstrFilename.front () == ' \" ' ) && wstrFilename.back () == ' \" ' )
374- wstrFilename = wstrFilename.substr (1 , wstrFilename.length () - 2 );
383+ if (hasMultipleFiles) {
384+ std::size_t curFilePathEnd1 = wstrFilename.find (L" " );
385+ std::size_t curFilePathEnd2 = wstrFilename.find (L" \" " );
386+ std::size_t nextQuoteIndex = wstrFilename.find (L" \" " );
387+
388+ while ((nextQuoteIndex == 0 && curFilePathEnd2 != std::wstring::npos) ||
389+ (nextQuoteIndex != 0 && curFilePathEnd1 != std::wstring::npos)) {
390+
391+ if (nextQuoteIndex == 0 && curFilePathEnd2 != std::wstring::npos) {
392+ // Appending a file path that is already wrapped in double-quotes.
393+ wstrFileArray += (wstrFilename.substr (0 , curFilePathEnd2 + 1 ) + L" ," );
394+
395+ // Strip the current file path and move index to next file path.
396+ wstrFilename = wstrFilename.substr (curFilePathEnd2 + 2 );
397+ } else {
398+ // Explicitly wrap a file path in double-quotes and append it to the file array.
399+ wstrFileArray += (L" \" " + wstrFilename.substr (0 , curFilePathEnd1) + L" \" ," );
400+
401+ // Strip the current file path and move index to next file path.
402+ wstrFilename = wstrFilename.substr (curFilePathEnd1 + 1 );
403+ }
404+
405+ curFilePathEnd1 = wstrFilename.find (L" " );
406+ curFilePathEnd2 = wstrFilename.find (L" \" " );
407+ nextQuoteIndex = wstrFilename.find (L" \" " );
408+ }
409+ }
410+
411+ // Add the last file or the only file into the file array.
412+ if (wstrFilename.front () == ' "' && wstrFilename.back () == ' "' ) {
413+ wstrFileArray += wstrFilename;
414+ } else if (wstrFilename.length ()) {
415+ wstrFileArray += (L" \" " + wstrFilename + L" \" " );
416+ }
417+ wstrFileArray += L" ]" ;
375418
376- g_handler->SendOpenFileCommand (g_handler->GetBrowser (), CefString (wstrFilename .c_str ()));
419+ g_handler->SendOpenFileCommand (g_handler->GetBrowser (), CefString (wstrFileArray .c_str ()));
377420 return TRUE ;
378421 }
379422
0 commit comments