GUI: system file picker error feedback

This commit is contained in:
tildearrow 2022-07-14 01:59:55 -05:00
parent 5f92a6ffa6
commit 28a2db7a57
3 changed files with 25 additions and 5 deletions

View file

@ -25,9 +25,10 @@ struct NFDState {
}; };
// TODO: filter // TODO: filter
void _nfdThread(const NFDState state, std::atomic<bool>* ok, String* result) { void _nfdThread(const NFDState state, std::atomic<bool>* ok, String* result, bool* errorOutput) {
nfdchar_t* out=NULL; nfdchar_t* out=NULL;
nfdresult_t ret=NFD_CANCEL; nfdresult_t ret=NFD_CANCEL;
errorOutput=false;
if (state.isSave) { if (state.isSave) {
ret=NFD_SaveDialog(state.filter,state.path.c_str(),&out,state.clickCallback); ret=NFD_SaveDialog(state.filter,state.path.c_str(),&out,state.clickCallback);
@ -49,6 +50,7 @@ void _nfdThread(const NFDState state, std::atomic<bool>* ok, String* result) {
case NFD_ERROR: case NFD_ERROR:
(*result)=""; (*result)="";
logE("NFD error! %s\n",NFD_GetError()); logE("NFD error! %s\n",NFD_GetError());
(*errorOutput)=true;
break; break;
default: default:
logE("NFD unknown return code %d!\n",ret); logE("NFD unknown return code %d!\n",ret);
@ -68,14 +70,16 @@ bool FurnaceGUIFileDialog::openLoad(String header, std::vector<String> filter, c
#ifdef USE_NFD #ifdef USE_NFD
dialogOK=false; dialogOK=false;
#ifdef NFD_NON_THREADED #ifdef NFD_NON_THREADED
_nfdThread(NFDState(false,header,filter,path,clickCallback),&dialogOK,&nfdResult); _nfdThread(NFDState(false,header,filter,path,clickCallback),&dialogOK,&nfdResult,&hasError);
#else #else
dialogO=new std::thread(_nfdThread,NFDState(false,header,filter,path,clickCallback),&dialogOK,&nfdResult); dialogO=new std::thread(_nfdThread,NFDState(false,header,filter,path,clickCallback),&dialogOK,&nfdResult,&hasError);
#endif #endif
#else #else
dialogO=new pfd::open_file(header,path,filter); dialogO=new pfd::open_file(header,path,filter);
hasError=!pfd::settings::available();
#endif #endif
} else { } else {
hasError=false;
ImGuiFileDialog::Instance()->DpiScale=dpiScale; ImGuiFileDialog::Instance()->DpiScale=dpiScale;
ImGuiFileDialog::Instance()->OpenModal("FileDialog",header,noSysFilter,path,1,nullptr,0,clickCallback); ImGuiFileDialog::Instance()->OpenModal("FileDialog",header,noSysFilter,path,1,nullptr,0,clickCallback);
} }
@ -92,14 +96,16 @@ bool FurnaceGUIFileDialog::openSave(String header, std::vector<String> filter, c
#ifdef USE_NFD #ifdef USE_NFD
dialogOK=false; dialogOK=false;
#ifdef NFD_NON_THREADED #ifdef NFD_NON_THREADED
_nfdThread(NFDState(true,header,filter,path,NULL),&dialogOK,&nfdResult); _nfdThread(NFDState(true,header,filter,path,NULL),&dialogOK,&nfdResult,&hasError);
#else #else
dialogS=new std::thread(_nfdThread,NFDState(true,header,filter,path,NULL),&dialogOK,&nfdResult); dialogS=new std::thread(_nfdThread,NFDState(true,header,filter,path,NULL),&dialogOK,&nfdResult,&hasError);
#endif #endif
#else #else
dialogS=new pfd::save_file(header,path,filter); dialogS=new pfd::save_file(header,path,filter);
hasError=!pfd::settings::available();
#endif #endif
} else { } else {
hasError=false;
ImGuiFileDialog::Instance()->DpiScale=dpiScale; ImGuiFileDialog::Instance()->DpiScale=dpiScale;
ImGuiFileDialog::Instance()->OpenModal("FileDialog",header,noSysFilter,path,1,nullptr,ImGuiFileDialogFlags_ConfirmOverwrite); ImGuiFileDialog::Instance()->OpenModal("FileDialog",header,noSysFilter,path,1,nullptr,ImGuiFileDialogFlags_ConfirmOverwrite);
} }
@ -193,6 +199,10 @@ bool FurnaceGUIFileDialog::isOpen() {
return opened; return opened;
} }
bool FurnaceGUIFileDialog::isError() {
return hasError;
}
String FurnaceGUIFileDialog::getPath() { String FurnaceGUIFileDialog::getPath() {
if (sysDialog) { if (sysDialog) {
if (curPath.size()>1) { if (curPath.size()>1) {

View file

@ -28,6 +28,7 @@ class FurnaceGUIFileDialog {
bool sysDialog; bool sysDialog;
bool opened; bool opened;
bool saving; bool saving;
bool hasError;
String curPath; String curPath;
String fileName; String fileName;
#ifdef USE_NFD #ifdef USE_NFD
@ -46,12 +47,14 @@ class FurnaceGUIFileDialog {
void close(); void close();
bool render(const ImVec2& min, const ImVec2& max); bool render(const ImVec2& min, const ImVec2& max);
bool isOpen(); bool isOpen();
bool isError();
String getPath(); String getPath();
String getFileName(); String getFileName();
explicit FurnaceGUIFileDialog(bool system): explicit FurnaceGUIFileDialog(bool system):
sysDialog(system), sysDialog(system),
opened(false), opened(false),
saving(false), saving(false),
hasError(false),
dialogO(NULL), dialogO(NULL),
dialogS(NULL) {} dialogS(NULL) {}
}; };

View file

@ -3221,6 +3221,13 @@ bool FurnaceGUI::loop() {
workingDirROM=fileDialog->getPath()+DIR_SEPARATOR_STR; workingDirROM=fileDialog->getPath()+DIR_SEPARATOR_STR;
break; break;
} }
if (fileDialog->isError()) {
#if defined(_WIN32) || defined(__APPLE__)
showError("there was an error in the file dialog! you may want to report this issue to:\nhttps://github.com/tildearrow/furnace/issues\ncheck the Log Viewer (window > log viewer) for more information.\n\nfor now please disable the system file picker in Settings > General.");
#else
showError("Zenity/KDialog not available!\nplease install one of these, or disable the system file picker in Settings > General.");
#endif
}
if (fileDialog->accepted()) { if (fileDialog->accepted()) {
fileName=fileDialog->getFileName(); fileName=fileDialog->getFileName();
if (fileName!="") { if (fileName!="") {