| 336 | } |
| 337 | |
| 338 | void OpenFileDialogKey(const char* key, const char* title, const char* filters, const std::string& initialPath, bool saveMode) |
| 339 | { |
| 340 | key = dialog_key_or_default(key); |
| 341 | title = title ? title : "Choose File"; |
| 342 | filters = filters ? filters : ".*"; |
| 343 | const auto dialogPath = resolve_dialog_initial_directory(initialPath); |
| 344 | |
| 345 | if (can_use_native_dialog()) |
| 346 | { |
| 347 | #ifdef HAS_NFD |
| 348 | ensure_wayland_display(); |
| 349 | ParsedNFDFilters parsed = parse_igfd_filters(filters); |
| 350 | |
| 351 | nfdu8char_t* outPath = nullptr; |
| 352 | nfdresult_t result = NFD_ERROR; |
| 353 | |
| 354 | AmigaMonitor* mon = &AMonitors[0]; |
| 355 | nfdwindowhandle_t parentWindow{}; |
| 356 | if (mon->gui_window) |
| 357 | NFD_GetNativeWindowFromSDL3Window(mon->gui_window, &parentWindow); |
| 358 | |
| 359 | if (saveMode) |
| 360 | { |
| 361 | nfdsavedialogu8args_t args{}; |
| 362 | if (!parsed.items.empty()) |
| 363 | { |
| 364 | args.filterList = parsed.items.data(); |
| 365 | args.filterCount = static_cast<nfdfiltersize_t>(parsed.items.size()); |
| 366 | } |
| 367 | args.defaultPath = dialogPath.empty() ? nullptr : dialogPath.c_str(); |
| 368 | args.parentWindow = parentWindow; |
| 369 | result = NFD_SaveDialogU8_With(&outPath, &args); |
| 370 | } |
| 371 | else |
| 372 | { |
| 373 | nfdopendialogu8args_t args{}; |
| 374 | if (!parsed.items.empty()) |
| 375 | { |
| 376 | args.filterList = parsed.items.data(); |
| 377 | args.filterCount = static_cast<nfdfiltersize_t>(parsed.items.size()); |
| 378 | } |
| 379 | args.defaultPath = dialogPath.empty() ? nullptr : dialogPath.c_str(); |
| 380 | args.parentWindow = parentWindow; |
| 381 | result = NFD_OpenDialogU8_With(&outPath, &args); |
| 382 | } |
| 383 | |
| 384 | if (result == NFD_OKAY) |
| 385 | { |
| 386 | std::string path = outPath ? outPath : ""; |
| 387 | if (outPath) |
| 388 | NFD_FreePathU8(outPath); |
| 389 | s_results[key] = path; |
| 390 | if (!path.empty()) |
| 391 | macos_bookmark_store(path); |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | if (result == NFD_CANCEL) |
no test coverage detected