| 1 |
#include "../ta-utils.h" |
| 2 |
#include "imgui.h" |
| 3 |
#include <functional> |
| 4 |
#include "../pch.h" |
| 5 |
|
| 6 |
#if defined(_WIN32) || defined(_WIN64) || defined(__APPLE__) |
| 7 |
#ifndef SUPPORT_XP |
| 8 |
#define USE_NFD |
| 9 |
#endif |
| 10 |
#endif |
| 11 |
|
| 12 |
#ifdef USE_NFD |
| 13 |
#include <atomic> |
| 14 |
#include <thread> |
| 15 |
|
| 16 |
#ifdef __APPLE__ |
| 17 |
#define NFD_NON_THREADED |
| 18 |
#endif |
| 19 |
|
| 20 |
#elif defined(ANDROID) |
| 21 |
#include <jni.h> |
| 22 |
#elif (!defined(SUPPORT_XP) || !defined(_WIN32)) |
| 23 |
namespace pfd { |
| 24 |
class open_file; |
| 25 |
class save_file; |
| 26 |
class select_folder; |
| 27 |
} |
| 28 |
#else |
| 29 |
// nothing |
| 30 |
#endif |
| 31 |
|
| 32 |
typedef std::function<void(const char*)> FileDialogSelectCallback; |
| 33 |
|
| 34 |
class FurnaceGUIFileDialog { |
| 35 |
bool sysDialog; |
| 36 |
bool opened; |
| 37 |
unsigned char dialogType; |
| 38 |
bool hasError; |
| 39 |
char noSysFilter[4096]; |
| 40 |
String curPath; |
| 41 |
std::vector<String> fileName; |
| 42 |
#ifdef USE_NFD |
| 43 |
std::thread* dialogO; |
| 44 |
std::thread* dialogS; |
| 45 |
std::thread* dialogF; |
| 46 |
std::atomic<bool> dialogOK; |
| 47 |
std::vector<String> nfdResult; |
| 48 |
#elif defined(ANDROID) |
| 49 |
JNIEnv* jniEnv; |
| 50 |
void* dialogO; |
| 51 |
void* dialogS; |
| 52 |
void* dialogF; |
| 53 |
#elif (!defined(SUPPORT_XP) || !defined(_WIN32)) |
| 54 |
pfd::open_file* dialogO; |
| 55 |
pfd::save_file* dialogS; |
| 56 |
pfd::select_folder* dialogF; |
| 57 |
#else |
| 58 |
unsigned char* dialogO; |
| 59 |
unsigned char* dialogS; |
| 60 |
unsigned char* dialogF; |
| 61 |
#endif |
| 62 |
|
| 63 |
void convertFilterList(std::vector<String>& filter); |
| 64 |
public: |
| 65 |
bool mobileUI; |
| 66 |
bool openLoad(String header, std::vector<String> filter, String path, double dpiScale, FileDialogSelectCallback clickCallback=NULL, bool allowMultiple=false, String hint=""); |
| 67 |
bool openSave(String header, std::vector<String> filter, String path, double dpiScale, String hint=""); |
| 68 |
bool openSelectDir(String header, String path, double dpiScale, String hint=""); |
| 69 |
bool accepted(); |
| 70 |
void close(); |
| 71 |
bool render(const ImVec2& min, const ImVec2& max); |
| 72 |
bool isOpen(); |
| 73 |
bool isError(); |
| 74 |
String getPath(); |
| 75 |
std::vector<String>& getFileName(); |
| 76 |
explicit FurnaceGUIFileDialog(bool system): |
| 77 |
sysDialog(system), |
| 78 |
opened(false), |
| 79 |
dialogType(0), |
| 80 |
hasError(false), |
| 81 |
#ifdef ANDROID |
| 82 |
jniEnv(NULL), |
| 83 |
#endif |
| 84 |
dialogO(NULL), |
| 85 |
dialogS(NULL), |
| 86 |
mobileUI(false) {} |
| 87 |
}; |