diff --git a/src/app/core/core_library.cmake b/src/app/core/core_library.cmake index 3ec626fa..8ba2d4c2 100644 --- a/src/app/core/core_library.cmake +++ b/src/app/core/core_library.cmake @@ -10,6 +10,7 @@ if (WIN32 OR MINGW OR (UNIX AND NOT APPLE)) list(APPEND YAZE_APP_CORE_SRC app/platform/font_loader.cc app/platform/asset_loader.cc + app/platform/file_dialog_nfd.cc # NFD file dialog for Windows/Linux ) endif() @@ -102,6 +103,13 @@ target_link_libraries(yaze_core_lib PUBLIC ${CMAKE_DL_LIBS} ) +# Link nativefiledialog-extended for Windows/Linux file dialogs +if(WIN32 OR (UNIX AND NOT APPLE)) + add_subdirectory(${CMAKE_SOURCE_DIR}/src/lib/nativefiledialog-extended ${CMAKE_BINARY_DIR}/nfd EXCLUDE_FROM_ALL) + target_link_libraries(yaze_core_lib PUBLIC nfd) + target_include_directories(yaze_core_lib PUBLIC ${CMAKE_SOURCE_DIR}/src/lib/nativefiledialog-extended/src/include) +endif() + target_sources(yaze_core_lib PRIVATE ${CMAKE_SOURCE_DIR}/src/cli/service/testing/test_workflow_generator.cc ) diff --git a/src/app/editor/editor_library.cmake b/src/app/editor/editor_library.cmake index 73e83617..336270dd 100644 --- a/src/app/editor/editor_library.cmake +++ b/src/app/editor/editor_library.cmake @@ -108,6 +108,11 @@ target_link_libraries(yaze_editor PUBLIC ImGui ) +# Link test support library if testing is enabled (for TestManager) +if(YAZE_BUILD_TESTS AND TARGET yaze_test_support) + target_link_libraries(yaze_editor PUBLIC yaze_test_support) +endif() + if(YAZE_WITH_JSON) target_include_directories(yaze_editor PUBLIC ${CMAKE_SOURCE_DIR}/third_party/json/include) diff --git a/src/app/platform/file_dialog_nfd.cc b/src/app/platform/file_dialog_nfd.cc new file mode 100644 index 00000000..e3c85e5d --- /dev/null +++ b/src/app/platform/file_dialog_nfd.cc @@ -0,0 +1,122 @@ +// Windows and Linux implementation of FileDialogWrapper using nativefiledialog-extended +#include "util/file_util.h" + +#include +#include +#include +#include + +namespace yaze { +namespace util { + +std::string FileDialogWrapper::ShowOpenFileDialog() { + nfdchar_t* outPath = nullptr; + nfdresult_t result = NFD_OpenDialog(nullptr, nullptr, &outPath); + + if (result == NFD_OKAY) { + std::string path(outPath); + NFD_FreePath(outPath); + return path; + } + + return ""; +} + +std::string FileDialogWrapper::ShowOpenFolderDialog() { + nfdchar_t* outPath = nullptr; + nfdresult_t result = NFD_PickFolder(nullptr, &outPath); + + if (result == NFD_OKAY) { + std::string path(outPath); + NFD_FreePath(outPath); + return path; + } + + return ""; +} + +std::string FileDialogWrapper::ShowSaveFileDialog(const std::string& default_name, + const std::string& default_extension) { + nfdchar_t* outPath = nullptr; + nfdfilteritem_t filterItem[1] = {{default_extension.empty() ? "All Files" : default_extension.c_str(), + default_extension.empty() ? "*" : default_extension.c_str()}}; + + nfdresult_t result = NFD_SaveDialog(default_extension.empty() ? nullptr : filterItem, + default_extension.empty() ? 0 : 1, + nullptr, + default_name.c_str(), + &outPath); + + if (result == NFD_OKAY) { + std::string path(outPath); + NFD_FreePath(outPath); + return path; + } + + return ""; +} + +std::vector FileDialogWrapper::GetSubdirectoriesInFolder( + const std::string& folder_path) { + std::vector subdirs; + + try { + for (const auto& entry : std::filesystem::directory_iterator(folder_path)) { + if (entry.is_directory()) { + subdirs.push_back(entry.path().string()); + } + } + } catch (...) { + // Return empty vector on error + } + + return subdirs; +} + +std::vector FileDialogWrapper::GetFilesInFolder( + const std::string& folder_path) { + std::vector files; + + try { + for (const auto& entry : std::filesystem::directory_iterator(folder_path)) { + if (entry.is_regular_file()) { + files.push_back(entry.path().string()); + } + } + } catch (...) { + // Return empty vector on error + } + + return files; +} + +// Delegate to main implementations +std::string FileDialogWrapper::ShowOpenFileDialogNFD() { + return ShowOpenFileDialog(); +} + +std::string FileDialogWrapper::ShowOpenFileDialogBespoke() { + return ShowOpenFileDialog(); +} + +std::string FileDialogWrapper::ShowSaveFileDialogNFD(const std::string& default_name, + const std::string& default_extension) { + return ShowSaveFileDialog(default_name, default_extension); +} + +std::string FileDialogWrapper::ShowSaveFileDialogBespoke(const std::string& default_name, + const std::string& default_extension) { + return ShowSaveFileDialog(default_name, default_extension); +} + +std::string FileDialogWrapper::ShowOpenFolderDialogNFD() { + return ShowOpenFolderDialog(); +} + +std::string FileDialogWrapper::ShowOpenFolderDialogBespoke() { + return ShowOpenFolderDialog(); +} + +} // namespace util +} // namespace yaze +