| 444 | #endif |
| 445 | |
| 446 | FileBrowserHandle fileBrowserCreate(const bool isEmbed, |
| 447 | const uintptr_t windowId, |
| 448 | const double scaleFactor, |
| 449 | const FileBrowserOptions& options) |
| 450 | { |
| 451 | String startDir(options.startDir); |
| 452 | |
| 453 | if (startDir.isEmpty()) |
| 454 | { |
| 455 | #ifdef DISTRHO_OS_WINDOWS |
| 456 | if (char* const cwd = _getcwd(nullptr, 0)) |
| 457 | #else |
| 458 | if (char* const cwd = getcwd(nullptr, 0)) |
| 459 | #endif |
| 460 | { |
| 461 | startDir = cwd; |
| 462 | std::free(cwd); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | DISTRHO_SAFE_ASSERT_RETURN(startDir.isNotEmpty(), nullptr); |
| 467 | |
| 468 | if (! startDir.endsWith(DISTRHO_OS_SEP)) |
| 469 | startDir += DISTRHO_OS_SEP_STR; |
| 470 | |
| 471 | String windowTitle(options.title); |
| 472 | |
| 473 | if (windowTitle.isEmpty()) |
| 474 | windowTitle = "FileBrowser"; |
| 475 | |
| 476 | ScopedPointer<FileBrowserData> handle(new FileBrowserData(options.saving)); |
| 477 | |
| 478 | #ifdef DISTRHO_OS_MAC |
| 479 | # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 |
| 480 | // unsupported |
| 481 | d_stderr2("fileBrowserCreate is unsupported on macos < 10.8"); |
| 482 | return nullptr; |
| 483 | # else |
| 484 | NSSavePanel* const nsBasePanel = handle->nsBasePanel; |
| 485 | DISTRHO_SAFE_ASSERT_RETURN(nsBasePanel != nullptr, nullptr); |
| 486 | |
| 487 | if (! options.saving) |
| 488 | { |
| 489 | NSOpenPanel* const nsOpenPanel = handle->nsOpenPanel; |
| 490 | DISTRHO_SAFE_ASSERT_RETURN(nsOpenPanel != nullptr, nullptr); |
| 491 | |
| 492 | [nsOpenPanel setAllowsMultipleSelection:NO]; |
| 493 | [nsOpenPanel setCanChooseDirectories:NO]; |
| 494 | [nsOpenPanel setCanChooseFiles:YES]; |
| 495 | } |
| 496 | |
| 497 | NSString* const startDirString = [[NSString alloc] |
| 498 | initWithBytes:startDir |
| 499 | length:strlen(startDir) |
| 500 | encoding:NSUTF8StringEncoding]; |
| 501 | [nsBasePanel setDirectoryURL:[NSURL fileURLWithPath:startDirString]]; |
| 502 | |
| 503 | // TODO file filter using allowedContentTypes: [UTType] |
no test coverage detected