mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-24 03:39:56 -04:00
add task-based file picking functions
This commit is contained in:
parent
d5d5c3adb7
commit
e7df9a7a03
3 changed files with 15 additions and 5 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "MiniFunction.hpp"
|
||||
#include "../loader/Event.hpp"
|
||||
#include "../loader/Loader.hpp"
|
||||
#include <mutex>
|
||||
|
||||
namespace geode {
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "Result.hpp"
|
||||
#include "general.hpp"
|
||||
#include "../loader/Event.hpp"
|
||||
#include "Task.hpp"
|
||||
|
||||
#include <matjson.hpp>
|
||||
#include <Geode/DefaultInclude.hpp>
|
||||
|
@ -257,7 +258,7 @@ namespace geode::utils::file {
|
|||
* @param mode Type of file selection prompt to show
|
||||
* @param options Picker options
|
||||
*/
|
||||
[[deprecated("Use overload with callback instead, this will be removed in a later version.")]]
|
||||
[[deprecated("Use pick() instead, this will be removed in a later version.")]]
|
||||
GEODE_DLL Result<ghc::filesystem::path> pickFile(PickMode mode, FilePickOptions const& options);
|
||||
|
||||
GEODE_DLL void pickFile(
|
||||
|
@ -265,13 +266,14 @@ namespace geode::utils::file {
|
|||
utils::MiniFunction<void(ghc::filesystem::path)> callback,
|
||||
utils::MiniFunction<void()> failed = {}
|
||||
);
|
||||
GEODE_DLL Task<Result<ghc::filesystem::path>> pick(PickMode mode, FilePickOptions const& options);
|
||||
|
||||
/**
|
||||
* Prompt the user to pick a bunch of files for opening using the system's file system picker
|
||||
* @deprecated Will not work on Android, use the callback version instead
|
||||
* @param options Picker options
|
||||
*/
|
||||
[[deprecated("Use overload with callback instead, this will be removed in a later version.")]]
|
||||
[[deprecated("Use pickMany() instead, this will be removed in a later version.")]]
|
||||
GEODE_DLL Result<std::vector<ghc::filesystem::path>> pickFiles(FilePickOptions const& options);
|
||||
|
||||
GEODE_DLL void pickFiles(
|
||||
|
@ -279,6 +281,7 @@ namespace geode::utils::file {
|
|||
utils::MiniFunction<void(std::vector<ghc::filesystem::path>)> callback,
|
||||
utils::MiniFunction<void()> failed = {}
|
||||
);
|
||||
GEODE_DLL Task<Result<std::vector<ghc::filesystem::path>>> pickMany(FilePickOptions const& options);
|
||||
|
||||
class GEODE_DLL FileWatchEvent : public Event {
|
||||
protected:
|
||||
|
|
|
@ -121,7 +121,7 @@ Result<ghc::filesystem::path> utils::file::pickFile(
|
|||
return Ok(path);
|
||||
}
|
||||
|
||||
GEODE_DLL void file::pickFile(
|
||||
void file::pickFile(
|
||||
PickMode mode, FilePickOptions const& options,
|
||||
MiniFunction<void(ghc::filesystem::path)> callback,
|
||||
MiniFunction<void()> failed
|
||||
|
@ -134,16 +134,19 @@ GEODE_DLL void file::pickFile(
|
|||
failed();
|
||||
}
|
||||
}
|
||||
Task<Result<ghc::filesystem::path>> file::pick(PickMode mode, FilePickOptions const& options) {
|
||||
return Task<Result<ghc::filesystem::path>>::immediate(std::move(file::pickFile(mode, options)));
|
||||
}
|
||||
|
||||
Result<std::vector<ghc::filesystem::path>> utils::file::pickFiles(
|
||||
file::FilePickOptions const& options
|
||||
) {
|
||||
std::vector<ghc::filesystem::path> paths;
|
||||
GEODE_UNWRAP(nfdPick(NFDMode::OpenFolder, options, &paths));
|
||||
GEODE_UNWRAP(nfdPick(NFDMode::OpenFiles, options, &paths));
|
||||
return Ok(paths);
|
||||
}
|
||||
|
||||
GEODE_DLL void file::pickFiles(
|
||||
void file::pickFiles(
|
||||
FilePickOptions const& options,
|
||||
MiniFunction<void(std::vector<ghc::filesystem::path>)> callback,
|
||||
MiniFunction<void()> failed
|
||||
|
@ -156,6 +159,9 @@ GEODE_DLL void file::pickFiles(
|
|||
failed();
|
||||
}
|
||||
}
|
||||
Task<Result<std::vector<ghc::filesystem::path>>> file::pickMany(FilePickOptions const& options) {
|
||||
return Task<Result<std::vector<ghc::filesystem::path>>>::immediate(std::move(file::pickFiles(options)));
|
||||
}
|
||||
|
||||
void utils::web::openLinkInBrowser(std::string const& url) {
|
||||
ShellExecuteA(0, 0, url.c_str(), 0, 0, SW_SHOW);
|
||||
|
|
Loading…
Add table
Reference in a new issue