feat(cmake): add native file dialog support for Windows/Linux
- Introduced a new file dialog implementation using nativefiledialog-extended for better file handling on Windows and Linux platforms. - Updated CMake configuration to link the new file dialog library and include necessary directories. - Enhanced the editor library to conditionally link a test support library when testing is enabled. Benefits: - Improved user experience with native file dialogs for file operations. - Streamlined testing support in the editor library, enhancing modularity and maintainability.
This commit is contained in:
@@ -10,6 +10,7 @@ if (WIN32 OR MINGW OR (UNIX AND NOT APPLE))
|
|||||||
list(APPEND YAZE_APP_CORE_SRC
|
list(APPEND YAZE_APP_CORE_SRC
|
||||||
app/platform/font_loader.cc
|
app/platform/font_loader.cc
|
||||||
app/platform/asset_loader.cc
|
app/platform/asset_loader.cc
|
||||||
|
app/platform/file_dialog_nfd.cc # NFD file dialog for Windows/Linux
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -102,6 +103,13 @@ target_link_libraries(yaze_core_lib PUBLIC
|
|||||||
${CMAKE_DL_LIBS}
|
${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
|
target_sources(yaze_core_lib PRIVATE
|
||||||
${CMAKE_SOURCE_DIR}/src/cli/service/testing/test_workflow_generator.cc
|
${CMAKE_SOURCE_DIR}/src/cli/service/testing/test_workflow_generator.cc
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -108,6 +108,11 @@ target_link_libraries(yaze_editor PUBLIC
|
|||||||
ImGui
|
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)
|
if(YAZE_WITH_JSON)
|
||||||
target_include_directories(yaze_editor PUBLIC
|
target_include_directories(yaze_editor PUBLIC
|
||||||
${CMAKE_SOURCE_DIR}/third_party/json/include)
|
${CMAKE_SOURCE_DIR}/third_party/json/include)
|
||||||
|
|||||||
122
src/app/platform/file_dialog_nfd.cc
Normal file
122
src/app/platform/file_dialog_nfd.cc
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
// Windows and Linux implementation of FileDialogWrapper using nativefiledialog-extended
|
||||||
|
#include "util/file_util.h"
|
||||||
|
|
||||||
|
#include <nfd.h>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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<std::string> FileDialogWrapper::GetSubdirectoriesInFolder(
|
||||||
|
const std::string& folder_path) {
|
||||||
|
std::vector<std::string> 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<std::string> FileDialogWrapper::GetFilesInFolder(
|
||||||
|
const std::string& folder_path) {
|
||||||
|
std::vector<std::string> 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
|
||||||
|
|
||||||
Reference in New Issue
Block a user