GUI: implement multi sel on NFD and IGFD
This commit is contained in:
parent
666b0d581a
commit
96b7e5d353
|
@ -26,36 +26,48 @@ struct NFDState {
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: filter
|
// TODO: filter
|
||||||
void _nfdThread(const NFDState state, std::atomic<bool>* ok, String* result, bool* errorOutput) {
|
void _nfdThread(const NFDState state, std::atomic<bool>* ok, std::vector<String>* result, bool* errorOutput) {
|
||||||
nfdchar_t* out=NULL;
|
nfdchar_t* out=NULL;
|
||||||
nfdresult_t ret=NFD_CANCEL;
|
nfdresult_t ret=NFD_CANCEL;
|
||||||
(*errorOutput)=false;
|
(*errorOutput)=false;
|
||||||
|
nfdpathset_t paths;
|
||||||
|
|
||||||
|
result->clear();
|
||||||
|
|
||||||
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);
|
||||||
|
} else {
|
||||||
|
if (state.allowMultiple) {
|
||||||
|
ret=NFD_OpenDialogMultiple(state.filter,state.path.c_str(),&paths,state.clickCallback);
|
||||||
} else {
|
} 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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case NFD_OKAY:
|
case NFD_OKAY:
|
||||||
if (out!=NULL) {
|
if (state.allowMultiple) {
|
||||||
(*result)=out;
|
logD("pushing multi path");
|
||||||
|
for (size_t i=0; i<NFD_PathSet_GetCount(&paths); i++) {
|
||||||
|
result->push_back(String(NFD_PathSet_GetPath(&paths,i)));
|
||||||
|
}
|
||||||
|
NFD_PathSet_Free(&paths);
|
||||||
} else {
|
} else {
|
||||||
(*result)="";
|
logD("pushing single path");
|
||||||
|
if (out!=NULL) {
|
||||||
|
logD("we have it");
|
||||||
|
result->push_back(String(out));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NFD_CANCEL:
|
case NFD_CANCEL:
|
||||||
(*result)="";
|
|
||||||
break;
|
break;
|
||||||
case NFD_ERROR:
|
case NFD_ERROR:
|
||||||
(*result)="";
|
|
||||||
logE("NFD error! %s\n",NFD_GetError());
|
logE("NFD error! %s\n",NFD_GetError());
|
||||||
(*errorOutput)=true;
|
(*errorOutput)=true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
logE("NFD unknown return code %d!\n",ret);
|
logE("NFD unknown return code %d!\n",ret);
|
||||||
(*result)="";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
(*ok)=true;
|
(*ok)=true;
|
||||||
|
@ -155,7 +167,7 @@ bool FurnaceGUIFileDialog::render(const ImVec2& min, const ImVec2& max) {
|
||||||
#ifdef USE_NFD
|
#ifdef USE_NFD
|
||||||
if (dialogOK) {
|
if (dialogOK) {
|
||||||
fileName.clear();
|
fileName.clear();
|
||||||
fileName.push_back(nfdResult);
|
fileName=nfdResult;
|
||||||
if (!fileName.empty()) {
|
if (!fileName.empty()) {
|
||||||
size_t dsPos=fileName[0].rfind(DIR_SEPARATOR);
|
size_t dsPos=fileName[0].rfind(DIR_SEPARATOR);
|
||||||
if (dsPos!=String::npos) curPath=fileName[0].substr(0,dsPos);
|
if (dsPos!=String::npos) curPath=fileName[0].substr(0,dsPos);
|
||||||
|
@ -235,7 +247,14 @@ std::vector<String>& FurnaceGUIFileDialog::getFileName() {
|
||||||
return fileName;
|
return fileName;
|
||||||
} else {
|
} else {
|
||||||
fileName.clear();
|
fileName.clear();
|
||||||
|
if (saving) {
|
||||||
fileName.push_back(ImGuiFileDialog::Instance()->GetFilePathName());
|
fileName.push_back(ImGuiFileDialog::Instance()->GetFilePathName());
|
||||||
|
} else {
|
||||||
|
for (auto& i: ImGuiFileDialog::Instance()->GetSelection()) {
|
||||||
|
fileName.push_back(i.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ class FurnaceGUIFileDialog {
|
||||||
std::thread* dialogO;
|
std::thread* dialogO;
|
||||||
std::thread* dialogS;
|
std::thread* dialogS;
|
||||||
std::atomic<bool> dialogOK;
|
std::atomic<bool> dialogOK;
|
||||||
String nfdResult;
|
std::vector<String> nfdResult;
|
||||||
#else
|
#else
|
||||||
pfd::open_file* dialogO;
|
pfd::open_file* dialogO;
|
||||||
pfd::save_file* dialogS;
|
pfd::save_file* dialogS;
|
||||||
|
|
Loading…
Reference in New Issue