2022-03-13 23:32:35 +00:00
|
|
|
#include "fileDialog.h"
|
|
|
|
#include "ImGuiFileDialog.h"
|
2022-03-14 04:10:43 +00:00
|
|
|
#include "../ta-log.h"
|
2022-03-14 02:19:52 +00:00
|
|
|
|
2022-03-14 03:02:50 +00:00
|
|
|
#include "../../extern/pfd-fixed/portable-file-dialogs.h"
|
2022-03-13 23:32:35 +00:00
|
|
|
|
2022-03-14 04:10:43 +00:00
|
|
|
bool FurnaceGUIFileDialog::openLoad(String header, std::vector<String> filter, const char* noSysFilter, String path, double dpiScale) {
|
2022-03-13 23:32:35 +00:00
|
|
|
if (opened) return false;
|
|
|
|
saving=false;
|
|
|
|
curPath=path;
|
|
|
|
if (sysDialog) {
|
|
|
|
dialogO=new pfd::open_file(header,path,filter);
|
|
|
|
} else {
|
|
|
|
ImGuiFileDialog::Instance()->DpiScale=dpiScale;
|
2022-03-14 04:10:43 +00:00
|
|
|
ImGuiFileDialog::Instance()->OpenModal("FileDialog",header,noSysFilter,path);
|
2022-03-13 23:32:35 +00:00
|
|
|
}
|
2022-03-14 04:10:43 +00:00
|
|
|
opened=true;
|
2022-03-13 23:32:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-14 04:10:43 +00:00
|
|
|
bool FurnaceGUIFileDialog::openSave(String header, std::vector<String> filter, const char* noSysFilter, String path, double dpiScale) {
|
|
|
|
if (opened) return false;
|
|
|
|
saving=true;
|
2022-03-13 23:32:35 +00:00
|
|
|
curPath=path;
|
|
|
|
if (sysDialog) {
|
2022-03-14 04:10:43 +00:00
|
|
|
dialogS=new pfd::save_file(header,path,filter);
|
2022-03-13 23:32:35 +00:00
|
|
|
} else {
|
|
|
|
ImGuiFileDialog::Instance()->DpiScale=dpiScale;
|
2022-03-14 04:10:43 +00:00
|
|
|
ImGuiFileDialog::Instance()->OpenModal("FileDialog",header,noSysFilter,path,1,nullptr,ImGuiFileDialogFlags_ConfirmOverwrite);
|
2022-03-13 23:32:35 +00:00
|
|
|
}
|
2022-03-14 04:10:43 +00:00
|
|
|
opened=true;
|
2022-03-13 23:32:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FurnaceGUIFileDialog::accepted() {
|
|
|
|
if (sysDialog) {
|
|
|
|
return (fileName!="");
|
|
|
|
} else {
|
|
|
|
return ImGuiFileDialog::Instance()->IsOk();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FurnaceGUIFileDialog::close() {
|
|
|
|
if (sysDialog) {
|
|
|
|
if (saving) {
|
|
|
|
if (dialogS!=NULL) {
|
|
|
|
delete dialogS;
|
|
|
|
dialogS=NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (dialogO!=NULL) {
|
|
|
|
delete dialogO;
|
|
|
|
dialogO=NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ImGuiFileDialog::Instance()->Close();
|
|
|
|
}
|
2022-03-14 04:10:43 +00:00
|
|
|
opened=false;
|
2022-03-13 23:32:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FurnaceGUIFileDialog::render(const ImVec2& min, const ImVec2& max) {
|
|
|
|
if (sysDialog) {
|
|
|
|
if (saving) {
|
|
|
|
if (dialogS!=NULL) {
|
2022-03-29 21:18:38 +00:00
|
|
|
if (dialogS->ready(0)) {
|
2022-03-13 23:32:35 +00:00
|
|
|
fileName=dialogS->result();
|
2022-03-14 04:10:43 +00:00
|
|
|
logD("returning %s\n",fileName.c_str());
|
2022-03-13 23:32:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (dialogO!=NULL) {
|
2022-03-29 21:18:38 +00:00
|
|
|
if (dialogO->ready(0)) {
|
2022-03-13 23:32:35 +00:00
|
|
|
if (dialogO->result().empty()) {
|
|
|
|
fileName="";
|
2022-03-14 04:10:43 +00:00
|
|
|
logD("returning nothing\n");
|
2022-03-13 23:32:35 +00:00
|
|
|
} else {
|
|
|
|
fileName=dialogO->result()[0];
|
2022-03-14 04:10:43 +00:00
|
|
|
logD("returning %s\n",fileName.c_str());
|
2022-03-13 23:32:35 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return ImGuiFileDialog::Instance()->Display("FileDialog",ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove,min,max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String FurnaceGUIFileDialog::getPath() {
|
|
|
|
if (sysDialog) {
|
|
|
|
return curPath;
|
|
|
|
} else {
|
|
|
|
return ImGuiFileDialog::Instance()->GetCurrentPath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String FurnaceGUIFileDialog::getFileName() {
|
|
|
|
if (sysDialog) {
|
|
|
|
return fileName;
|
|
|
|
} else {
|
|
|
|
return ImGuiFileDialog::Instance()->GetFilePathName();
|
|
|
|
}
|
2022-03-14 02:19:52 +00:00
|
|
|
}
|