diff --git a/extern/nfd-modified/src/nfd_win.cpp b/extern/nfd-modified/src/nfd_win.cpp index 0cb614b20..fd40f2ad6 100644 --- a/extern/nfd-modified/src/nfd_win.cpp +++ b/extern/nfd-modified/src/nfd_win.cpp @@ -466,6 +466,15 @@ nfdresult_t NFD_OpenDialog( const std::vector& filterList, goto end; } + // Set the file name + if (defaultFileName!=NULL) { + std::wstring defFileName=utf8To16(defaultFileName); + result = fileOpenDialog->SetFileName(defFileName.c_str()); + if ( !SUCCEEDED(result) ) { + // ignore + } + } + // Pass the callback winEvents=new NFDWinEvents(selCallback); if ( !SUCCEEDED(fileOpenDialog->Advise(winEvents,&eventID)) ) { @@ -577,6 +586,15 @@ nfdresult_t NFD_OpenDialogMultiple( const std::vector& filterList, goto end; } + // Set the file name + if (defaultFileName!=NULL) { + std::wstring defFileName=utf8To16(defaultFileName); + result = fileOpenDialog->SetFileName(defFileName.c_str()); + if ( !SUCCEEDED(result) ) { + // ignore + } + } + // Pass the callback winEvents=new NFDWinEvents(selCallback); if ( !SUCCEEDED(fileOpenDialog->Advise(winEvents,&eventID)) ) { @@ -686,6 +704,15 @@ nfdresult_t NFD_SaveDialog( const std::vector& filterList, goto end; } + // Set the file name + if (defaultFileName!=NULL) { + std::wstring defFileName=utf8To16(defaultFileName); + result = fileSaveDialog->SetFileName(defFileName.c_str()); + if ( !SUCCEEDED(result) ) { + // ignore + } + } + // Set a flag for no history DWORD dwFlags; result = fileSaveDialog->GetOptions(&dwFlags); diff --git a/src/gui/fileDialog.cpp b/src/gui/fileDialog.cpp index 38afb3274..edcae89cd 100644 --- a/src/gui/fileDialog.cpp +++ b/src/gui/fileDialog.cpp @@ -18,13 +18,15 @@ struct NFDState { String header; std::vector filter; String path; + String defFileName; FileDialogSelectCallback clickCallback; - NFDState(unsigned char save, String h, std::vector filt, String pa, FileDialogSelectCallback cc, bool multi): + NFDState(unsigned char save, String h, std::vector filt, String pa, FileDialogSelectCallback cc, bool multi, String defFN): isSave(save), allowMultiple(multi), header(h), filter(filt), path(pa), + defFileName(defFN), clickCallback(cc) { } }; @@ -40,12 +42,12 @@ void _nfdThread(const NFDState state, std::atomic* ok, std::vector if (state.isSave==2) { ret=NFD_PickFolder(state.path.c_str(),&out); } else if (state.isSave==1) { - ret=NFD_SaveDialog(state.filter,state.path.c_str(),&out,state.clickCallback); + ret=NFD_SaveDialog(state.filter,state.path.c_str(),&out,state.clickCallback,state.defFileName.empty()?NULL:state.defFileName.c_str()); } else { if (state.allowMultiple) { - ret=NFD_OpenDialogMultiple(state.filter,state.path.c_str(),&paths,state.clickCallback); + ret=NFD_OpenDialogMultiple(state.filter,state.path.c_str(),&paths,state.clickCallback,state.defFileName.empty()?NULL:state.defFileName.c_str()); } else { - ret=NFD_OpenDialog(state.filter,state.path.c_str(),&out,state.clickCallback); + ret=NFD_OpenDialog(state.filter,state.path.c_str(),&out,state.clickCallback,state.defFileName.empty()?NULL:state.defFileName.c_str()); } } @@ -131,9 +133,9 @@ bool FurnaceGUIFileDialog::openLoad(String header, std::vector filter, S #ifdef USE_NFD dialogOK=false; #ifdef NFD_NON_THREADED - _nfdThread(NFDState(0,header,filter,path,clickCallback,allowMultiple),&dialogOK,&nfdResult,&hasError); + _nfdThread(NFDState(0,header,filter,path,clickCallback,allowMultiple,hint),&dialogOK,&nfdResult,&hasError); #else - dialogO=new std::thread(_nfdThread,NFDState(0,header,filter,path,clickCallback,allowMultiple),&dialogOK,&nfdResult,&hasError); + dialogO=new std::thread(_nfdThread,NFDState(0,header,filter,path,clickCallback,allowMultiple,hint),&dialogOK,&nfdResult,&hasError); #endif #elif defined(ANDROID) hasError=false; @@ -223,9 +225,9 @@ bool FurnaceGUIFileDialog::openSave(String header, std::vector filter, S #ifdef USE_NFD dialogOK=false; #ifdef NFD_NON_THREADED - _nfdThread(NFDState(1,header,filter,path,NULL,false),&dialogOK,&nfdResult,&hasError); + _nfdThread(NFDState(1,header,filter,path,NULL,false,hint),&dialogOK,&nfdResult,&hasError); #else - dialogS=new std::thread(_nfdThread,NFDState(1,header,filter,path,NULL,false),&dialogOK,&nfdResult,&hasError); + dialogS=new std::thread(_nfdThread,NFDState(1,header,filter,path,NULL,false,hint),&dialogOK,&nfdResult,&hasError); #endif #elif defined(ANDROID) hasError=false; @@ -303,9 +305,9 @@ bool FurnaceGUIFileDialog::openSelectDir(String header, String path, double dpiS #ifdef USE_NFD dialogOK=false; #ifdef NFD_NON_THREADED - _nfdThread(NFDState(2,header,std::vector(),path,NULL,false),&dialogOK,&nfdResult,&hasError); + _nfdThread(NFDState(2,header,std::vector(),path,NULL,false,""),&dialogOK,&nfdResult,&hasError); #else - dialogF=new std::thread(_nfdThread,NFDState(2,header,std::vector(),path,NULL,false),&dialogOK,&nfdResult,&hasError); + dialogF=new std::thread(_nfdThread,NFDState(2,header,std::vector(),path,NULL,false,""),&dialogOK,&nfdResult,&hasError); #endif #elif defined(ANDROID) hasError=true;