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
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;
nfdresult_t ret=NFD_CANCEL;
errorOutput=false;
if (state.isSave) {
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:
(*result)="";
logE("NFD error! %s\n",NFD_GetError());
(*errorOutput)=true;
break;
default:
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
dialogOK=false;
#ifdef NFD_NON_THREADED
_nfdThread(NFDState(false,header,filter,path,clickCallback),&dialogOK,&nfdResult);
_nfdThread(NFDState(false,header,filter,path,clickCallback),&dialogOK,&nfdResult,&hasError);
#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
#else
dialogO=new pfd::open_file(header,path,filter);
hasError=!pfd::settings::available();
#endif
} else {
hasError=false;
ImGuiFileDialog::Instance()->DpiScale=dpiScale;
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
dialogOK=false;
#ifdef NFD_NON_THREADED
_nfdThread(NFDState(true,header,filter,path,NULL),&dialogOK,&nfdResult);
_nfdThread(NFDState(true,header,filter,path,NULL),&dialogOK,&nfdResult,&hasError);
#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
#else
dialogS=new pfd::save_file(header,path,filter);
hasError=!pfd::settings::available();
#endif
} else {
hasError=false;
ImGuiFileDialog::Instance()->DpiScale=dpiScale;
ImGuiFileDialog::Instance()->OpenModal("FileDialog",header,noSysFilter,path,1,nullptr,ImGuiFileDialogFlags_ConfirmOverwrite);
}
@ -193,6 +199,10 @@ bool FurnaceGUIFileDialog::isOpen() {
return opened;
}
bool FurnaceGUIFileDialog::isError() {
return hasError;
}
String FurnaceGUIFileDialog::getPath() {
if (sysDialog) {
if (curPath.size()>1) {

View File

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

View File

@ -3221,6 +3221,13 @@ bool FurnaceGUI::loop() {
workingDirROM=fileDialog->getPath()+DIR_SEPARATOR_STR;
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()) {
fileName=fileDialog->getFileName();
if (fileName!="") {