mirror of
https://github.com/Zelda64Recomp/Zelda64Recomp.git
synced 2025-10-30 08:03:03 +00:00
Use a multiple file select dialog for mod install button
This commit is contained in:
parent
e44abf27cb
commit
55bfc0153a
3 changed files with 37 additions and 2 deletions
|
|
@ -3,10 +3,12 @@
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace zelda64 {
|
namespace zelda64 {
|
||||||
std::filesystem::path get_asset_path(const char* asset);
|
std::filesystem::path get_asset_path(const char* asset);
|
||||||
void open_file_dialog(std::function<void(bool success, const std::filesystem::path& path)> callback);
|
void open_file_dialog(std::function<void(bool success, const std::filesystem::path& path)> callback);
|
||||||
|
void open_file_dialog_multiple(std::function<void(bool success, const std::list<std::filesystem::path>& paths)> callback);
|
||||||
void show_error_message_box(const char *title, const char *message);
|
void show_error_message_box(const char *title, const char *message);
|
||||||
|
|
||||||
// Apple specific methods that usually require Objective-C. Implemented in support_apple.mm.
|
// Apple specific methods that usually require Objective-C. Implemented in support_apple.mm.
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,29 @@ namespace zelda64 {
|
||||||
callback(success, path);
|
callback(success, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void perform_file_dialog_operation_multiple(const std::function<void(bool, const std::list<std::filesystem::path>&)>& callback) {
|
||||||
|
const nfdpathset_t* native_paths = nullptr;
|
||||||
|
nfdresult_t result = NFD_OpenDialogMultipleN(&native_paths, nullptr, 0, nullptr);
|
||||||
|
|
||||||
|
bool success = (result == NFD_OKAY);
|
||||||
|
std::list<std::filesystem::path> paths;
|
||||||
|
nfdpathsetsize_t count = 0;
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
NFD_PathSet_GetCount(native_paths, &count);
|
||||||
|
for (nfdpathsetsize_t i = 0; i < count; i++) {
|
||||||
|
nfdnchar_t* cur_path = nullptr;
|
||||||
|
nfdresult_t cur_result = NFD_PathSet_GetPathN(native_paths, i, &cur_path);
|
||||||
|
if (cur_result == NFD_OKAY) {
|
||||||
|
paths.emplace_back(std::filesystem::path{cur_path});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NFD_PathSet_Free(native_paths);
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(success, paths);
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Public API
|
// MARK: - Public API
|
||||||
|
|
||||||
std::filesystem::path get_asset_path(const char* asset) {
|
std::filesystem::path get_asset_path(const char* asset) {
|
||||||
|
|
@ -41,6 +64,16 @@ namespace zelda64 {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void open_file_dialog_multiple(std::function<void(bool success, const std::list<std::filesystem::path>& paths)> callback) {
|
||||||
|
#ifdef __APPLE__
|
||||||
|
dispatch_on_ui_thread([callback]() {
|
||||||
|
perform_file_dialog_operation_multiple(callback);
|
||||||
|
});
|
||||||
|
#else
|
||||||
|
perform_file_dialog_operation_multiple(callback);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void show_error_message_box(const char *title, const char *message) {
|
void show_error_message_box(const char *title, const char *message) {
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
std::string title_copy(title);
|
std::string title_copy(title);
|
||||||
|
|
|
||||||
|
|
@ -243,11 +243,11 @@ void ModMenu::open_mods_folder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModMenu::open_install_dialog() {
|
void ModMenu::open_install_dialog() {
|
||||||
zelda64::open_file_dialog([](bool success, const std::filesystem::path& path) {
|
zelda64::open_file_dialog_multiple([](bool success, const std::list<std::filesystem::path>& paths) {
|
||||||
if (success) {
|
if (success) {
|
||||||
ContextId old_context = recompui::try_close_current_context();
|
ContextId old_context = recompui::try_close_current_context();
|
||||||
|
|
||||||
recompui::drop_files({ path });
|
recompui::drop_files(paths);
|
||||||
|
|
||||||
if (old_context != ContextId::null()) {
|
if (old_context != ContextId::null()) {
|
||||||
old_context.open();
|
old_context.open();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue